I am writing a script which scrapes USGS earthquake data in GeoJSON format. I then try to create a shapefile using Arcpy copy features tool and I cannot seem to get it right
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[place] = [mag,x,y]
pointlist = []
point = arcpy.Point()
for k,v in earthquakes.items():
point.X = v[1]
point.Y = v[2]
magn = v[0]
place = k
pointGeometry = arcpy.PointGeometry(point)
pointlist.append(place)
pointlist.append(magn)
pointlist.append(pointGeometry)
arcpy.CopyFeatures_management(pointlist, "C:\Users\rzagha\Desktop\earthquake.shp")
I keep getting this error
Traceback (most recent call last):
File "<string>", line 254, in run_nodebug
File "<module1>", line 24, in <module>
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 2429, in CopyFeatures
raise e
RuntimeError: Object: Error in executing tool
when I print out the pointlist:
[u'29km SSW of Leilani Estates, Hawaii', 2.65, <PointGeometry object at 0x7dd47f0L[0x7d6d530L]>, u'67km NNW of Jayapura, Indonesia', 4.7, <PointGeometry object at 0x7dd4198L[0x128f3490L]>, u'61km NNE of Isabela, Puerto Rico', 2.9, <PointGeometry object at 0x7dd4668L[0x128f3c88L]>, u'61km N of Isabela, Puerto Rico', 2.9, <PointGeometry object at 0x7dd4278L[0x5917968L]>, u'150km SSW of Ndoi Island, Fiji', 5, <PointGeometry object at 0x7dd4240L[0x5917af8L]>, u'19km NE of La Paz Centro, Nicaragua', 5.5, <PointGeometry object at 0x7dd49e8L[0x5917ad0L]>, u'11km ESE of East Foothills, California', 3.25, <PointGeometry object at 0x7dd4208L[0x5917b20L]>, u'134km SE of Pangai, Tonga', 5, <PointGeometry object at 0x7dd4470L[0x5917b70L]>, u'23km ESE of Three Rivers, Oregon', 2.8, <PointGeometry object at 0x7dd4a90L[0x12b42f80L]>, u'27km ENE of Winnemucca, Nevada', 2.6, <PointGeometry object at 0x7dd4320L[0x12b42e68L]>, u'66km E of Namie, Japan', 4.6, <PointGeometry object at 0x7dd41d0L[0x12b42d28L]>, u'23km ENE of Mooreland, Oklahoma', 2.5, <PointGeometry object at 0x7dd4518L[0x12b42f58L]>, u'44km WNW of Piru, Indonesia', 4.6, <PointGeometry object at 0x7dcbdd8L[0x12b42a80L]>, u'13km WNW of Pawnee, Oklahoma', 2.8, <PointGeometry object at 0x7dcba90L[0x12b42d00L]>, u'21km SSE of Ridgemark, California', 2.84, <PointGeometry object at 0x7dcb668L[0x12b42760L]>, u'20km ESE of Little Lake, CA', 3.06, <PointGeometry object at 0x7dcbb70L[0x12b42dc8L]>, u'78km E of Old Iliamna, Alaska', 2.5, <PointGeometry object at 0x7dcb978L[0x12b42ee0L]>, u'Southeast of Easter Island', 5.2, <PointGeometry object at 0x7dcbd30L[0x12b42670L]>, u'47km S of Kangding, China', 4.4, <PointGeometry object at 0x7dcbcf8L[0x12b42d78L]>, u'114km S of Raoul Island, New Zealand', 5.3, <PointGeometry object at 0x7dcb8d0L[0x12b42c88L]>, u'126km SSE of Lambasa, Fiji', 4.5, <PointGeometry object at 0x7dcb6a0L[0x12b42738L]>, u'192km ENE of Saipan, Northern Mariana Islands', 5, <PointGeometry object at 0x7dcbc50L[0x12b42710L]>, u'99km S of San Pedro de Atacama, Chile', 4.2, <PointGeometry object at 0x7dcbc88L[0x12b428f0L]>, u'139km E of Shikotan, Russia', 4.8, <PointGeometry object at 0x5944c88L[0x12b42e90L]>, u'61km SSW of Santiago Pinotepa Nacional, Mexico', 5.1, <PointGeometry object at 0x7d96978L[0x12b425f8L]>, u'10km ESE of Cuajinicuilapa, Mexico', 5.2, <PointGeometry object at 0x59189b0L[0x12b42418L]>, u'33km N of Sutton-Alpine, Alaska', 2.9, <PointGeometry object at 0x59187b8L[0x12b42c10L]>, u'54km ENE of Fritz Creek, Alaska', 3, <PointGeometry object at 0x5918710L[0x12b42fd0L]>, u'North of Ascension Island', 4.9, <PointGeometry object at 0x5918908L[0x12b42da0L]>, u'78km SE of Lata, Solomon Islands', 4.8, <PointGeometry object at 0xacff978L[0x12b48468L]>, u'20km SSE of Guanica, Puerto Rico', 2.5, <PointGeometry object at 0x12b44048L[0x12b48e90L]>]
I am using this ESRI page to guide me http://pro.arcgis.com/en/pro-app/arcpy/classes/pointgeometry.htm
Should I try and create a feature class then use an insert cursor to update that shapefile? what is the reason the copy features tool is not taking in my pointgeometry?
I have also tried removing the place and magn variables and used just the x,y coordinates and I get the same error
from @artwork21 answer: i created a feature class in a GDB and used an insert cursor to insert the rows
def GeoJSONToFC(gdb,USGSurl,fcname):
import urllib2
import json
import arcpy
arcpy.env.overwriteOutput = True
geodb = gdb
url = USGSurl
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 = float(i["geometry"]["coordinates"][0]),float(i["geometry"]["coordinates"][1])
earthquakes.append([place,mag,[x,y]])
earthq = arcpy.CreateFeatureclass_management(geodb,fcname,"POINT",'','',"ENABLED",4326)
arcpy.AddField_management(earthq,"Place","TEXT")
arcpy.AddField_management (earthq, "Magnitude", "SHORT")
with arcpy.da.InsertCursor(earthq,["Place","Magnitude","SHAPE@XY"]) as cur:
for v in earthquakes:
place = v[0]
mag = v[1]
pointGeometry = arcpy.PointGeometry(arcpy.Point(*v[2]))
row = (place,mag,pointGeometry)
cur.insertRow(row)
print row
gdb = "C:\Users\Ralph\Desktop\quakes.gdb"
url = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/significant_month.geojson"
name = "MajorQuakes"
GeoJSONToFC(gdb,url,name)