Tag Info

Hot answers tagged

17

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, ...


13

If the length of the ID field values is always constant I would recommend using either Field Calculator or Calculate Fields tool with python slices. TOWN calculation: !ID![:8] ERF calculation !ID![8:16] PORTION calculation !ID![-5:]


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

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

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

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

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

In cursors, length is a read-only property. I couldn't imagine what a predictable outcome would be for setting a new length of a line. Would it just extend the last point out in the bearing from the next to last point? What if it were multipart? Would it grow the entire polyline segment by segment?


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")''' ...


8

Python is treating \t as tab so you are really doing C{TAB}est you need to escape with \\ or use a raw string using r e.g r'C:\test_script'


7

This just plain won't work, you're going to need to look into multiprocessing if you want parallelism. ArcGIS Desktop/Server's architecture is based on the COM Single-Threaded Apartment model, meaning that any objects created on one thread can only be used on that thread. You can create a new ArcObjects object graph on another thread (see the linked ...


7

Try something like this: import arcpy from arcpy import env env.workspace = "E:\Example.gdb" # here you are creating a list of all features from your workspace lst = arcpy.ListFeatureClasses("", "Polyline") # and here you are looping for featureClass in lst: arcpy.CreateRandomPoints_Management(


7

If they are all have the same name schema then you should be able to do the following: import arcpy arcpy.env.workspace = 'LOCATION OF THE GDB' fcs = arcpy.ListFeatureClasses("*cnty*","") for fc in fcs: arcpy.Rename_management(fc, "%s%s" % (fc[0:1],fc[-2:]))


7

You can loop through the FC first and find them maximum value. Example: import arcpy nullvalues = ["", " ", None, 0] # Loop through and get Max value cur = arcpy.SearchCursor("Telecommunications Line") fac_id_values = [int(row.FACILITYID[-4:]) for row in cur if row.FACILITYID not in nullvalues] max_value = max(fac_id_values) # Loop through and Calculate ...


7

You are observing a difference between what arcpy and arcpy.da cursors return: arcpy cursors: The Row object represents the row of a table. The Row object is returned from InsertCursor, SearchCursor, and UpdateCursor. and a Row object has a getValue method. arcpy.da cursors: Returns an iterator of lists. The order of values in the list ...


7

Here's a function I've written to do a conversion directly from any feature class (or table) to a dictionary with an arcpy.da.SearchCursor: def make_attribute_dict(fc, key_field, attr_list=['*']): ''' Create a dictionary of feature class/table attributes. Default of ['*'] for attr_list (instead of actual attribute names) will create a ...


7

acres "\Legal Acreage\" true true false 50 Double You've escaped the L here rather than the double quote.


7

For comparison of 'equals' you need to use a double equals sign '==' if row[0] == 4401: row[1] = "Aire" cursor.updateRow(row) A single equals sign is the assignment operator in python.


7

You'll need to get a 64 bit ArcGIS installation of some sort to get arcpy to work correctly in a 64 bit installation. The most expedient thing would be to install 64 bit background geoprocessing for your current install of ArcGIS. That will install a 64 bit version of all the necessary Python libraries needed to use arcpy.


7

The Dissolve tool can create a Godzilla by combining smaller (but still fairly large) features into one feature. This is known as the combinatorial problem. The Dissolve tool has logic that prevents it from creating a Godzilla (you’ll receive the warning code 000059) but this logic is based on the machine’s available memory at the time Dissolve is run. So, ...


7

I see in your script you are using arcpy, in which case you you can use the out-of-the-box Table to Table (Conversion). This tool also allows you the freedom to select which fields to include as FieldMappings as well as directly outputting a .csv file. import arcpy fc = r'C:\path\to\your\fc' outws = r'C:\temp' arcpy.TableToTable_conversion (fc, outws, ...



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