1

I have a GeoJSON that I'm trying to convert to a feature class or shapefile using ArcPy.

The original GeoJSON is taken from a web link here:

geojson

Here's a sample of the GeoJSON:

{ "type": "FeatureCollection", "features": [{"type":"Feature","geometry":{"type":"Point","coordinates":[-122.4223477910157,37.79754300228804]},"properties":{":@computed_region_6qbp_sg9q":"105","point_city":"","location":"Greens Sports Bar",":@computed_region_26cr_cadq":"3","objectid":"1308","globalid":"{B1BEFBCB-BEB6-458A-B8C5-DDB016BAF2A2}","point_zip":"",":@computed_region_ajp5_b2md":"32","placement":"SIDEWALK",":@computed_region_qgnn_b9vv":"4","install_yr":"2003","install_mo":"0","address":"2239 POLK ST","lon":"-122.422348","street":"POLK","point_address":"","racks":"1","spaces":"2","point_state":"","lat":"37.797543"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-122.38985779819565,37.77014138205314]}

And then proccessed:

bikeLanesRaw = 'https://data.sfgov.org/resource/ygmz-vaxd.geojson'
bikeLanesRawResponse = urllib2.urlopen(bikeLanesRaw)
bikeLanesRaw_JSON = bikeLanesRawResponse.read()
#Write each response to JSON
foo = open(bikeFacilitiesFolder + "\\" + "bikeLanes_SF_2.json", "wb")
foo.write(bikeLanesRaw_JSON);
foo.close()

filename = bikeFacilitiesFolder + "\\" + "bikeLanes_SF_2.json"

And then I iterate through the features to use AsShape:

with open(filename, 'r') as fp:
# read json and add "features"
jData = json.loads(fp.read().decode("utf-8-sig").encode("utf-8"))
for feature in jData['features']:
    geom = feature["geometry"]
    point = arcpy.AsShape(geom)
    print(point)

I can successfully print the points, which gives me a series of:

<geoprocessing describe geometry object object at 0x17B0F480>
<geoprocessing describe geometry object object at 0x17B0F480>

But I'm unclear on what the next step is. Ideally, I want to use arcpy.JSONToFeatures_conversion to convert the JSON to features for use in ArcMap, but I'm unsure where to go from here once I've used AsShape.

  • 2
    Once you use AsShape, you have a Geometry object which can be inserted via an InsertCursor. JSONToFeatures is a completely different use pattern, not a follow-on to AsShape. – Vince Aug 7 at 21:25
  • I guess my real question is, using the geojson in the link provided above, what steps would I need to take to convert this to a feature class in arcPy? Eventually, I'm guessing I would want to use JSONtoFeatures, provided the format of the geojson is correct. – DiamondJoe12 Aug 7 at 21:47
  • Rather than provide only a link to a (presumably large) GeoJSON file when potential answerers may be like me and prefer not to follow links, I think you should cut that GeoJSON file down to a tiny sample that can be posted here as text, but still be used to show the error. – PolyGeo Aug 7 at 22:08
  • PolyGeo - thank you for your suggestion . I've added a sample of the GeoJSON. When using this GeoJSON in JSONToFeatures, I believe it is still not totally in the correct format, since it is failing. Though, I'm confused as to why, since the documentation explicitly states you can use a GeoJSON in JSONToFeatures. – DiamondJoe12 Aug 7 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.