Write JSON from Website to Feature Class

539
4
Jump to solution
03-07-2023 10:11 AM
kapalczynski
Occasional Contributor III

Any thoughts?

 

If I copy this JSON from this location (web link) to a local file I can import to File GDB.

import arcpy
import os
arcpy.env.workspace = r"C:\Users\xx\Desktop\GIS\IMPORT DEQ DATA"
arcpy.conversion.JSONToFeatures("myjsonfeatures.json", os.path.join("Datasets.gdb", "myfeatures"))

 

But I want to read the URL live as I want to run this script a couple times a day.  How do I do that...

I tried the below but does not work

import arcpy
import os
geoJSON = "https://apps.deq.virginia.gov/arcgis/rest/services/public/EDMA/MapServer/104/query?outFields=*&where=1%3D1&f=geojson"
arcpy.env.workspace = r"C:\Users\xxx\Desktop\GIS\IMPORT DEQ DATA"
arcpy.conversion.JSONToFeatures(geoJSON, os.path.join("DEQ_Datasets.gdb", "myfeatures"))

 

 

", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000814: Invalid file type
Failed to execute (JSONToFeatures).

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Think the only thing you can do is write it to a file each time since the JSONToFeatures needs a txt file input. You can use the json dumps to write it.

 

with open("sample.json", "w") as outfile:
    json.dump(injson, outfile)

 

View solution in original post

4 Replies
by Anonymous User
Not applicable

Think the only thing you can do is write it to a file each time since the JSONToFeatures needs a txt file input. You can use the json dumps to write it.

 

with open("sample.json", "w") as outfile:
    json.dump(injson, outfile)

 

kapalczynski
Occasional Contributor III

So I cannot read it live into the Feature Class... I have to write it local everytime?

0 Kudos
by Anonymous User
Not applicable

You could go the Json to pandas df, then df to dictionary, then to featureclass to keep it stateless, but if you want to use the JSONToFeatureclass method, then you'll have to write it to a file each time.

0 Kudos
kapalczynski
Occasional Contributor III

Is there any other way possible to do this with the service URL I provided?

 

0 Kudos