EcohydroLib  1.29
Functions | Variables
ecohydrolib.spatialdata.utils Namespace Reference

Generic utilities for manipulating spatial data sets. More...

Functions

def bboxFromString (bboxStr)
 Get bbox dictionary from comma separated string of the form '-76.769782 39.273610 -76.717498 39.326008'. More...
 
def isValidSrs (srsString)
 Determine if spatial reference string is valid. More...
 
def getEPSGStringForUTMZone (zone, isNorth)
 Get EPSG string, e.g. More...
 
def getUTMZoneFromCoordinates (longitude, latitude)
 Determine the UTM zone for coordinate pair. More...
 
def transformCoordinates
 Transform a pair of X,Y coordinates from one reference system to another. More...
 
def getRasterExtentAsBbox (extentRasterFilepath)
 Determine raster extent and store it in a bbox along with the spatial reference system of the raster. More...
 
def extractTileFromRasterByRasterExtent
 Extract a tile from a raster using the extent of another raster as the tile bounds. More...
 
def extractTileFromRaster (config, outputDir, inRasterFilename, outRasterFilename, bbox)
 Extract a tile from a raster. More...
 
def resampleRaster
 Resample raster from one spatial reference system and resolution to another. More...
 
def rescaleRaster (config, outputDir, inRasterFilepath, outRasterFilename, scalar)
 Rescale DN values of raster. More...
 
def convertGMLToShapefile (config, outputDir, gmlFilepath, layerName, t_srs)
 Convert a GML file to a shapefile. More...
 
def convertGMLToGeoJSON
 
def convertGeoJSONToShapefile
 Convert a GeoJSON file to a shapefile. More...
 
def mergeFeatureLayers
 Combine vector feature files readable by OGR into a single feature layer. More...
 
def convertFeatureLayerToShapefile
 Convert a vector feature file readible by OGR to a shapefile. More...
 
def deleteShapefile (shpfilePath)
 Delete shapefile and its related files (.dbf, .prj, .shx) More...
 
def getCoordinatesOfPointsFromShapefile (shpFilepath, layerName, pointIDAttr, pointIDs)
 Get WGS84 coordinates of point features in shapefile. More...
 
def deleteGeoTiff (geoTiffPath)
 Delete GeoTIFF and its related files (.aux.xml) More...
 
def isCoordinatePairInBoundingBox (bbox, coordinates)
 Determine whether coordinate pair lies within bounding box. More...
 
def calculateBoundingBoxCenter (bbox)
 Calculate the central point of the bounding box. More...
 
def calculateBoundingBoxArea
 Calculate bbox area in squared units of srs. More...
 
def tileBoundingBox
 Break up bounding box into tiles if bounding box is larger than threshold. More...
 
def getBoundingBoxForShapefile
 Return the bounding box, in WGS84 (EPSG:4326) coordinates, for the ESRI shapefile. More...
 
def bufferBoundingBox (bbox, buffer)
 Buffer the bounding by a given percentage. More...
 
def getMeterConversionFactorForLinearUnitOfGMLfile (gmlFilename)
 Get conversion factor for converting a GML file's linear unit into meters. More...
 
def getMeterConversionFactorForLinearUnitOfShapefile (shpFilename)
 Get conversion factor for converting a shapefile's linear unit into meters. More...
 
def getNodataValuesForRaster (filename)
 Get nodata value for each band in a raster. More...
 
def getSpatialReferenceForRaster (filename)
 Get pixel size and unit for DEM. More...
 
def getDimensionsForRaster (filename)
 Get number of columns and rows for raster. More...
 
def getBoundingBoxForRaster (filename)
 Return the bounding box, in WGS84 (EPSG:4326) coordinates, for the raster dateset. More...
 
def writeBboxPolygonToShapefile
 Write bbox to a shapfile. More...
 
def writeCoordinatePairsToPointShapefile
 Write coordinates as a point shapefile. More...
 
def copyRasterToGeoTIFF (config, outputDir, inRasterPath, outRasterName)
 Copy input raster from a location outside of outputDir to a GeoTIFF format raster stored in outputDir. More...
 

Variables

int SHP_MINX = 0
 
int SHP_MAXX = 1
 
int SHP_MINY = 2
 
int SHP_MAXY = 3
 
list RASTER_RESAMPLE_METHOD = ['near', 'bilinear', 'cubic', 'cubicspline', 'lanczos', 'average', 'mode']
 
int WGS84_EPSG = 4326
 
string WGS84_EPSG_STR = 'EPSG:4326'
 
float NORTH = 0.0
 
float EAST = 90.0
 
float BBOX_TILE_DIVISOR = 1.0
 
string OGR_SHAPEFILE_DRIVER_NAME = 'ESRI Shapefile'
 
string OGR_GEOJSON_DRIVER_NAME = 'GeoJSON'
 
dictionary OGR_DRIVERS
 
tuple EPSG_RE = re.compile('^epsg:\d+$')
 
tuple GDAL_VERSION_RE = re.compile('^GDAL\s(\d{1,2})\.(\d{1,2})\.(\d{1,2}),\sreleased\s\d{4}/\d{2}/\d{2}\s*$')
 

Detailed Description

Generic utilities for manipulating spatial data sets.

Builds a task-oriented API, for select operations, on top of GDAL/OGR utilities, GDAL/OGR API, Proj API.

This software is provided free of charge under the New BSD License. Please see the following license information:

Copyright (c) 2013, University of North Carolina at Chapel Hill All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Author
Brian Miles brian.nosp@m._mil.nosp@m.es@un.nosp@m.c.ed.nosp@m.u
Todo:
Refactor raster and vector functions into their own sub-packages Refactor bounding box as class

Builds a task-oriented API, for select operations, on top of GDAL/OGR utilities, GDAL/OGR API, Proj API.

This software is provided free of charge under the New BSD License. Please see the following license information:

Copyright (c) 2013, University of North Carolina at Chapel Hill All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Author
Brian Miles brian.nosp@m._mil.nosp@m.es@un.nosp@m.c.ed.nosp@m.u
Todo:
Refactor raster and vector functions into their own sub-packages Refactor bounding box as class

Function Documentation

def ecohydrolib.spatialdata.utils.bboxFromString (   bboxStr)

Get bbox dictionary from comma separated string of the form '-76.769782 39.273610 -76.717498 39.326008'.

Parameters
bboxStrString representing bounding box in WGS84 coordinates
Returns
Dict representing bounding box with keys: minX, minY, maxX, maxY, and srs
def ecohydrolib.spatialdata.utils.bufferBoundingBox (   bbox,
  buffer 
)

Buffer the bounding by a given percentage.

Parameters
bboxA dict containing keys: minX, minY, maxX, maxY, srs, where srs='EPSG:4326'
bufferFloat >= 0.0 representing number of degrees by which to buffer the bounding box; 0.0 = no buffer, 0.01 = 0.01 degree buffer
def ecohydrolib.spatialdata.utils.calculateBoundingBoxArea (   bbox,
  srs = WGS84_EPSG_STR 
)

Calculate bbox area in squared units of srs.

Parameters
bboxA dict containing keys: minX, minY, maxX, maxY, srs, where srs='EPSG:4326'
srsString representing spatial reference system, in EPSG format, in which area should be calculated.
Returns
Float representing the bounding box area in square meters
def ecohydrolib.spatialdata.utils.calculateBoundingBoxCenter (   bbox)

Calculate the central point of the bounding box.

Parameters
bboxA dict containing keys: minX, minY, maxX, maxY, srs, where srs='EPSG:4326'
Returns
Tuple of floats of the form (longitude, latitude)
def ecohydrolib.spatialdata.utils.convertFeatureLayerToShapefile (   config,
  outputDir,
  featureFilepath,
  shapefileName,
  layerName = None,
  t_srs = 'EPSG:4326',
  overwrite = False 
)

Convert a vector feature file readible by OGR to a shapefile.

Will silently exit if output shapefile already exists

Parameters
configA Python ConfigParser containing the section 'GDAL/OGR' and option 'PATH_OF_OGR2OGR'
outputDirString representing the absolute/relative path of the directory into which shapefile should be written
featureFilepathString representing the absolute path of the feature file to convert
layerNameString representing the name of the layer contained in the feature file to write to a shapefile. If none, the base name of featureFilepath will be used
t_srsString representing the spatial reference system of the output shapefile, of the form 'EPSG:XXXX'
Returns
String representing the name of the shapefile written
Exceptions
Exceptionif the conversion failed.
def ecohydrolib.spatialdata.utils.convertGeoJSONToShapefile (   config,
  outputDir,
  geoJSONFilepath,
  shapefileName,
  layerName = 'OGRGeoJSON',
  t_srs = 'EPSG:4326' 
)

Convert a GeoJSON file to a shapefile.

Will silently exit if shapefile already exists

   @param config A Python ConfigParser containing the section 'GDAL/OGR' and option 'PATH_OF_OGR2OGR'
   @param outputDir String representing the absolute/relative path of the directory into which shapefile should be written
   @param geoJSONFilepath String representing the absolute path of the GeoJSON file to convert
   @param layerName String representing the name of the layer contained in the GeoJSON file to write to a shapefile
   @param t_srs String representing the spatial reference system of the output shapefile, of the form 'EPSG:XXXX'

   @return String representing the name of the shapefile written

   @exception Exception if the conversion failed.
def ecohydrolib.spatialdata.utils.convertGMLToGeoJSON (   config,
  outputDir,
  gmlFilepath,
  layerName,
  t_srs = 'EPSG:4326',
  flip_gml_coords = False 
)
Convert a GML file to a shapefile.  Will silently exit if GeoJSON already exists

    @param config A Python ConfigParser containing the section 'GDAL/OGR' and option 'PATH_OF_OGR2OGR'
    @param outputDir String representing the absolute/relative path of the directory into which GeoJSON should be written
    @param gmlFilepath String representing the absolute path of the GML file to convert
    @param layerName String representing the name of the layer contained in the GML file to write to a GeoJSON
    @param t_srs String representing the spatial reference system of the output GeoJSON, of the form 'EPSG:XXXX'
    
    @return String representing the name of the GeoJSON written

    @exception Exception if the conversion failed.
def ecohydrolib.spatialdata.utils.convertGMLToShapefile (   config,
  outputDir,
  gmlFilepath,
  layerName,
  t_srs 
)

Convert a GML file to a shapefile.

Will silently exit if shapefile already exists

   @param config A Python ConfigParser containing the section 'GDAL/OGR' and option 'PATH_OF_OGR2OGR'
   @param outputDir String representing the absolute/relative path of the directory into which shapefile should be written
   @param gmlFilepath String representing the absolute path of the GML file to convert
   @param layerName String representing the name of the layer contained in the GML file to write to a shapefile
   @param t_srs String representing the spatial reference system of the output shapefile, of the form 'EPSG:XXXX'

   @return String representing the name of the shapefile written

   @exception Exception if the conversion failed.
def ecohydrolib.spatialdata.utils.copyRasterToGeoTIFF (   config,
  outputDir,
  inRasterPath,
  outRasterName 
)

Copy input raster from a location outside of outputDir to a GeoTIFF format raster stored in outputDir.

Parameters
configA Python ConfigParser containing the section 'GDAL/OGR' and option 'PATH_OF_GDAL_TRANSLATE'
outputDirString representing the absolute/relative path of the directory into which shapefile should be written
inRasterPathString representing path of input raster
outRasterNameString representing name of output raster to be stored in outputDir

IOError if gdal_translate binary is not found/executable IOError if output directory does not exist or not writable IOError if input raster is not readable

def ecohydrolib.spatialdata.utils.deleteGeoTiff (   geoTiffPath)

Delete GeoTIFF and its related files (.aux.xml)

Parameters
geoTiffPath– Path, including filename, of the GeoTIFF to be deleted
def ecohydrolib.spatialdata.utils.deleteShapefile (   shpfilePath)

Delete shapefile and its related files (.dbf, .prj, .shx)

Parameters
shpfilePath– Path, including filename, of the shapefile to be deleted
def ecohydrolib.spatialdata.utils.extractTileFromRaster (   config,
  outputDir,
  inRasterFilename,
  outRasterFilename,
  bbox 
)

Extract a tile from a raster.

Tile extent is defined by supplied bounding box with coordinates defined in WGS84 (EPSG:4326).

Note
Output raster will be in LZW-compressed GeoTIFF file.
Will silently return if output raster already exists.
Parameters
configPython ConfigParser containing the section 'GDAL/OGR' and option 'PATH_OF_GDAL_TRANSLATE'
outputDirString representing the absolute/relative path of the directory into which output raster should be written
inRasterFilenameString representing the name of the input raster
outRasterFilenameString representing the name of the output raster
bboxA dict containing keys: minX, minY, maxX, maxY, srs, where srs='EPSG:4326' (WGS84)
def ecohydrolib.spatialdata.utils.extractTileFromRasterByRasterExtent (   config,
  outputDir,
  extentRasterFilepath,
  inRasterFilepath,
  outRasterFilename,
  resampleMethod = 'near' 
)

Extract a tile from a raster using the extent of another raster as the tile bounds.

Note
Output raster will be in LZW-compressed GeoTIFF file.
Will delete existing output raster if it already exists, then perform the extraction
Parameters
configPython ConfigParser containing the section 'GDAL/OGR' and option 'PATH_OF_GDAL_WARP'
outputDirString representing the absolute/relative path of the directory into which output raster should be written
extentRasterFilepathString representing the path of the extent raster
inRasterFilepathString representing the path of the raster from which a tile will be extracted
outRasterFilenameString representing the name of the output raster
resampleMethodString representing method to use to resample; one of: RASTER_RESAMPLE_METHOD
def ecohydrolib.spatialdata.utils.getBoundingBoxForRaster (   filename)

Return the bounding box, in WGS84 (EPSG:4326) coordinates, for the raster dateset.

Assumes raster exists and is readable. Code adapted from: http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/gdalinfo.py

Parameters
filenameString representing the DEM file to read pixel size and units
Returns
A tuple of the form: (columns, rows) or None if raster could not be opened
Exceptions
IOErrorif filename is not readable
Exceptionif raster dataset failed to open
def ecohydrolib.spatialdata.utils.getBoundingBoxForShapefile (   shapefileName,
  buffer = 0.0 
)

Return the bounding box, in WGS84 (EPSG:4326) coordinates, for the ESRI shapefile.

Assumes shapefile exists and is readable. Based on http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/ogrinfo.py

Parameters
shapefileNameString representing the path of the shapefile whose bounding box should be determined.
bufferFloat >= 0.0 representing number of degrees by which to buffer the bounding box; 0.0 = no buffer, 0.01 = 0.01 degree buffer
Returns
A dict containing keys: minX, minY, maxX, maxY, srs, where srs='EPSG:4326'
def ecohydrolib.spatialdata.utils.getCoordinatesOfPointsFromShapefile (   shpFilepath,
  layerName,
  pointIDAttr,
  pointIDs 
)

Get WGS84 coordinates of point features in shapefile.

Parameters
shpFilepathString representing the path of the shapefile
layerNameString representing the name of the layer within the shapefile from to read points
pointIDAttrString representing name of the attribute used to identify points
pointIDsList of strings representing IDs of coordinate pairs

Exception if unable to read layer of shapefile, or if no feature(s) with given attribute value(s) were found in the shapefile

Returns
Tuple of floats of the form (longitude, latitude)
def ecohydrolib.spatialdata.utils.getDimensionsForRaster (   filename)

Get number of columns and rows for raster.

Uses GDAL library Code adapted from: http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/gdalinfo.py

Parameters
filenameString representing the DEM file to read pixel size and units
Returns
A tuple of the form: (columns, rows) or None if raster could not be opened
Exceptions
IOErrorif filename is not readable
def ecohydrolib.spatialdata.utils.getEPSGStringForUTMZone (   zone,
  isNorth 
)

Get EPSG string, e.g.

"EPSG:32618" for UTM zone (WGS84)

    @param zone Integer representing UTM zone
    @param isNorth True if north

    @return String of the pattern "^EPSG:\d+$"
def ecohydrolib.spatialdata.utils.getMeterConversionFactorForLinearUnitOfGMLfile (   gmlFilename)

Get conversion factor for converting a GML file's linear unit into meters.

Parameters
gmlFilenameString representing the GML file
Returns
Float representing the conversion factor
Exceptions
IOError(errno.EACCES)if the GML file cannot be opened
def ecohydrolib.spatialdata.utils.getMeterConversionFactorForLinearUnitOfShapefile (   shpFilename)

Get conversion factor for converting a shapefile's linear unit into meters.

Parameters
shpFilenameString representing the name of the shapefile
Returns
Float representing the conversion factor
Exceptions
IOError(errno.EACCES)if the shapefile cannot be opened
def ecohydrolib.spatialdata.utils.getNodataValuesForRaster (   filename)

Get nodata value for each band in a raster.

Uses GDAL library Code adapted from: http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/gdalinfo.py

Parameters
filenameString representing the DEM file path
Returns
List containing nodata values for each band
Exceptions
IOErrorif filename is not readable
def ecohydrolib.spatialdata.utils.getRasterExtentAsBbox (   extentRasterFilepath)

Determine raster extent and store it in a bbox along with the spatial reference system of the raster.

Parameters
extentRasterFilepathString representing the path of the raster whose extent we are interested in
Returns
Dict representing bounding box with keys: minX, minY, maxX, maxY, and srs

IOError(errno.ENOENT) if extentRasterFilepath does not exist IOError(errno.EACCESS) if extentRasterFilepath is not readable

def ecohydrolib.spatialdata.utils.getSpatialReferenceForRaster (   filename)

Get pixel size and unit for DEM.

Uses GDAL library Code adapted from: http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/gdalinfo.py

Parameters
filenameString representing the DEM file path
Returns
A tuple of the form: (pixelWidth, pixelHeight, linearUnitsName, linearUnitsConversionFactor, WKT SRS string, EPSG SRS string)
Exceptions
IOErrorif filename is not readable
def ecohydrolib.spatialdata.utils.getUTMZoneFromCoordinates (   longitude,
  latitude 
)

Determine the UTM zone for coordinate pair.

Parameters
longitudeFloat representing WGS84 longitude
latitudeFloat representing WGS84 latitude
Returns
Tuple of the form (zone number, true if north)
def ecohydrolib.spatialdata.utils.isCoordinatePairInBoundingBox (   bbox,
  coordinates 
)

Determine whether coordinate pair lies within bounding box.

Parameters
bboxA dict containing keys: minX, minY, maxX, maxY, srs, where srs='EPSG:4326'
coordinatesList of tuples of floats of the form (longitude, latitude), in WGS84
Returns
True if coordinates pair is within bounding box
def ecohydrolib.spatialdata.utils.isValidSrs (   srsString)

Determine if spatial reference string is valid.

Currently, only strings of the form 'EPSG:X...X' are valid.

Parameters
srsString
Returns
True if valid, False if invalid
def ecohydrolib.spatialdata.utils.mergeFeatureLayers (   config,
  outputDir,
  featureFilepaths,
  outLayerName,
  outFormat = 'GeoJSON',
  keepOriginals = False,
  t_srs = 'EPSG:4326',
  overwrite = False 
)

Combine vector feature files readable by OGR into a single feature layer.

Parameters
configA Python ConfigParser containing the section 'GDAL/OGR' and option 'PATH_OF_OGR2OGR'
outputDirString representing the absolute/relative path of the directory into which shapefile should be written
featureFilepathsArray of strings representing the absolute path of the feature files to convert
outLayerNameString representing the name of the merged GeoJSON feature. Extension '.geojson' will be added.
outFormatString representing output format supported by OGR listed in OGR_DRIVERS
keepOriginalsBoolean, if True, original feature layers will be retained (otherwise they will be deleted)
t_srsString representing the spatial reference system of the output feature, of the form 'EPSG:XXXX'
overwriteBoolean, if True any existing files will be overwritten
Returns
String representing the absolute path of the single feature file written
Exceptions
Exceptionif OGR returned an error.
def ecohydrolib.spatialdata.utils.resampleRaster (   config,
  outputDir,
  inRasterFilepath,
  outRasterFilename,
  s_srs,
  t_srs,
  trX,
  trY,
  resampleMethod = 'bilinear' 
)

Resample raster from one spatial reference system and resolution to another.

Note
Output raster will be in LZW-compressed GeoTIFF file.
Will silently return if output raster already exists.
Parameters
configPython ConfigParser containing the section 'GDAL/OGR' and option 'PATH_OF_GDAL_WARP'
outputDirString representing the absolute/relative path of the directory into which output raster should be written
inRasterFilepathString representing the path of the input raster
outRasterFilenameString representing the name of the output raster
s_srsString representing the spatial reference of the input raster, if s_srs is None, the input raster's spatial reference
t_srsString representing the spatial reference of the output raster
trXFloat representing the X resolution of the output raster (in target spatial reference units)
trYFloat representing the Y resolution of the output raster (in target spatial reference units)
resampleMethodString representing resampling method to use. Must be one of spatialdatalib.utils.RASTER_RESAMPLE_METHOD.
Exceptions
ConfigParser.NoSectionError
ConfigParser.NoOptionError
IOError(errno.ENOTDIR)if outputDir is not a directory
IOError(errno.EACCESS)if outputDir is not writable
ValueErrorif trX or trY are not floating point numbers greater than 0
Exceptionif a gdal_warp command fails
def ecohydrolib.spatialdata.utils.rescaleRaster (   config,
  outputDir,
  inRasterFilepath,
  outRasterFilename,
  scalar 
)

Rescale DN values of raster.

Note
Output raster will be in LZW-compressed GeoTIFF file.
Will silently return if output raster already exists.
Parameters
configPython ConfigParser containing the section 'GDAL/OGR' and option 'PATH_OF_GDAL_WARP'
outputDirString representing the absolute/relative path of the directory into which output raster should be written
inRasterFilepathString representing the path of the input raster
outRasterFilenameString representing the name of the output raster
scalarFloat representing scalar. Values can run from (-Inf, Inf).
Exceptions
ConfigParser.NoSectionError
ConfigParser.NoOptionError
IOError(errno.ENOTDIR)if outputDir is not a directory
IOError(errno.EACCESS)if outputDir is not writable
ValueErrorif scalar is not a floating point number
Exceptionif a gdal_calc.py command fails
def ecohydrolib.spatialdata.utils.tileBoundingBox (   bbox,
  threshold,
  t_srs = WGS84_EPSG_STR,
  divisor = BBOX_TILE_DIVISOR 
)

Break up bounding box into tiles if bounding box is larger than threshold.

Bounding box must be defined by WGS84 lat,lon coordinates

Parameters
bboxDict containing keys: minX, minY, maxX, maxY, srs, where srs='EPSG:4326'
thresholdFloat representing threshold area above which bounding box will be tiled. Units: sq. meters
t_srsString representing spatial reference system, in EPSG format, in which area should be calculated.
divisorFloat representing amount by which to divide tile sides, such that tile side = sqrt(threshold) / divisor
Returns
A list containing tiles defined as a dict containing keys: minX, minY, maxX, maxY, srs, where srs='EPSG:4326'
def ecohydrolib.spatialdata.utils.transformCoordinates (   sourceX,
  sourceY,
  t_srs,
  s_srs = "EPSG:4326" 
)

Transform a pair of X,Y coordinates from one reference system to another.

Parameters
sourceXA float representing the X coordinate
sourceYA float representing the Y coordinate
t_srsA string representing the spatial reference system of the output coordinates
s_srsA string representing the spatial reference system, in EPSG format, of the input coordinates
Returns
A tuple of floats representing the transformed coordinates
def ecohydrolib.spatialdata.utils.writeBboxPolygonToShapefile (   bbox,
  outputDir,
  layerName,
  overwrite = True 
)

Write bbox to a shapfile.

Parameters
bboxA dict containing keys: minX, minY, maxX, maxY, srs, where srs='EPSG:4326'
outputDirString representing the absolute/relative path of the directory into which shapefile should be written
layerNameString representing the name of the layer. Will be used as root of filename of output shapefile
overwriteTrue if existing shapefile should be overwritten.
Returns
String representing the name of shapefile created (not the absolute path)

IOError is output directory is not a writable directory Exception if shapefile already exists Exception is failed to create shapefile

def ecohydrolib.spatialdata.utils.writeCoordinatePairsToPointShapefile (   outputDir,
  layerName,
  pointIDAttr,
  pointIDs,
  coordinates,
  overwrite = True 
)

Write coordinates as a point shapefile.

Parameters
outputDirString representing the absolute/relative path of the directory into which shapefile should be written
layerNameString representing the name of the layer. Will be used as root of filename of output shapefile
pointIDAttrString representing name of the attribute used to identify points
pointIDsList of strings representing IDs of coordinate pairs
coordinatesList of tuples of floats of the form (longitude, latitude), in WGS84
overwriteTrue if existing shapefile should be overwritten.
Returns
String representing the name of shapefile created (not the absolute path)

IOError is output directory is not a writable directory Exception if shapefile already exists Exception is failed to create shapefile

Variable Documentation

float ecohydrolib.spatialdata.utils.BBOX_TILE_DIVISOR = 1.0
float ecohydrolib.spatialdata.utils.EAST = 90.0
tuple ecohydrolib.spatialdata.utils.EPSG_RE = re.compile('^epsg:\d+$')
tuple ecohydrolib.spatialdata.utils.GDAL_VERSION_RE = re.compile('^GDAL\s(\d{1,2})\.(\d{1,2})\.(\d{1,2}),\sreleased\s\d{4}/\d{2}/\d{2}\s*$')
float ecohydrolib.spatialdata.utils.NORTH = 0.0
dictionary ecohydrolib.spatialdata.utils.OGR_DRIVERS
Initial value:
1 = {OGR_SHAPEFILE_DRIVER_NAME: 'shp',
2  OGR_GEOJSON_DRIVER_NAME: 'geojson'}
string ecohydrolib.spatialdata.utils.OGR_GEOJSON_DRIVER_NAME = 'GeoJSON'
string ecohydrolib.spatialdata.utils.OGR_SHAPEFILE_DRIVER_NAME = 'ESRI Shapefile'
list ecohydrolib.spatialdata.utils.RASTER_RESAMPLE_METHOD = ['near', 'bilinear', 'cubic', 'cubicspline', 'lanczos', 'average', 'mode']
int ecohydrolib.spatialdata.utils.SHP_MAXX = 1
int ecohydrolib.spatialdata.utils.SHP_MAXY = 3
int ecohydrolib.spatialdata.utils.SHP_MINX = 0
int ecohydrolib.spatialdata.utils.SHP_MINY = 2
int ecohydrolib.spatialdata.utils.WGS84_EPSG = 4326
string ecohydrolib.spatialdata.utils.WGS84_EPSG_STR = 'EPSG:4326'