Skip to main content
added 499 characters in body
Source Link
crmackey
  • 8.5k
  • 19
  • 33

Just wanted to add that what you were trying to do does work with some small tweaks:

import urllib2
import json
import arcpy
url = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson"
weburl = urllib2.urlopen(url)
if weburl.getcode() == 200:
    data = json.loads(weburl.read())
earthquakes = []
for i in data["features"]:
    mag, place = i["properties"]["mag"],i["properties"]["place"]
    x,y = i["geometry"]["coordinates"][0],i["geometry"]["coordinates"][1]
    earthquakes.append([place,mag,[x,y]])
m = []
sr = arcpy.SpatialReference(4326)
for v in earthquakes:
    place = v[0]
    magn = v[1]
    m.append(arcpy.PointGeometry(arcpy.Point(*v[2]), sr))
    print place,magn,type(m)
arcpy.CopyFeatures_management(m, "C:\\Users\\rzagha\\Desktop\\earthquake.shp")

For copy features to work this way, you can pass in a list of arcpy.PointGeometry() objects. With this, you do need to provide a spatial reference (wkid 4326 is WGS1984).

However, as @artwork21 suggested, Creating a new feature class with all the schema predefined with an insert cursor would be the way to go. Then you could just map all the geojson field info in there at the same time.

Also, it is worth noting you can get a PointGeometry object by using the arcpy.AsShape() function:

pt = arcpy.AsShape(i["geometry"], False)
pt.spatial_reference = arcpy.SpatialReference(4326) # set sr to WGS 1984

This is the same as:

pt = arcpy.AsShape({u'type': u'Point', u'coordinates': [-117.4365, 41.0826, 11.5]})

Just wanted to add that what you were trying to do does work with some small tweaks:

import urllib2
import json
import arcpy
url = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson"
weburl = urllib2.urlopen(url)
if weburl.getcode() == 200:
    data = json.loads(weburl.read())
earthquakes = []
for i in data["features"]:
    mag, place = i["properties"]["mag"],i["properties"]["place"]
    x,y = i["geometry"]["coordinates"][0],i["geometry"]["coordinates"][1]
    earthquakes.append([place,mag,[x,y]])
m = []
sr = arcpy.SpatialReference(4326)
for v in earthquakes:
    place = v[0]
    magn = v[1]
    m.append(arcpy.PointGeometry(arcpy.Point(*v[2]), sr))
    print place,magn,type(m)
arcpy.CopyFeatures_management(m, "C:\\Users\\rzagha\\Desktop\\earthquake.shp")

For copy features to work this way, you can pass in a list of arcpy.PointGeometry() objects. With this, you do need to provide a spatial reference (wkid 4326 is WGS1984).

However, as @artwork21 suggested, Creating a new feature class with all the schema predefined with an insert cursor would be the way to go. Then you could just map all the geojson field info in there at the same time.

Just wanted to add that what you were trying to do does work with some small tweaks:

import urllib2
import json
import arcpy
url = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson"
weburl = urllib2.urlopen(url)
if weburl.getcode() == 200:
    data = json.loads(weburl.read())
earthquakes = []
for i in data["features"]:
    mag, place = i["properties"]["mag"],i["properties"]["place"]
    x,y = i["geometry"]["coordinates"][0],i["geometry"]["coordinates"][1]
    earthquakes.append([place,mag,[x,y]])
m = []
sr = arcpy.SpatialReference(4326)
for v in earthquakes:
    place = v[0]
    magn = v[1]
    m.append(arcpy.PointGeometry(arcpy.Point(*v[2]), sr))
    print place,magn,type(m)
arcpy.CopyFeatures_management(m, "C:\\Users\\rzagha\\Desktop\\earthquake.shp")

For copy features to work this way, you can pass in a list of arcpy.PointGeometry() objects. With this, you do need to provide a spatial reference (wkid 4326 is WGS1984).

However, as @artwork21 suggested, Creating a new feature class with all the schema predefined with an insert cursor would be the way to go. Then you could just map all the geojson field info in there at the same time.

Also, it is worth noting you can get a PointGeometry object by using the arcpy.AsShape() function:

pt = arcpy.AsShape(i["geometry"], False)
pt.spatial_reference = arcpy.SpatialReference(4326) # set sr to WGS 1984

This is the same as:

pt = arcpy.AsShape({u'type': u'Point', u'coordinates': [-117.4365, 41.0826, 11.5]})
Source Link
crmackey
  • 8.5k
  • 19
  • 33

Just wanted to add that what you were trying to do does work with some small tweaks:

import urllib2
import json
import arcpy
url = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson"
weburl = urllib2.urlopen(url)
if weburl.getcode() == 200:
    data = json.loads(weburl.read())
earthquakes = []
for i in data["features"]:
    mag, place = i["properties"]["mag"],i["properties"]["place"]
    x,y = i["geometry"]["coordinates"][0],i["geometry"]["coordinates"][1]
    earthquakes.append([place,mag,[x,y]])
m = []
sr = arcpy.SpatialReference(4326)
for v in earthquakes:
    place = v[0]
    magn = v[1]
    m.append(arcpy.PointGeometry(arcpy.Point(*v[2]), sr))
    print place,magn,type(m)
arcpy.CopyFeatures_management(m, "C:\\Users\\rzagha\\Desktop\\earthquake.shp")

For copy features to work this way, you can pass in a list of arcpy.PointGeometry() objects. With this, you do need to provide a spatial reference (wkid 4326 is WGS1984).

However, as @artwork21 suggested, Creating a new feature class with all the schema predefined with an insert cursor would be the way to go. Then you could just map all the geojson field info in there at the same time.