[gdal-dev] Burn 3d-lines from python

Simon Lyngby Kokkendorff silyko at gmail.com
Tue Aug 11 02:36:32 PDT 2015


Hello list,

  I'm trying to rasterize some 3d-lines programtically from python. Using
gdal 1.11.2 from the osgeo4w64 environment. Seems to work fine, except that
I get a z-offset of 255 (one byte) in my output raster. Works fine if I use
gdal_rasterize with the -3d option.

 The following python code should reproduce the problem:

from osgeo import ogr,gdal
print gdal.__version__
georef=[0,1.0,0,10.5,0,-1.0]
m_drv_ogr=ogr.GetDriverByName("Memory")
line_ds = m_drv_ogr.CreateDataSource( "dummy")
layer = line_ds.CreateLayer( "lines", None, ogr.wkbLineString25D)
layerdefn=layer.GetLayerDefn()
line=ogr.Geometry(ogr.wkbLineString25D)
line.AddPoint(0,5.5,0)
line.AddPoint(10,5.5,10)
feature=ogr.Feature(layerdefn)
feature.SetGeometry(line)
res=layer.CreateFeature(feature)
layer.ResetReading()
m_drv_gdal=gdal.GetDriverByName("MEM")
raster_ds=m_drv_gdal.Create("dummy",10,10,1,gdal.GDT_Float64)
raster_ds.SetGeoTransform(georef)
ok=gdal.RasterizeLayer(raster_ds,[1], layer, options=["BURN_VALUE_FROM=Z"])
A=raster_ds.ReadAsArray()
print A

Will output:

[[   0.    0.    0.    0.    0.    0.    0.    0.    0.    0.]
 [   0.    0.    0.    0.    0.    0.    0.    0.    0.    0.]
 [   0.    0.    0.    0.    0.    0.    0.    0.    0.    0.]
 [   0.    0.    0.    0.    0.    0.    0.    0.    0.    0.]
 [   0.    0.    0.    0.    0.    0.    0.    0.    0.    0.]
 [ 255.  256.  257.  258.  259.  260.  261.  262.  263.  264.]
 [   0.    0.    0.    0.    0.    0.    0.    0.    0.    0.]
 [   0.    0.    0.    0.    0.    0.    0.    0.    0.    0.]
 [   0.    0.    0.    0.    0.    0.    0.    0.    0.    0.]
 [   0.    0.    0.    0.    0.    0.    0.    0.    0.    0.]]

Cheers,
Simon Kokkendorff, Dansish Geodata Agency
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20150811/d6d4a8a1/attachment.html>


More information about the gdal-dev mailing list