Shape File From Raster

[vc_row][vc_column width=”1/1″][vc_column_text]

How to create a shape-file from raster to exactly match irregular image boundary.

In my case I want to get rid of the extra (black) area (fig. shown at the end of this post) to reduce the file dimensions, to be able to use images in PhotoMod (demo) software for mosaicing tiles together. As the demo software is limited to 20 Mega pixels per image and rectified image exceeds that limit if flight line is (rotated) as rotation increases the bounding rectangle, which results in increased image X-Y size.

(Entire process can be done in ArcMap too, but I like to use Gdal (free software) as much as possible.)

Here I will explain how to create the above mentioned shape-file using Gdal & ArcMap.

First step is to convert all non-zero digital numbers of a raster to “0 & 1″

For this conversion I use Gdal Batch Commander and enter the following command in parameters field…
“-co compress=lzw -b 1 -ot byte 0 -a_no-data 0 -scale 1 1″.

This will create a new raster with all non-zero (except no-data,0) values converted to “1” (You can use any number in place of 1).

Command line parameters explained :-

  1. -co compress=lzw it to compress the generated tiffs with losseless LZW compression.
  2. -b 1 option is for using only first band, just to save time by not reading all the bands in MS imagery.
  3. -ot byte will create 8-bit raster.
  4. -a_nodata 0 specifies nodata value for the input band. This one is not shown is figure below, so don’t skip it. As this parameter helps ArcMap to ignore outer rectangle (black area) for its shapefile generation routine.
  5. -scale 1 1 will convert all non-zero pixel values to 1.

gdal batch commander convert raster to 0 & 1

Second step is to convert “0 & 1″ image to shape file.

In ArcMap you can choose “Raster to Polygon” tool to create shapefile. Use ArcMap’s model builder to create a shape file from all the newly created tiffs (with 0 & 1 as pixel values for no-data and data areas respectively). Below is a screenshot of model builder that I used to convert 0&1 tiff to shape file.
Note: Check simplify polygon option in “Raster to Polygon” window.

ArcMap model to convert tiffs (0&1) to shape-file. Don't forget to check simplify polygons option in Raster to Polygon dialog.

Resulting shape file (a yellow polygon) is produced after running Gdal_translate & ArcMap.

2015_04_08_16_31_06_Untitled - ArcMap

Now I can use the shape-file to crop the raster to the newly generated polygon and get rid of the extra black area.