Tag Info

Hot answers tagged

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


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'


9

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)]


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


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

Not wishing to detract from PolyGeo's excellent answer I wanted to know what other words can't be used for creating feature classes. To this end I wrote a simple script in python to try every alphanumeric combination and found some interesting results: Names cannot start with a number Dashes are not allowed At the risk of putting the 'horse before the ...


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


7

You should not bother using Describe to describe the path to the feature class first and then describing the geodatabase itself to find out whether it is personal or file one. I recommend using the AddFieldDelimiters arcpy function which will find out the data source and use proper syntax. This means that whatever the source you will use, you will always ...


7

I can crush this down to 3 lines of code, no cursors required! import arcpy arcpy.SpatialJoin_analysis("Site", "points","in_memory/points_SpatialJoin", "JOIN_ONE_TO_MANY", "KEEP_ALL", "", "INTERSECT") arcpy.Statistics_analysis("points_SpatialJoin", "in_memory/stats", "Join_Count SUM","Id") Then simply sort the table to find the polygon with most points.


7

A good starting point to understanding this is a help page entitled Understanding the progress dialog box in script tools: There are four functions you use to control the progress dialog box and its progressor. This certainly works for foreground Geoprocessing and I assume that it will have a similar effect on the Background Geoprocessing dialog.


7

Use the cursor.updateRow(field) instead of cursor.updateRow([field]). You should supply an object, not the list.


7

Use Python as the parser, and check the Advanced box. Then just replace yourFieldName with the name of the field you want to label. def FindLabel([yourFieldName]): value = [yourFieldName] first = False third = False if value[0] == "0": first = True if value[2] == "0": third = True if first == True and third == ...


6

If you really want to do it your way (which is fine in this case because it's just an exercise, but I would never recommend for any important work), it should be possible in the following manner: with arcpy.da.UpdateCursor(utable, ["column2"], """"column1" = 'aa'""") as ucursor: with arcpy.da.SearchCursor(stable, ["column2"], """"column1" = 'aa'""") as ...



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