2

Given an unique raster topographic file at start, I want to get vector polygons for elevations thresholds 1m, 200m, 500m, 1000m, 2000m into a single shp file. I first slice my raster into 5 (or more) rasters, then polygonize each, and then have to merge them.

How to get these outputs into a single shape file ? Either by sending them as layers directly into the same file, or by creating individual shp files to merge into one final shp.


Current workflow details: It seems I must do this because poligonize works on pixels with a same value (elevation) x.

1. Generate raster slices: I used gdal_calc.py to generate kinds of vertical slices, with one .tif for each level :

gdal_calc.py -A crop.tif --outfile=level001.tif --calc="1*(A>0)"     --NoDataValue=0
gdal_calc.py -A crop.tif --outfile=level200.tif --calc="200*(A>200)" --NoDataValue=0
...
...
...
...

All conserved pixels in level001.tif have an elevation of 1. All conserved pixels in level200.tif have an elevation of 200m. Opened together in QGis it give slices like this:

enter image description here

2. Polygonize my rasters slices (files):

I run polygonize.py separatedly on each of these several raster files to get my vector layers:

gdal_polygonize.py level001.tif -f "ESRI Shapefile" levels001.shp levels001 elev
gdal_polygonize.py level200.tif -f "ESRI Shapefile" levels200.shp levels200 elev
...
...
...
...

3. Merge into one shp file.

How to merge these shp outputs ?

Alternatively, I'am also interested by smoother workflow (loop).

3

If the shapefiles to be merged are in the same directory:

ogr2ogr merge.shp levels001.shp
ogr2ogr -update -append merge.shp levels200.shp -nln merge
ogr2ogr -update -append merge.shp levels500.shp -nln merge
ogr2ogr -update -append merge.shp levels1000.shp -nln merge
ogr2ogr -update -append merge.shp levels2000.shp -nln merge

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.