Thursday, June 2, 2011

GeoJSON to Geometry

Arcpy contains a helpful tool to convert GeoJSON objects to Geometry objects.  GeoJSON is a text representation of geographic features.  To convert GeoJSON to geometry use the AsShape(). This function can create the following geometries: Point, LineString, Polygon, MultiPoint, and MultiLineString.

GeoJSON Point to Point Geometry

import arcpy
gjPoint = {"type": "Point", "coordinates": [5.0, 5.0]}
ptGeometry = arcpy.AsShape(ptGeometry)


GeoJSON Multipoint to Multipoint Geometry

import arcpy
gjMultiPoint = {
"type": "MultiPoint",
"coordinates": [[5.0, 4.0], [8.0, 7.0]]}
multiPoint = arcpy.AsShape(gjMultiPoint)


GeoJSON Polyline to Polyline Geometry

import arcpy
gjLineString = {
"type": "LineString",
"coordinates": [[5.0, 4.0], [8.0, 7.0]]}
polyLine = arcpy.AsShape(gjLineString)


GeoJSON Polygon to Polygon Geometry

import arcpy
gjPolygon = {
"type": "Polygon",
"coordinates": [
[[10.0, 0.0], [20.0, 0.0], [20.0, 10.0], [10.0, 10.0], [10.0, 0.0]]]}
polygon = arcpy.AsShape(gjPolygon)


(sample code came from webhelp.esri.com)

Enjoy