Tag Info

Hot answers tagged

16

One of the developers of arcpy.da here. We got the performance where it is because performance was our primary concern: the main gripe with the old cursors were that they were slow, not that they lacked any particular functionality. The code uses the same underlying ArcObjects available in ArcGIS since 8.x (the CPython implementation of the search cursor, ...


12

The two are very, very close in functionality but not completely equivalent. Common to both Includes a set of tools with a unique alias for identification Can call from arcpy Get a Geoprocessing tool dialog (essentially a full UI) for free for each tool Can keep all Python code in one file (embedding tool source in TBX, holding all the implementation in ...


12

Since you are using v10.2 it is looking for the path of the Spatial Analyst toolbox which has changed directory locations slightly from v9: To update, open the ruggedness.py file using Notepad or some other text editor and change line 20 path to something like this: C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Toolboxes\Spatial Analyst Tools.tbx


11

What if you fed the points into a numpy array and used a scipy cKDTree to look for neighbors. I process LiDAR point clouds with large numbers of points (> 20 million) in several MINUTES using this technique. There is documentation here for kdtree and here for numpy conversion. Basically, you read the x,y into an array, and iterate over each point in the ...


10

One way to handle intermediate data is to use the in_memory workspace. For example: arcpy.Project_management(Footprints, "in_memory", out_coordinate_system) You can specify multiple in_memory objects by adding a name and path separator: "in_memory\temp1" "in_memory\temp2" ... If your datasets are very large and you are worried about cumulative ...


10

newarray = array * 2.0 performs the math on the entire array, not just on one element. It should instead be something like this: raster = arcpy.Raster(r"C:\test.jpg") array = arcpy.RasterToNumPyArray(raster) # modify cell array[0,0] *= 2.0 # save to a new raster newraster = NumPyArrayToRaster(array) newraster.save(r"C:\export.gdb\t") Or, if you want ...


10

You're using an arcpy.da.UpdateCursor. It by definition and design returns rows as lists, not as row objects. You need to use an arcpy.UpdateCursor if you want row objects. The old arcpy objects from 10.0 like arcpy.*Cursor are still there in 10.1 and still behave as expected. You can even use the old 9.3 arcgisscripting APIs and they'll still work the ...


10

Instead of using multiple RegExes to parse addresses, just use Esri's out of the box tool that is designed for this task, Standardize Addresses. It's available at all license levels and my experience with it has been positive.


10

What you are looking at is an Advanced Field Calculation. It's a little confusing because you're kind of referencing it backwards. If you right-click on a field in an attribute table and select the field calculator, you'll notice an option in the field calculator window to change the parser to Python as well as a check box named 'Show Code Block'. When ...


9

If PointID is one of the fields of fc, you can either use urow.GIS_ID_PAM = "PAM - " + str(urow.PointID) or urow.setValue("GIS_ID_PAM", "PAM - " + str(urow.getValue("PointID")) str() is not necessary if your PointID field is already of type "text". EDIT : example with .format() (based on Paul's comment) urow.setValue("GIS_ID_PAM", "PAM - ...


9

What about the following: fc = "path to input feature class" desc = arcpy.Describe(fc) areafieldname = desc.AreaFieldName Should work on various feature classes that have auto generated Area fields. This will exclude shapefiles.


9

A Dissolve operation will usually reduce the number of features, arcs and nodes within a layer, particularly for layers with significant lengths of shared boundaries. Since the time spent during a Buffering operation is highly dependent on the number of nodes, pre-processing with Dissolve may significantly reduce the running time (and memory requirements). ...


9

If memory use is your prime concern, then lots of little (low vertex count) features is probably going to be more to your liking than a few very large (high vertex count) features. But you may find that "too many features" may eventually overwhelm even "too many vertices" for processing speed. If you think about how the algorithms must be structured to ...


8

When you define the parameters for your script. For the "State" parameter, you have to set the "obtained from" parameter properties to "Prepared Footprint".


8

The ext is an object and not a list so Split won't work. What you can do is: list = [ext.XMin, ext.YMin, ext.XMax, ext.YMax]


8

I agree with Barbarossa that accessing the power of the da module would be beneficial. Here is very clean scripting approach: import arcpy fc = r'C:\Users\OWNER\Documents\ArcGIS\Default.gdb\samplePolyline' fields = ['x1','x2','y1','y2'] # Add fields to your FC for field in fields: arcpy.AddField_management(fc,str(field),"DOUBLE") with ...


8

A SearchCursor is read-only. You want to use an UpdateCursor. Also don't forget to call the cursor's updateRow method after setting a row's values. See Accessing data using cursors in the help for more information.


8

The following example shows how to integrate the built-in python method .upper() with the arcpy update cursor. This example first tests if a field is of type String then checks each row within that string for lowercase values. If there are lower case values, the row is updated with all upper case. import arcpy fc = r'C:\temp\test.gdb\yourFC' desc = ...


8

You can call the GP tools in two ways: arcpy.%toolbox%.%toolname% or arcpy.%toolname%_%toolbox% Both are calling the same function, so there is no difference. It is a matter of taste; I always call functions in the arcpy.Buffer_analysis format because I seem to read the name tool faster in this way (I see first the toolname, and often seeing the ...


8

In addition to using the new arcpy.da cursor, I would also suggest: You have many different search cursors on the same layer, see if you can eliminate some of those and pull your attributes from one or two Apply an Add Attribute Index on any column that you are querying against See if you can remove the select layer by attribute logic and apply that query ...


8

Run the field calc on the Summary field. Use Python as the parser and check the Show Codeblock box. For the Pre-Logic Script Code put: def Reclass(B, C, D, E): if None not in (B, C, D, E) and "" not in (B, C, D, E): return "Verified" else: return "In Progess" Then put this in the bottom box: Reclass(!B!, !C!, !D!, !E!) The ...


8

It's having a problem with the output directory, which is including a trailing slash: "C:\TEST\MIDLANDS\ZIP\CONVERSION\SHP\" Try taking that off and see if it works: "C:\TEST\MIDLANDS\ZIP\CONVERSION\SHP" You could also put this into a list/loop to simplify the syntax a little bit. SiteList = ["1AMBLABLSITE001", "1BODDBODDSITE001", etc.] for Site in ...


8

I would group with parens as follows if (calculation < -0.001 or calculation > 0.001) and linkup == " ":


8

Why would you want to avoid using an update Cursor? They will out perform the field calculator 100% of the time. You need to write this as an expression: import arcpy, datetime fc = r'C:\GIS\CARGIS\SHAPES.gdb\CRASH_ON_2013' field = "DTCARXTRCT" exp = '''def add_date(): import time return time.strftime("%Y/%m/%d")''' ...


7

In arcpy, When you implement the Search Cursor or Update Cursor you have the option of using the where_clause parameter, which will allow you to select a specific row based on a field value (e.g. row ID). This help file will show you how to build an appropriate SQL query for selecting a specific row.


7

Extract by attributes using "VALUE NOT IN (1,2,4,8,16,32,64,128)" (Thanks to @afalciano) will give you a new raster with only the cells where the value is different from your list.


7

After some more digging, this post answers my question: http://blog.technicallyliving.com/2013/08/arcpy-testing-for-selected-features/ desc=arcpy.Describe("layer_name") desc.FIDSet u'3; 4; 5; 6' The author says "FIDSet will return a semicolon delineated string of selected FIDs. When none are selected, it is blank". Problem solved, I think. Any other ...


7

You can run this code to get it: arcpy.env.workspace = NAME OF GDB HERE # Get stand alone FCs fccount = len(arcpy.ListFeatureClasses("","")) # Get list of Feature Datasets and loop through them fds = arcpy.ListDatasets("","") for fd in fds: oldws = arcpy.env.workspace arcpy.env.workspace = oldws + "\\" + fd fccount = fccount + ...


7

The arcpy.da.Walk() method is the way to go: import arcpy, os workspace = r"C:\Users\OWNER\Documents\ArcGIS\Default.gdb" feature_classes = [] for dirpath, dirnames, filenames in arcpy.da.Walk(workspace, datatype="FeatureClass", type="Any"): for filename ...


7

pyodbc library is capable of executing stored procedures. Check out the getting started guide here. It is a Python 2.x and 3.x module that allows you to use ODBC to connect to almost any database from Windows, Linux, OS/X, and more. It implements the Python Database API Specification v2.0, but additional features have been added to simplify ...



Only top voted, non community-wiki answers of a minimum length are eligible