Database Reference
In-Depth Information
datatype =
gdal.GetDataTypeName(band.DataType)
ogr_ft = ogr.OFTString #
default for a field is string
if datatype in ('Float32',
'Float64'):
ogr_ft = ogr.OFTReal
elif datatype in ('Int16',
'Int32'):
ogr_ft = ogr.OFTInteger
# here we add the field to
the PostGIS layer
fd_band =
ogr.FieldDefn('band_%s' % b, ogr_ft)
pg_layer.CreateField(fd_band)
print 'Field band_%s
created.' % b
# 3. iterate rows and cols
for r in range(0, rows):
y = yOrigin + (r *
pixelHeight)
for c in range(0, cols):
x = xOrigin + (c *
pixelWidth)
# for each cell, let's
add a point feature in the PostGIS table
point_wkt = 'POINT(%s
%s)' % (x, y)
point =
ogr.CreateGeometryFromWkt(point_wkt)
featureDefn =
pg_layer.GetLayerDefn()
feature =
ogr.Feature(featureDefn)
# now iterate bands, and
add a value for each table's field
for b in range(1,
Search WWH ::




Custom Search