I also create ArcPy geoprocessing tools using PyDev for Eclipse. Generally, I run my scripts as in-process geoprocessing tools in a custom toolbox (.tbx) from within ArcMap so that the import arcpy
happens instantly. If I run a script from outside of ArcMap, the import arcpy
step usually takes about 5 seconds on a Sandy Bridge Core i5.
I think your trouble may lie in the use of 64-bit Python and the ArcGIS 64-bit background geoprocessing package. I don't know why this would take so much longer to import compared to 32-bit ArcPy. If you want confirmation, you could iteratively add/remove Python libraries from the Python Interpreters menu you have and see if a specific folder is causing the excessive import times.
Personally, I haven't found a compelling need to use 64-bit geoprocessing. Even in some of the massive Spatial Analyst workflows I've had to implement, geoprocessing usually crashes before I hit memory limits. I prefer to divide my inputs before processing and merge them together at the end. This also ensures better compatibility with 3rd part modules, most of which are already compiled for 32-bit Python.
I also think there's a bunch of tweaks you can make to your code to make it faster, besides the import arcpy
issue and 64- vs. 32-bit Python. Creating a new searchCursor
object for each iteration of your fc_nodes
features is really slow. This means you are creating 6290 * 6290 = 39,564,100
search cursor objects. Creating each cursor object has processing overhead, so it's not surprising that this is taking many minutes to run. You want to avoid this code structure with nested cursors.
It appears that you are trying to find the counts of features in fc_links
with the value of the TONODENO
field equal to each possible value of the NO
field in fc_nodes
. Instead of using these nested cursors, it would be much easier to use the arcpy.Statistics_analysis()
tool, with the TONODENO
as the case field:
fc_links = "Rede_Cbr_MM_2008_WithoutMetro"
fieldname = "TONODENO"
statisticsTable = "OutputStatisticsTable"
arcpy.Statistics_analysis(fc_links, statisticsTable, [[fieldname,"COUNT"]], fieldname)
This is similar to do a Group By query in SQL, or a Totals query in Excel. In the output table, the FREQUENCY
column gives the number of features in fc_links
that have that value for the TONODENO
field. You can join this back table to the fc_nodes
table, or store it in a dictionary or something like that.
Don't make life more complicated, it's much easier:
- On Unix systems (Linux and Mac OS X) QGIS use the standard Python, installed by default. This is not the case in Windows where Python is not installed by default and there is no PYTHONPATH variable.
- Therefore QGIS installs its own version (with libraries in
C:\Program Files\QGIS Lyon\apps\Python27 in the Standalone version and a different location in the OSGeo4W installer)
So:
1) You can use the Python console as a classic Python shell using exclusively the QGIS Python with PyQGIS and the other modules installed by default, as Numpy (in C:\Program Files\QGIS Lyon\apps\Python27\Lib\site-packages) = the PYTHONPATH of the QGIS Python. You can control it by typing in the console
import sys
print sys.path
2) if you want to install an other Python module as Docutils, the problem is that Setuptools (setup.py, easy_install) or pip are not installed by default, even with the OSGeo4W installer, -> look at How to install 3rd party python libraries for QGIS on Windows?, QGIS Standalone and the Python Modules, Installing Python setuptools into OSGeo4W Python or OSGeo4W External Python Packages
At this stage, you have a full Windows Python version: you can use setup.py, easy_install or pip to install new modules, you don't need to fix the PYTHONPATH and you can use PyQGIS and the other modules installed in the QGIS site_packages folder
- via commands in the Python console
- via Python scripts in the Processing Toolbox or with the ScritRunner plugin of Gary Sherman
- via the development of custom Plugins
If you want to use other simple modules installed in other Python versions, simply use:
sys.path.append(path_of_the_module)
3) But if you want to use PyQGIS from outside (in other version of Python), it is another problem: search for on the GIS SE or the Web (as in Configure PyScripter to use with QGIS (and still use arcpy) on Windows, Standalone applications using QGIS and environment variables, and many others)
Best Answer
You need to add
%ARCGISINSTALLDIR%\bin
and%ARCGISINSALLDIR%\arcpy
to your paths as well.