Skip to content

Instantly share code, notes, and snippets.

@AlexArcPy
Created March 14, 2018 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AlexArcPy/50b6481c7096cf0b66b3c2f45e79ab4f to your computer and use it in GitHub Desktop.
Save AlexArcPy/50b6481c7096cf0b66b3c2f45e79ab4f to your computer and use it in GitHub Desktop.
ArcPy to WKT and from WKT
import arcpy
# read California cities features' geometries into a WKT string
arcpy.Multipoint(
arcpy.Array([
arcpy.Point(*coords) for coords in [
r[0] for r in arcpy.da.SearchCursor('cities', 'SHAPE@XY',
"STATE_NAME = 'California'",
arcpy.SpatialReference(3857))
]
])).WKT
# read California state feature's geometry into a WKT string
[
r[0] for r in arcpy.da.SearchCursor('states', 'SHAPE@',
"STATE_NAME = 'California'",
arcpy.SpatialReference(3857))
][0].WKT
# loading the Convex Hull polygon from JTS back into ArcMap
wkt_string = 'JTS result WKT'
chull = arcpy.FromWKT(wkt_string, arcpy.SpatialReference(3857))
arcpy.CopyFeatures_management(chull, 'in_memory/chull')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment