lib.geolib module¶
Geospatial functions for rasters, vectors.
-
class
pygeotools.lib.geolib.ProjBox(bbox, epsg)[source]¶ Object containing bbox geom and srs
Used for automatic projection determination
-
pygeotools.lib.geolib.bbox2geom(bbox, a_srs=<Mock name='mock.SpatialReference()' id='140299428549904'>, t_srs=None)[source]¶
-
pygeotools.lib.geolib.bilinear(px, py, band_array, gt)[source]¶ Bilinear interpolated point at(px, py) on band_array
-
pygeotools.lib.geolib.block_stats(x, y, z, ds, stat='median', bins=None)[source]¶ Compute points on a regular grid (matching input GDAL Dataset) from scattered point data using specified statistic
Wrapper for scipy.stats.binned_statistic_2d
Note: this is very fast for mean, std, count, but bignificantly slower for median
-
pygeotools.lib.geolib.block_stats_grid(x, y, z, ds, stat='median')[source]¶ Fill regular grid (matching input GDAL Dataset) from scattered point data using specified statistic
-
pygeotools.lib.geolib.copyproj(src_fn, dst_fn, gt=True)[source]¶ Copy projection and geotransform from one raster file to another
-
pygeotools.lib.geolib.corner_extent(ul, ll, ur, lr)[source]¶ Get min/max extent based on corner coord
-
pygeotools.lib.geolib.ds_cT(ds, x, y, xy_srs=<Mock name='mock.SpatialReference()' id='140299428549904'>)[source]¶ Convert input point coordinates to map coordinates that match input dataset
-
pygeotools.lib.geolib.ds_extent(ds, t_srs=None)[source]¶ Return min/max extent of dataset based on corner coordinates
xmin, ymin, xmax, ymax
If t_srs is specified, output will be converted to specified srs
-
pygeotools.lib.geolib.ell2geoid(lon, lat, z=0.0, geoid=<Mock name='mock.SpatialReference()' id='140299428549904'>)[source]¶
-
pygeotools.lib.geolib.gdaldem_mem_ds(ds, processing='hillshade', returnma=False, computeEdges=False)[source]¶ Wrapper for gdaldem functions
Uses gdaldem API, requires GDAL v2.1+
-
pygeotools.lib.geolib.gdaldem_mem_ma(ma, ds=None, res=None, extent=None, srs=None, processing='hillshade', returnma=False, computeEdges=False)[source]¶ Wrapper to allow gdaldem calculations for arbitrary NumPy masked array input Untested, work in progress placeholder Should only need to specify res, can caluclate local gt, cartesian srs
-
pygeotools.lib.geolib.gdaldem_wrapper(fn, product='hs', returnma=True, verbose=True)[source]¶ Wrapper for gdaldem functions
Note: gdaldem is directly avaialable through API as of GDAL v2.1
https://trac.osgeo.org/gdal/wiki/rfc59.1_utilities_as_a_library
This function is no longer necessry, and will eventually be removed.
-
pygeotools.lib.geolib.geoid2ell(lon, lat, z=0.0, geoid=<Mock name='mock.SpatialReference()' id='140299428549904'>)[source]¶
-
pygeotools.lib.geolib.geom2localortho(geom)[source]¶ Convert existing geom to local orthographic projection
Useful for local cartesian distance/area calculations
-
pygeotools.lib.geolib.geom2shp(geom, out_fn, fields=False)[source]¶ Write out a new shapefile for input geometry
-
pygeotools.lib.geolib.geom_dup(geom)[source]¶ Create duplicate geometry
Needed to avoid segfault when passing geom around. See: http://trac.osgeo.org/gdal/wiki/PythonGotchas
-
pygeotools.lib.geolib.geom_wh(geom)[source]¶ Compute width and height of geometry in projected units
-
pygeotools.lib.geolib.get_dem_mosaic_cmd(fn_list, o, fn_list_txt=None, tr=None, t_srs=None, t_projwin=None, georef_tile_size=None, threads=None, tile=None, stat=None)[source]¶ Create ASP dem_mosaic command Useful for spawning many single-threaded mosaicing processes
-
pygeotools.lib.geolib.get_geoid_offset(ds, geoid_srs=<Mock name='mock.SpatialReference()' id='140299428549904'>)[source]¶ Return offset for center of ds
Offset is added to input (presumably WGS84 HAE) to get to geoid
Note: requires vertical offset grids in proj share dir - see earlier note
-
pygeotools.lib.geolib.get_geoid_offset_ll(lon, lat, geoid_srs=<Mock name='mock.SpatialReference()' id='140299428549904'>)[source]¶
-
pygeotools.lib.geolib.get_outline(ds, t_srs=None, scale=1.0, simplify=False, convex=False)[source]¶ Generate outline of unmasked values in input raster
get_outline is an attempt to reproduce the PostGIS Raster ST_MinConvexHull function
Could potentially do the following: Extract random pts from unmasked elements, get indices, Run scipy convex hull, Convert hull indices to mapped coords
See this: http://stackoverflow.com/questions/3654289/scipy-create-2d-polygon-mask
This generates a wkt polygon outline of valid data for the input raster
Want to limit the dimensions of a, as notmasked_edges is slow: a = iolib.ds_getma_sub(ds, scale=scale)
-
pygeotools.lib.geolib.get_proj(geom, proj_list=None)[source]¶ Determine best projection for input geometry
-
pygeotools.lib.geolib.get_res(ds, t_srs=None, square=False)[source]¶ Get GDAL Dataset raster resolution
-
pygeotools.lib.geolib.get_res_stats(ds_list, t_srs=None)[source]¶ Return resolution stats for an input dataset list
-
pygeotools.lib.geolib.get_xy_1D(ds, stride=1, getval=False)[source]¶ Return 1D arrays of x and y map coordinates for input GDAL Dataset
-
pygeotools.lib.geolib.get_xy_grids(ds, stride=1, getval=False)[source]¶ Return 2D arrays of x and y map coordinates for input GDAL Dataset
-
pygeotools.lib.geolib.get_xy_ma(bma, gt, stride=1, origmask=True, newmask=None)[source]¶ Return arrays of x and y map coordinates for input array and geotransform
-
pygeotools.lib.geolib.gt_corners(gt, nx, ny)[source]¶ Get corner coordinates based on input geotransform and raster dimensions
-
pygeotools.lib.geolib.line2pts(geom, dl=None)[source]¶ Given an input line geom, generate points at fixed interval
Useful for extracting profile data from raster
-
pygeotools.lib.geolib.localortho(lon, lat)[source]¶ Create srs for local orthographic projection centered at lat, lon
-
pygeotools.lib.geolib.ma_fitplane(bma, gt=None, perc=(2, 98), origmask=True)[source]¶ Fit a plane to values in input array
-
pygeotools.lib.geolib.ma_fitpoly(bma, order=1, gt=None, perc=(2, 98), origmask=True)[source]¶ Fit a plane to values in input array
-
pygeotools.lib.geolib.mapToPixel(mX, mY, geoTransform)[source]¶ Convert map coordinates to pixel coordinates based on geotransform
Accepts float or NumPy arrays
GDAL model used here - upper left corner of upper left pixel for mX, mY (and in GeoTransform)
-
pygeotools.lib.geolib.mem_ds(res, extent, srs=None, dtype=<Mock name='mock.GDT_Float32' id='140299428550736'>)[source]¶ Create a new GDAL Dataset in memory
Useful for various applications that require a Dataset
-
pygeotools.lib.geolib.nps2geoid(x, y, z=0.0, geoid=<Mock name='mock.SpatialReference()' id='140299428549904'>)[source]¶
-
pygeotools.lib.geolib.pixelToMap(pX, pY, geoTransform)[source]¶ Convert pixel coordinates to map coordinates based on geotransform
Accepts float or NumPy arrays
GDAL model used here - upper left corner of upper left pixel for mX, mY (and in GeoTransform)
-
pygeotools.lib.geolib.raster_shpclip(r_fn, shp_fn, extent='raster', bbox=False, pad=None, invert=False, verbose=False)[source]¶ Clip an input raster by input polygon shapefile for given extent
-
pygeotools.lib.geolib.sample(ds, mX, mY, xy_srs=None, bn=1, pad=0, min_samp_perc=50, circ=False, count=False)[source]¶ Sample input dataset at map coordinates
This is a generic sampling function, and will return value derived from window (dimensions pad*2+1) around each point
By default, assumes input map coords are identical to ds srs. If different, specify xy_srs to enable conversion.
-
pygeotools.lib.geolib.scale_ps(lat)[source]¶ This function calculates the scaling factor for a polar stereographic projection (ie. SSM/I grid) to correct area calculations. The scaling factor is defined (from Snyder, 1982, Map Projections used by the U.S. Geological Survey) as:
k = (mc/m)*(t/tc), where:
m = cos(lat)/sqrt(1 - e2*sin(lat)^2) t = tan(Pi/4 - lat/2)/((1 - e*sin(lat))/(1 + e*sin(lat)))^(e/2) e2 = 0.006693883 is the earth eccentricity (Hughes ellipsoid) e = sqrt(e2) mc = m at the reference latitude (70 degrees) tc = t at the reference latitude (70 degrees)
The ratio mc/tc is precalculated and stored in the variable m70_t70.
From Ben Smith PS scale m file (7/12/12)
-
pygeotools.lib.geolib.shp2array(shp_fn, r_ds=None, res=None, extent=None, t_srs=None)[source]¶ Rasterize input shapefile to match existing raster Dataset (or specified res/extent/t_srs)
-
pygeotools.lib.geolib.shp2geom(shp_fn)[source]¶ Extract geometries from input shapefile
Need to handle multi-part geom: http://osgeo-org.1560.x6.nabble.com/Multipart-to-singlepart-td3746767.html
-
pygeotools.lib.geolib.shp_dict(shp_fn, fields=None, geom=True)[source]¶ Get a dictionary for all features in a shapefile
Optionally, specify fields
-
pygeotools.lib.geolib.sps2geoid(x, y, z=0.0, geoid=<Mock name='mock.SpatialReference()' id='140299428549904'>)[source]¶