Tag Info

Hot answers tagged

15

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


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

Summary This answer places the question into a larger context, describes an efficient algorithm applicable to the shapefile representation of features (as "vectors" or "linestrings" of points), shows some examples of its application, and gives working code for using or porting into a GIS environment. Background This is an example of a morphological ...


10

Use arcpy.Describe. fieldcount = len(arcpy.Describe(featureClass).fields)


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

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


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

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


9

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.


8

Use os.walk and then loop through the files appending to a list, where the filename starts with 'point' and ends with '.shp'. import os path = "D:/Files/GIS/Datafiles/" shp_list = [] for dirpath, dirnames, files in os.walk(path): for f in files: if f.lower().endswith(".shp") and f.lower().startswith("point"): print f ...


8

Remember that all of ArcGIS' Python stuff dealing with strings starting in 9.3 uses Unicode objects, which will make your life quite a bit easier because encoding becomes less of a big deal in the data. You'll still need to think about it in your scripts, but if you use UTF-8 in any Python source you write outside of dialogs in Arc*.exe ArcGIS will handle it ...


8

Threading doesn't work with most UI manipulation in Windows as UI elements have thread affinity, which is probably why the map view is failing to refresh. I've got a Python project that does this in ArcGIS without threading on Github. It uses the Win32 event loop in the main thread to do timed calls in an add-in extension. You can also use it independently ...


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

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


7

I know this question is a few months old, but I'm posting this in case it helps others. I developed this kludge to parse version numbers from MXD documents. It basically reads the first 4000 or so characters of an MXD document and searches for a version number. I tested with MXD versions 9.2, 9.3, 10.0, and 10.1. import re def getMXDVersion(mxdFile): ...


7

Use GetCount. shapefiles = [r"c:\data.shp", r"c:\data2.shp", r"c:\data3.shp"] for file in shapefiles: if arcpy.management.GetCount(file)[0] == "0": print file


7

Ok, I've figured it out. Thanks Luke for pointing out that file was already the file name. My other mistake was the brackets around the mxd version number. The final code is as follows. import arcpy, os #workspace to search for MXDs Workspace = r"C:\Testing\ImageMapperReplacement\LRM157" arcpy.env.workspace = Workspace #list map documents in folder ...


7

This sort of question is better answered in StackOverflow but the answer is straight-forward enough so I'll give you a hint here. Your date is not a date as far as Python is concerned but a division sum - which is the main reason why it doesn't work. Your code also won't give you the last four digits. You need '[-4:]' (yours gives everything except the ...


7

You can get the coordinates a mouse click via the onMouseDownMap() function of the Tool Class for Python add-ins. The x and y values for onMouseDownMap and onMouseUpMap represent the map coordinates where the button was pressed or released. Since you are already creating scripts in Python, it's not much more learning to implement this is an add-in. ...


7

I think the short answer is NO. In arcpy you would typically "Describe" an object to get a handle on its properties. It appears there is no way within arcpy to find out the version the toolbox was saved in. If anyone knows of a way then please shoot me down in flames so I can learn from your wisdom! But you could fudge it this way: In ArcCatalog right ...


7

Using a combination of string manipulation and renaming the feature classes using arcpy.Rename_management works, sort of. There's an odd problem with doing this directly. Since your output and input names are technically the same in ArcMap's opinion (this is apparently one of its operations that's case insensitive), it will complain if you just convert them ...


7

History logs are stored in C:\Users\<user name>\AppData\(Local or LocalLow or Roaming)\ESRI\Desktop10.1\ArcToolbox\History but to save log history, you have to activate it, using this code : arcpy.SetLogHistory(True) EDIT: For Arcgis 10.0 ArcPy do not support SetLogHistory(), so you have to activate it manually like described in this link


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



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