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

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

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

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

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


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

here is an example. You need to extract the bounding box from a describe object. desc = arcpy.Describe(fc) arcpy.CreateFishnet_management(fc[:-4]+"_c200.shp",str(desc.extent.lowerLeft),str(desc.extent.XMin) + " " + str(desc.extent.YMax + 10),"200","200","0","0",str(desc.extent.upperRight),"NO_LABELS","#","POLYGON")


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


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


7

A handy hint for 'special' folders is os.environ.get Some environments that will help you on windows: AGSDESKTOPJAVA ALLUSERSPROFILE APPDATA COMPUTERNAME HOMEDRIVE HOMEPATH LOCALAPPDATA NUMBER_OF_PROCESSORS PROCESSOR_ARCHITECTURE ProgramFiles ProgramFiles(x86) PUBLIC SystemDrive SystemRoot (don't write here, but it's handy for reading) TEMP TMP USERNAME ...


6

Yes you can, you could do it by adding a global variable that keeps track of your clicks. For example: class ToolClass2(object): """Implementation for Test_addin.tool (Tool)""" def __init__(self): self.enabled = True self.shape = "NONE" global clickCount clickCount = 0 def onMouseDownMap(self, x, y, button, shift): global clickCount ...


6

Try unchecking the 'Add results of geoprocessing operations to the display' in the Geoprocessing Options in ArcMap. You can also access this option via the addOutputsToMap property of the env class: just add arcpy.env.addOutputsToMap = 0 in the beginning of your script.


6

Use the dataSource attribute for the layer. for lyr in arcpy.mapping.ListLayers(mxd): dataSource = lyr.dataSource if ".gdb" in dataSource: # your pseudocode "if database = GDB:" print "GDB {}".format(dataSource) elif ".mdb" in dataSource: print "MDB {}".format(dataSource) else: print "OTHER"


6

ArcGIS-based solution (script tools + Python add-ins) Having a Python script, you can make a custom script tool which will have the GUI any other core geoprocessing tool has. There are panels and boxes with Browse buttons, you can work with drop-down lists, check boxes, multi-value tables and many others. Read through all the parameter types you have (you ...


6

You are missing date2 in dictIN: Change it: dictIN= [{'field1':"test1",'date1':'01-02-2015','date2':''},\ {'field1':"test2",'date1':'01-02-2015','date2':'01-02-2015'},\ {'field1':"test3",'date1':'','date2':''},\ {'field1':"test4",'date1':'01-02-2015','date2':''}] Full code is: dictIN= [{'field1':"test1",'date1':'01-02-2015','date2':''},\ ...


6

Here's a one-liner for getting the count of records in a specific FC or table: count = sum((1 for row in arcpy.da.SearchCursor(r'C:\PATH\TO\FC', ['OID@'])))


6

You want to access each item in the set individually, and print it: for value in uniqueValues: arcpy.AddMessage(value)


6

The problem is that your string inputFeature_json has special characters that are not in the ascii encoding. If you have characters that are not in the english alphabet they can cause encoding errors. Try to convert the string as unicode. for example: # Script arguments inputFeatures_json = arcpy.GetParameterAsText(0) #wtite to file jsonFileName = ...



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