- Download PyCharm IDE.
- Install PyCharm IDE.
- Start PyCharm IDE.
- Create New Project. If you have existing interpreters, choose the one that was installed by ArcGIS.

- Open File-Settings (or Ctrl+Alt+S).
- Click on Project Interpreter.

- Click on the gear icon (near the top right corner of the window).
- Select "Create VirtualEnv". This will give you a separate Python environment for each project.
- Give the virtual environment a name and location.
- Check "Inherit global site-packages".

- Click OK to clear the Settings windows.
- Go to the Project window.
- Right-click on "MyFirstArcpyProject".
- Select New-Python File.

- Call the new Python file "ExtractSpatialData.py".
- Go to your ArcMap or ArcCatalog's geoprocessing results frame.
- Right-click on the operation that you want to reuse.

- Click on "Copy As Python Snippet".
- Go to the PyCharm window.
- Paste the clipboard contents in ExtractSpatialData.py.
- Go to the top of the file.
- Add the line "import arcpy".
- Add the line "arcpy.env.workspace = <path to your datasets>".

- Run ExtractSpatialData.py (Ctrl+Shift+F10).
Instead of setting arcpy.env.workspace, you can also use the full path name to your input, clip, and output feature classes. If you are using extensions such as spatial analysis, you will need to checkout the license, e.g. arcpy.CheckOutExtension("Spatial"). See checkoutextension for more details.
No comments:
Post a Comment