Database Reference
In-Depth Information
bands+1):
band =
sds.GetRasterBand(1)
datatype =
gdal.GetDataTypeName(band.DataType)
value = data[b-1][r,c]
print 'Storing a
value for variable %s in point x: %s, y:
%s, band: %s, value: %s' % (variable, x,
y, b, value)
if datatype in
('Float32', 'Float64'):
value =
float(data[b-1][r,c])
elif datatype in
('Int16', 'Int32'):
value =
int(data[b-1][r,c])
else:
value = data[r,c]
feature.SetField('band_%s' % b, value)
# set the feature's
geometry and finalize its creation
feature.SetGeometry(point)
pg_layer.CreateFeature(feature)
4. Torunthe netcdf2postgis methodfromthecommandline,addtheentry
pointforthescript.Thecodewillcheckwhetherthescriptuseriscorrectlyus-
ingthethreeneededparameters—thenetCDFfilepath,theGDALPostGIS
connection string, and a prefix/suffixto use for table names in PostGIS:
if __name__ == '__main__':
# the user must provide at least
three parameters, the netCDF file path,
the PostGIS GDAL connection string
# and the prefix suffix to use for
Search WWH ::




Custom Search