1

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!')

ArcGIS Pro Print Screen

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Aug 7, 2023 at 15:50
6
  • 1
    WHERE are you running the script? Commented Aug 7, 2023 at 16:05
  • Currently, I am running the script in PyCharm. Commented Aug 7, 2023 at 16:38
  • 1
    You need to edit your question and show the full script and how you are accessing the active project. Commented Aug 7, 2023 at 18:29
  • Actualy, this is the full script. Do you have any idea how can I do that? Commented 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. Commented Aug 7, 2023 at 23:15

1 Answer 1

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()
answered Aug 8, 2023 at 0:52
3
  • 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. Commented Aug 11, 2023 at 15:21
  • I didn't understand, could you please explain a bit more? Commented 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? Commented Aug 15, 2023 at 15:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.