Database Reference
In-Depth Information
A netCDF dataset is composed of multiple subdatasets; each subdataset is com-
posed of multiple raster bands. Each band is composed of cells. This structure
shouldbecleartoyouafterinvestigatingasamplenetCDFdatasetusingthe gdal-
info GDAL command tool.
There are several approaches to export the cell values to PostGIS. The approach
youadoptedhereistogenerateaPostGISPointlayerforeachsubdataset,whichis
composed of one field for each subdataset band. You then iterated the raster cells
andappendedapointtothePostGISlayerwiththevaluesreadfromeachcellband.
ThewayyoudothiswithPythonisbyusingtheGDALPythonbindings.Forreading,
youopenthenetCDFdatasetandforupdating,youopenthePostGISdatabaseus-
ingthecorrectGDALandOGRdrivers.ThenyouiteratethenetCDFsubdatasetsus-
ingthe GetSubDatasets methodandcreateforeachsubdatasetaPostGIStable
namedasthenetCDFsubdatasetvariable(withtheprefix)usingthe CreateLayer
method.
Foreachsubdataset,youiterateitsbandsusingthe GetRasterBand method.For
readingeachband,yourunthe ReadAsArray methodthatusesNumpytogetthe
band as an array.
Foreachband,youcreateafieldinthePostGISlayerwiththecorrectfielddatatype
thatwillbeabletostoretheband'svalues.Tochoosethecorrectdatatype,youin-
vestigate the band's data type usingthe DataType property.
Finally,youiteratetherastercells,byreadingthecorrect x and y coordinatesusing
thesubdatasettransformparameters,availableviathe GetGeoTransform method.
For each cell, you create a point with the CreateGeometryFromWkt method and
then set the fields values, read from the band array, using the SetField feature
method.
Finally,youappendthenewpointtothePostGISlayerusingthe CreateFeature
method.
Search WWH ::




Custom Search