Utilities¶
A collection of utility functions and
PathUtils.py¶
General path utilities for workspaces and routing to map documents behind map services
- utilities.PathUtils.extractLayerPathFromMSDLayerXML(msd, xmlPath)¶
Extracts layer data source from layer XML files stored in MSD.
Parameters: - msd – MSD file opened via ZipFile
- xmlPath – path to XML file with layerInfo
Returns: list of layer paths, or None for each group layer; index in this list = layerID
- utilities.PathUtils.getDataPathsForService(serviceID)¶
Extract paths for data layers in map service. Returns cached lookup if possible.
Parameters: serviceID – Returns: return list of layers paths (or None for group layers); order in this list = layerID
ProjectionUtilities.py¶
General utilities for helping deal with projection related information
- utilities.ProjectionUtilities.getGCS(spatialReference)¶
Return the geographic coordinate system name for the spatial reference (e.g., GCS_North_American_1983).
Parameters: spatialReference – ArcGIS spatial reference object
- utilities.ProjectionUtilities.getProjUnitFactors(spatialReference)¶
Return the conversion factors for projection length to kilometers, projection area to hectares, and meters per projection unit for the spatial reference. Used to multiply the length and area calculated for features.
Parameters: spatialReference – ArcGIS spatial reference object Note
Limited to projections based on Meter and Foot_US
- utilities.ProjectionUtilities.getWGS84GeoTransform(gcs)¶
Find a general geographic transformation from one coordinate system to WGS 1984. These transformations are based on the continent scale transformations listed by ESRI, and are not exact for local calculations. Only the following source geographic coordinate systems are currently supported:
- NAD 1983
- NAD 1983 HARN
- NAD 1983 CRS
- SAD 1969
- ED 1950
Parameters: gcs – the input geographic coordinate system name extracted from the source projection well-known text Note
Target geographic coordinate system is always WGS 1984
- utilities.ProjectionUtilities.getGeoTransform(srcSR, targetSR)¶
Return the geographic transformation required to project between two projections (passing through WGS 1984, if required), or empty string if not required.
Parameters: - srcSR – source ArcGIS spatial reference object
- targetSR – target ArcGIS spatial reference object
Note
limited to the geographic coordinate systems supported by getWGS84GeoTransform
- utilities.ProjectionUtilities.projectExtent(extent, srcSR, targetSR)¶
Project the extent to the target spatial reference, and return the projected extent. Creates a temporary feature class based on bounding box of source.
Parameters: - extent – source extent
- srcSR – source ArcGIS spatial reference object
- targetSR – target ArcGIS spatial reference object
- utilities.ProjectionUtilities.createCustomAlbers(extent)¶
Given an extent in geographic coordinates, create a custom Albers projection centered over the extent that minimizes area distortions. Uses 1/6 inset from YMin and YMax to define latitude bounds, and centerline between XMin and XMax to define central meridian.
Parameters: extent – extent in geographic coordinates Returns: custom Albers spatial reference
- utilities.ProjectionUtilities.getSpatialReferenceFromWKID(WKID)¶
Returns a spatial reference object for WKID
Parameters: WKID – ESRI Well Known ID Returns: spatial reference object
- utilities.ProjectionUtilities.isValidAreaProjection(spatialReference)¶
Determines if projection is valid for area calculations.
Parameters: spatialReference – spatial reference object Returns: True if valid for area projections, False otherwise
FeatureSetConverter.py¶
Converts a featureset in JSON into a feature class in memory
- utilities.FeatureSetConverter.getFeatureGeometry(geomType, geometry)¶
Extract geometry from featureset JSON, and convert into geometry representation required for feature class.
Parameters: - geomType – ArcGIS JSON geometry type: esriGeometryPoint, esriGeometryMultipoint, esriGeometryPolyline, esriGeometryPolygon
- geometry – the geometry object extracted from JSON
- utilities.FeatureSetConverter.createFeatureClass(featureSet, name='drawingFC')¶
Create an in-memory feature class from a featureset JSON.
Parameters: - featureSet – the featureset JSON string.
- name – name of output feature class (always in memory)
Note
the original feature IDs (FID / OBJECTID) are not preserved in feature class, as they are built up fresh during construction of feature class.