[gdal-dev] polygon to grid?

Frank Warmerdam warmerdam at pobox.com
Mon Jul 13 11:12:58 EDT 2009


Lewis, Ambrose J. wrote:
> Hi All:
> 
> I’m relatively new to GDAL/OGR, so please forgive a dumb question!
> 
> I have a grid file (DTED elevations) and a shapefile of polygons 
> (building locations and an APEX attribute representing their height).
> 
> I’d like to combine these together so that my new[x,y] = DTED 
> elevation[x,y] + building apex[x,y] (assuming the building apex is zero 
> if the loc was outside any of the shapefile’s polygon)
> 
> How can I convert the polygons to a grid compatible with DTED?

Ambrose,

You can use the gdal_rasterize to burn the building elevations into an
empty file.  You will need a zeroed file of the right extents and resolution.
It may be helpful to create that by scaling your target dted tile to zero.

eg.

gdal_translate -scale 0 10000 0 0 src.dt2 apex_work.tif
gdal_rasterize -a buildapex \
    building_footprints.shp -l building_footprints \
    apex_work.tif
... your own script to add the apex_work.tif to src.dt2 ...

The above would create a GeoTIFF file named apex_work.tif
with the same resolution and extents as the DTED "src.dt2".

Then gdal_rasterize will burn all the polygons from building_footprints.shp
into the file using the attribute "buildapex" as the source of the
elevations to burn into the file.

There is no particular program available to add the building eleations
into the dted so you might need to write a python numpy script or something
like that.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the gdal-dev mailing list