Load GeoJSON in ArcMap

2 Feb

It came up on Twitter that you cannot edit GeoJSON in ArcMap. That gave me the idea to try and write a plugin that allows just that. This post will layout a procedure for editing GeoJSON in ArcMap. The final code solution needs work, but it is a good start.

Reading GeoJSON in ArcMap

I grabbed a text file from my Github and saved it to my desktop. This is not the best example, but it was good enough to test the process. I started by reading the file in to ArcMap. The code reads in the file and converts it to JSON. It then iterates through the features, grabbing the coordinates and putting them in to an array.  Lastly, it writes it to a default geodatabase.

import arcpy
from arcpy import env
import json
d=open(r”C:\Users\paul\Desktop\art.geojson”)
data=json.load(d)
points=[]
i=0
for x in data[“features”]:
points.append(arcpy.PointGeometry(arcpy.Point(data[“features”][i][1],data[“features”][i][0])))
i=i+1
arcpy.CopyFeatures_management(points,”testlayer13″)

You will have a map like the image below.

GeoJSON pointsl oaded via Python in ArcMap

GeoJSON pointsl oaded via Python in ArcMap

Writing GeoJSON in ArcMap

You can now use the editing toolbar to draw and edit features as you would any other data source in ArcMap. In the image below, I have deleted most of the features.

Features remaining after edit.

Features remaining after edit.

 

When you have finished editing, you can save out the data as GeoJSON by reading the feature class, grabbing the field that holds the geometry and then writing it out to a text file.

arcpy.env.workspace=r”c:\users\paul\documents\arcgis\default.gdb”
desc=arcpy.Describe(r”c:\users\paul\documents\arcgis\default.gdb\testlayer13″)
shapefieldname=desc.ShapeFieldName
rows = arcpy.SearchCursor(“testlayer13″)
out=open(r”c:\users\paul\desktop\DONE.txt”,”w+”)
out.write(‘{“type”: “FeatureCollection”,”features”: [\n’)
for row in rows:
feat=row.getValue(shapefieldname)
pnt=feat.getPart()
out.write(‘[‘+str(pnt.X)+’,’+str(pnt.Y)+’],’)
out.write(‘]}’)
out.close()

The output is a textfile with GeoJSON.

The GeoJSON output

The GeoJSON output

 

Not pretty, but a start for how I would go about it. Would need to figure out how to do this for polygons and polylines.

Advertisements

4 Responses to “Load GeoJSON in ArcMap”

  1. Rene Rubalcava (@odoenet) February 2, 2015 at 3:48 pm #

    That’s pretty neat. You could put that into a toolbox and I think you can add buttons in ArcMap to execute scripts, I haven’t tried it in a while. For the polygons and polylines, you could try out this script I was using to do conversions in a test project.
    https://github.com/odoe/SpatialJSON/tree/master/utils

    I’m sure it’s got some bugs, but might be useful.

  2. kampar February 5, 2015 at 3:39 am #

    Reblogged this on Dosen GIS and commented:
    buat yang ngga mau pake QGIS … eh?

  3. jon November 24, 2015 at 6:16 pm #

    exactly what i was looking for…thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: