Hot answers tagged arcgisscripting
33
Although this question was already answered, I thought I could chime in an give my two cents.
DISCLAIMER: I worked for ESRI at the GeoDatabase team for some years and was in charge of maintaining various parts of GeoDatabase code (Versioning, Cursors, EditSessions, History, Relationship Classes, etc etc).
I think the biggest source of performance problems ...
8
In 9.3 you can use the following diagram:
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=979&pid=977&topicname=Geoprocessor_programming_model
In 10 they switched to using arcpy:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/What_is_ArcPy/000v000000v7000000/
Hope this helps
8
I'd take a look at NumPy and Scipy - there's a good example of interpolating point data in the SciPy Cookbook using the scipy.interpolate.griddata function. Obviously this requires that you have the data in a numpy array;
Using the GDAL python bindings you can read your data into Python
using gdal.Dataset.ReadAsArray() for a raster.
With OGR you would loop ...
7
Try changing
Output_polygon_features = "D:\\J04-0083\\ShapeFiles.gdb\\" + "SH_" + filename + ".shp"
to
Output_polygon_features = "D:\\J04-0083\\ShapeFiles\\" + "SH_" + filename + ".shp"
And rename your output directory accordingly.
I think ArcGIS is getting confused between creating a feature class called "SH_" + filename + ".shp" in a file ...
7
If you are using ArcGIS 10.1 you can use the data access module which speeds up performance and, in my opinion, has a simpler syntax than the traditional cursors. However this module is only available for 10.1 so only use it if you are sure you will not need to run your code in older environments.
6
Have a look at the GDAL gridding API. I don't know if that is exposed in the Python bindings, but if not, you call call the gdal_grid utility via the subprocess module.
GDAL grid API only uses Inverse Distance Weighting, Moving Average and Nearest Neighbour, it doesn't implement splines. Another option is to use Scipy.
5
As of ArcGIS 10 its called arcpy. Keep in mind, you can also call all of the tools found in the Geoprocessing Tool Reference.
5
The Updating and fixing data sources with arcpy.mapping help topic has an example of how to loop through .mxd's in a folder (as well as other useful arcpy examples) but my preference for how to do this would be to use glob. Something like this:
import glob
mxdList = glob.glob('*.mxd')
for mxd in mxdList:
<put everything from your try/except block ...
5
Generally, for performance computations, I try to stay away from using any ESRI related stuff. For your example, I would suggest doing the process in steps, the first step reading the data into normal python objects, doing the calculations, and then the final step converting to the final ESRI spatial format. For ~10k records, you could probably get away with ...
5
Alice,
Answered you over on the ESRI Python Forum
http://forums.arcgis.com/threads/18825-Raster-to-polygon-script-loop-failing!!-error-99999!?p=60693#post60693
Full annotation and reworked script, but the essence of the problem was trying to name the feature class in the File Geodatabase with a .shp extension. And then not cleaning up after each script ...
5
I would think that using CalculateField_management would be faster than using a cursor as well, as you are not iterating through each record like you are with a cursor. If you need to, you can use a Python expression in the call. Available at 10.0 (and 9.x for that matter).
4
I would suggest trying to print out the output at each step of your program. For example:
for root, dirs, filenames in os.walk(folder): # returms root, dirs, and files
for filename in filenames:
print filename
filename_split = os.path.splitext(filename)
print filename_split
filename_zero = filename_split[0]
print ...
4
This is the method I use:
create a small python script called kill_processx.py
When run kill_processx creates a small test file called stop_processx.txt.
At the top or bottom of the loop in the main program check to see if the stop_processx.txt exists.
If it does exist, execute any cleanup routines you need, then stop gracefully.
Delete the ...
4
Unless you are using geoprocessing tools that are exclusive to 10.1, you should be able to convert it backwards.
First export your model to python from model builder.
then change
import arcpy
to
import arcgisscripting
next set a variable to the arcgisscripting module you imported
gp = arcgisscripting.create()
after that you need to import your gp ...
4
As @Zachary mentioned, the key is:
using tools that are available in both 10.1 and 9.3 at the same license level (don't forget that some tools changed license from 9.3 to 10.1)
change "import arcpy" to "import arcgisscripting"
If you really wanted to be sneaky, though, instead of creating a new variable called gp, from: gp = arcgisscripting.create() and ...
3
I think there may be unavoidable cursor transaction overhead to slow you down unless there is a way to update a large batch of rows at once. Comment out "cur.updaterow(row)" and run it again... is there a difference?
The secondary slow down in your case is a lot of unnecessary copying. dict.keys() copies values and you have many. Better to do "if k in dict" ...
3
What version of ArcMap are you using? I am assuming it is ArcGIS 10 and not 9.x. According to the Calculate Field help file, in ArcGIS 10:
VBScript does not allow you explicitly declare any data types; all variables are implicitly Variant. Statements like Dim x as String should be removed or simplified to Dim x.
This worked for me in Arc 10:
...
3
Here is a link to an Esri tech article "HowTo: Use VBA functions in the Field Calculator." Take a look at the Right Function which "...Returns a Variant (String) containing a specified number of characters from the right side of a string." An example is included on the page. You will have to add the new field separately, then use the right function to ...
3
if you want to solve in pythonic way, try this:
import sys
sys.exit()
or use:
raise SystemExit()
in detail:
import time
import sys
sTime= time.time()
if time.time() - sTime > 60:
sys.exit()
i hope it helps you...
3
UPDATE 2:
Just tested it and ESC doesn't work either. ArcGIS just freezes for a moment and then continues. There doesn't seem to be a way to do force quit it once it runs in the ArcGIS Python console. You can't kill it using Task Manager either as the Python process doesn't show up there.
If you really want to be able to force quit it, you might want to ...
3
It is bad practice to force shutdown using brute force tactics. Rather, as @Aragon pointed out you should add error handling to your script to isolate components and/or stop the script if certain conditions are not met. As @R.K. points out, the ArcGIS python console is next to worthless for running complex scripts and, in practice, should be reserved for ...
2
Okay, here are a couple of things:
I don't think the indention level of
the code you posted is correct. The
variable filename is
used outside its scope, for example.
Some uses of os.path.join in that code are pointless. The string fragments should be arguments: os.path.join(root, filename_zero + ".png")
It is a good practice to avoid using
try..except in ...
2
Did you 'Validate' the expression? Does it pass? Is this an FGDB or a PGDB table? For FGDB enclose the field in "" - double quotes, for shapefile i think it's also double quotes. Each uses different "field" enclosure. If the expression passes validation, check for Null values. Also make sure the field is numeric (as was already mentioned)
2
I am not sure what is your workflow, but for interpolation of Z's between known values (all at existing vertices) I used ArcObjects IZ.InterpolateZsBetween. I've been trying to interpolate with Calibration tool previously, however this tool have a bug. I'm not sure if it fits your purpose, but see code below for IZ.InterpolateZsBetween.
# import arcobjects ...
2
You shouldn't have to create the featureclass first using gp.CreateFeatureClass. CopyFeatures should create it for you. Try that and see what you get. And it sounds like you are using a layer selection, otherwise all of your features will get copied and not just your selected ones.
2
Try the RasterCatalog feature_type argument:
datasetList = arcpy.ListDatasets("C*", "RasterCatalog")
for dataset in datasetList:
print dataset
EDIT:
OK, above won't work on 9.3, so what about getting the DatasetType of each object and if it is of type RasterCatalog, then list it (below code untested)?
datasets = gp.ListDatasets("", "ALL")
for ...
2
Based on your edit to your question, it looks like you need to parse out parts of the old path to build the new path. How about splitting up the old path into a list, then building the new path with parts of that list:
>>> import os
>>> old_path = "\\dgdbimg\EGD\Data\DTED_2"
>>> old_parts = old_path.split("\\")
>>> ...
2
Hopefully the following recommendations will give you some ideas:
# Local variables
input = arcpy.GetParameterAsText(0) # Set data type: featureclass, shapefile, or table
pop_rank = arcpy.GetParameterAsText(1) # Set as data type: SQL expression
rows = arcpy.UpdateCursor (input, "", "", "", "pop A")
for row in rows:
row.setValue("RANK", ...
2
When you say 'same time' do you mean in the same process? If not, I would suggest using virtualenv. This is a python tool that allows you to have multiple installations of python with their own site-packages.
pip install virtualenv or easy_install virtualenv
Then when you create a virualenv to work in use the -p path/to/python/2.7. This tells the ...
2
On your script tool parameters definitions, create a derived, output parameter and set it using SetParameterAsText in your script.
This still depends on the Add results of geoprocessing operations to the display setting under Geoprocessing-Geoprocessing Options being checked, however.
(ignore the ModelBuilder part)
See also:
Setting script tool ...
Only top voted, non community-wiki answers of a minimum length are eligible




