Tag Info

Hot answers tagged

19

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

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


12

Do a set difference: s.difference(t) s - t new set with elements in s but not in t Ex: l1 = ['apple','banana', 'celentro', 'donut', 'elephant', 'film', 'gopher','hyena',1,2,3,4,5] l2 = ['film', 'celentro', 'badger', 'tiger', 100, 2, 4, 16] >>> set(l1).difference(set(l2)) set([1, 3, 'apple', 'gopher', 'hyena', 'donut', 'elephant', 'banana', ...


11

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


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

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


9

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'


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

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


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

Use collections.Counter: import collections with arcpy.da.SearchCursor(feature_class, field) as cur: count_of_items = collections.Counter(row[0] for row in cur) print "Sorted items" print "----" for item in sorted(count_of_items.items(), key=lambda x:x[1]): print "{0:>12} {1:>4}".format(item[0], item[1])


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

If you have the XY of the point, then you could create a PointGeometry. current_sr = arcpy.SpatialReference(102726) #Enter the current WKID for the point new_sr = arcpy.SpatialReference(4326) #This is the WKID for WGS84 point = arcpy.PointGeometry(arcpy.Point(7334719, 670307), current_sr) new_point = point.projectAs(new_sr) >>> ...


8

If you have Arc 10.1 or above, I'd use an arcpy.da cursor. Also specify just the field(s) you want. myLayer = 'YourLayer' myField = 'YourField' myList = [row[0] for row in arcpy.da.SearchCursor(myLayer, myField)]


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

64-bit Background Geoprocessing with ArcGIS 64-bit Background Geoprocessing installs a 64-bit version of Python 2.7.2, NumPy and Matplotlib if they are not already installed. By default they will be installed to C:\Python27\ArcGISx6410.1 (note the x64 in the path), an additional install from the 32-bit Python (C:\Python27\ArcGIS10.1) that Desktop ...


7

Cursors are the way to go for this type of problem. First, create a list of values using a Search Cursor and a generator expression: b = sum(row[0] for row in arcpy.da.SearchCursor(fc, 'QUANTITY_SOLID')) Then run an Update Cursor to populate the QUANTITY_SOLID_SUM field: with arcpy.da.UpdateCursor(fc, ['QUANTITY_SOLID_SUM']) as cursor: for row ...


7

You can use a simple block of code either directly from Python window in ArcGIS or as a Python script or as a custom script tool. Below is a sample code for a script tool. Just add your vector layers into a map document (.mxd) and specify the clip layer and the output geodatabase. import os, arcpy arcpy.env.overwriteOutput = True clip_layer = ...


7

Ok, let me start this with I am no python expert, so there are probably much more efficient ways to accomplish this, but... the first thought that comes to me would be maybe something along the lines of the following (pseudo code below) while success != True: funcCopyData() def funcCopyData(): try ... ... global var success = True except ...


7

You should be able to use either the Copy Rows tool or the Table to Table tool to get the job done. Just make sure to give your out_table/out_name parameter ends with '.csv' and you should have no trouble. EDIT: Due to another inexplicable Esri oversight, these tools do in fact force you to save as DBF if you're saving outside of a geodatabase. I maintain ...


7

I don't think the original poster was asking about how to use arcpy.da.SearchCursor(), but rather that the arcpy.da.SearchCursor() class was not appearing in the code completion window within Eclipse (sometimes called intellisense or intelligent code completion). I've been using Eclipse+PyDev and/or LiClipse for editing code for geoprocessing tools since ...


7

EDIT: I've revamped this answer after realizing that Linear Referencing supports determining the side along a line. The best approach to this problem is to use the Linear Referencing toolbox in ArcGIS: A linear reference system stores data using a relative position along existing line features. That is, location is given in terms of a known linear ...


7

The Describe object also has the hasM and hasZ properties.


7

Try lyr.longName longName (Read Only) This property is valuable when trying to determine whether a layer belongs to a group layer. If a layer does not belong to a group layer, the long name will equal the layer name. If a layer does belong to a group layer, the group layer structure will be included in the long name. For example, the name of a ...



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