I'm trying to automate map updating in ArcGIS Pro using Python. Essentially, I need the program to read a folder with GeoJSON files, import them into a map, and update it. When I use the code below, the data is imported into the geodatabase, but it's not added to the map. There are no errors occurring.
def conversion():
arcpy.conversion.JSONToFeatures(
in_json_file=r"D:\Programação\Python 3\pythonProject\Picarra.geojson",
out_features=r"D:\Geoprocessamento\Projetos\Teste02\Teste02.gdb\Mapateste_JSONToFeatures2",
geometry_type="POINT"
)
print('SUCESSO!')
-
1WHERE are you running the script?Hornbydd– Hornbydd2023年08月07日 16:05:32 +00:00Commented Aug 7, 2023 at 16:05
-
Currently, I am running the script in PyCharm.Bruno– Bruno2023年08月07日 16:38:36 +00:00Commented Aug 7, 2023 at 16:38
-
1You need to edit your question and show the full script and how you are accessing the active project.Hornbydd– Hornbydd2023年08月07日 18:29:34 +00:00Commented Aug 7, 2023 at 18:29
-
Actualy, this is the full script. Do you have any idea how can I do that?Bruno– Bruno2023年08月07日 22:40:10 +00:00Commented Aug 7, 2023 at 22:40
-
That's your issue, you are just calling a tool. You need to run it within ArcPro so that it knows to add it to an active map. Try running your script inside the python command line window inside ArcPro.Hornbydd– Hornbydd2023年08月07日 23:15:14 +00:00Commented Aug 7, 2023 at 23:15
1 Answer 1
Running code from inside ArcGIS has different behaviour than running code from outside (PyCharm). If you are running a script from outside of ArcGIS, then you need to also refer to the project, map and add the converted data to the map and finally save the aprx. Code might look like this:
arx_file_path = 'some/path/here/project.aprx'
in_json_file=r"D:\Programação\Python 3\pythonProject\Picarra.geojson",
out_features=r"D:\Geoprocessamento\Projetos\Teste02\Teste02.gdb\Mapateste_JSONToFeatures2"
# get the aprx
aprx = arcpy.mp.ArcGISProject(arx_file_path)
# get the map
m = aprx.listMaps("Your_Map_Name_HERE")[0]
# convert data
arcpy.conversion.JSONToFeatures(in_json_file,out_features,geometry_type="POINT")
# add data to map
m.addDataFromPath(out_features)
# save the aprx
aprx.save()
-
Or, if all your files have similar data, you don't add the feature to the map, you can re-source your layer in the map.danak– danak2023年08月11日 15:21:55 +00:00Commented Aug 11, 2023 at 15:21
-
I didn't understand, could you please explain a bit more?Bruno– Bruno2023年08月15日 14:08:15 +00:00Commented Aug 15, 2023 at 14:08
-
Now I have another issue: my code is returning the error "ERROR 000725: Output Feature Class: Dataset D:\Geoprocessing\Projects\Test02\Test02.gdb\Equipe1_JSONToFeatures already exists." Can you tell me what might be happening?Bruno– Bruno2023年08月15日 15:38:57 +00:00Commented Aug 15, 2023 at 15:38
Explore related questions
See similar questions with these tags.