|
POST
|
Both techniques will/do work, but in my experience the performance is not identical between the two. For small to medium datasets (~100,000 records or less), the performance can be quite similar with the arcpy.da.SearchCursor and arcpy.GetCount_management. For larger datasets, I have seen GetCount outperform cursors by 3 to 10 times. Jason Scheirer speaks to why using a GP tool is faster than a Python cursor with larger datasets: Re: How to determine number of records using arcpy.da.SearchCursor.
... View more
06-30-2015
07:16 PM
|
0
|
0
|
2512
|
|
POST
|
If you plan on continuing with any programming/scripting, I strongly encourage you to learn more about regular expressions. They are an extremely powerful form of pattern matching, and regular expressions are either built-in or available through libraries in many programming languages, including Python. : ) Regarding the specific code snippet I gave, let's look at the Python syntax first: re.sub(pattern, repl, string, count=0, flags=0). We are not using count or flags, so we need three things: 1) a regular expression pattern, 2) a replacement string, and 3) a string to apply the regular expression. Looking next at the regular expression: [^A-Za-z0-9]+. A bracket expression, [ ], matches a single character that is within the brackets, sort of an implicit or operator. A bracket expression that starts with a caret, [^ ], matches a single character that is not within the brackets. Bracket expressions allow for ranges, e.g., A-Z means any uppercase character from A through Z. The plus sign, +, matches the preceding occurrence/element one or more times. So, the bracket expression I provided, [^A-Za-z0-9], matches any character that isn't A through Z, a through z, or 0 through 9. The plus sign is used to match one or more occurrences. Finally, the matched characters are replaced with an empty string to remove them from the original string. The regular expression I provided is rather simplistic in that valid non-alphanumeric characters will also be removed, e.g., hyphens and underscores. If one knew his/her code was only going to be run on Windows, an assumption I wouldn't make myself, a regular expression could be make to only remove Windows file system reserved characters. As Grant Herbert pointed out, you could also use ArcPy's ValidateTableName method. Using that approach, though, the invalid characters are replaced with an underscore and there is no way to change the replacement character.
... View more
06-27-2015
07:38 AM
|
2
|
4
|
6587
|
|
POST
|
Since you didn't give a specific example, I am guessing you are running into layer names that contain Windows file system reserve characters, e.g., a colon, double quote, etc.... Feature Class to Feature Class fails because the underlying call to create the new feature class fails at the OS level. If you are willing to limit output names to only alphanumeric ASCII characters, you could also try the sub method in the regular expression module. re.sub('[^A-Za-z0-9]+', '', lyr.name)
... View more
06-24-2015
03:14 PM
|
2
|
8
|
6587
|
|
POST
|
A quick tour of SQL functions used with ST_Geometry has been reformatted at 10.3.x. Although the content is much the same as earlier versions, the improved presentation is helpful in understanding some of the information. Regarding AddGeometryColumn, CreateSpatialIndex, DropGeometryMetadata, etc..., Esri doesn't document those SQL functions because they are not part of the ST_Geometry data type. Since Esri didn't create/develop those functions and they aren't part of the ST_Geometry data type, they assume users will use the relevant DBMS documentation to read up on how those functions work.
... View more
06-24-2015
02:44 PM
|
0
|
3
|
2982
|
|
POST
|
The FIDSet property doesn't return a Python list, it returns a Python string that represents a list of FIDs. Since the property is string-based, there is nothing else besides an empty string (u'')that can be returned when no records are selected. It is the behavior of the Python string splitting function that is returning a list with an empty string instead of an empty list, but that is a Python issue and not an ArcPy issue. If arcpy.Describe('your_dataset').fidset is returning a list, trying to split it will fail either by an AttributeError or TypeError depending on your syntax.
... View more
06-18-2015
01:07 PM
|
0
|
0
|
3263
|
|
POST
|
What you are running into is a Python issue/idiosyncrasy, not really an ArcPy issue. An empty string doesn't say you have a match of '1', an empty string is saying there are no matched because the fidset is empty. The reason your length check is returning 1 is due to how the Python string splitting method works, specifically related to separators. 5.6.1. String Methods .... str.split([sep[, maxsplit]]) .... If sep is given, consecutive delimiters are not grouped together and are deemed to delimit empty strings (for example, '1,,2'.split(',') returns ['1', '', '2']). The sep argument may consist of multiple characters (for example, '1<>2<>3'.split('<>') returns ['1', '2', '3']). Splitting an empty string with a specified separator returns ['']. If sep is not specified or is None, a different splitting algorithm is applied: runs of consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace. Consequently, splitting an empty string or a string consisting of just whitespace with a None separator returns []. Looking at a few examples: >>> fidset_empty = ''
>>> fidset_empty.split(';')
['']
>>> fidset_one = '1'
>>> fidset_one.split(';')
['1']
>>> fidset_two = '1; 2'
>>> fidset_two.split(';')
['1', ' 2'] The length of lines 03 and 06 are both 1 because a separator was explicitly passed to the split method so an empty string returned a list with an empty string. If you can live with the extra semicolon being attached to all but the last FID, then passing no separator to split will yield an empty list with a length of zero. >>> fidset_empty.split()
[]
>>> len(fidset_empty.split())
0 With your workaround code, you are using a variable 'lst'. Although 'lst' could be anything, most people reading your code would assume it is a list, but it is actually a string because fidset returns a string and not a list.
... View more
06-09-2015
03:19 PM
|
0
|
1
|
3263
|
|
POST
|
Providing a bit more information would be helpful. What edition of SDE? Personal, Workgroup, Enterprise? What backend DBMS and what version? How much RAM and what is your disk arrangement like? Points? Polygons? How many fields besides the spatial column? There are so many factors that may be impacting your results, that the best we can offer is speculation without more information.
... View more
06-09-2015
10:57 AM
|
0
|
1
|
1558
|
|
POST
|
I think you want Get Count. Get Count is designed to work on views, layers, and similar such. Describe is more focused on data sources. The reason you are seeing 1 in your first example is because the Python string split method is returning your empty string back to you in a list. A list with a single empty string in it has a length of 1. You are not handling the no selected features situation correctly. Before you run split, check to see if fidset returns an empty string, which indicates no selected features. If you are only interested in counts and not FIDs of selected features, I think Get Count works well.
... View more
06-09-2015
10:21 AM
|
0
|
2
|
3263
|
|
POST
|
Esri Support: BUG-000088086: Interactive Python Window doesn't display usage and tool-specific help in help window for all classes/functions Now the real fun begins trying to get it fixed.
... View more
06-04-2015
10:49 AM
|
1
|
0
|
977
|
|
POST
|
Owen Earley, thanks for the heads up. waqar ahmad, please share posts among different places instead of creating duplicating ones.
... View more
05-31-2015
05:38 PM
|
0
|
1
|
1038
|
|
POST
|
Can you upload any sample data that replicates the problem? Since your code isn't failing, i.e., it isn't generating an error message, it is hard to troubleshoot from the code itself.
... View more
05-31-2015
02:52 PM
|
0
|
0
|
1038
|
|
POST
|
The accepted answer on StackExchange works for ArcGIS Desktop, which is what the OP was asking about, but the accepted answer won't work for ArcGIS Pro. The arcpy.mapping Layer function was removed in ArcGIS Pro, it has been replaced with LayerFile. If one looks at the Summary for Layer: Summary Provides access to layer properties and methods. It can either reference layers in a map document (.mxd) or layers in a layer (.lyr) file. It turns out, the accepted answer on StackExchange was never supposed to work but it does. Originally, arcpy.mapping Layer was designed to work on layers in MXDs or existing layer files, but there was a bug that allowed it to work directly against some data sources (but not all). Since the hack was fairly common place, the bug wasn't fixed, until ArcGIS Pro. To avoid confusion over changed functionality and having people submit bug reports, Layer was renamed LayerFile to emphasize how it is designed to work. I can't remember right off the top what the workflow is in Pro. I will post it later if I find it or remember.
... View more
05-31-2015
10:00 AM
|
1
|
0
|
4725
|
|
BLOG
|
I think this blog post follows up nicely to Dan Patterson's recent blog post, ...That empty feeling... The conversation about null and empty geometries in ArcGIS isn't new, but it does take some getting your head around. When it comes to creating new feature classes, I am sure most people are quite familiar with the following screen from the New Feature Class wizard: When creating a new feature class using ArcGIS Desktop, either through the GUI or ArcPy, the default settings allow for NULL values in the SHAPE field (see yellow highlight above). Regardless of whether NULLs in the SHAPE field are a good or bad idea, they are supported and allowed by default, so it is good to understand what does/can happen when geometries aren't populated with the rest of a record in feature classes. After troubleshooting several cases where NULL wasn't NULL, I decided to take a deeper look at what really happens when geometries aren't populated in feature classes. It turns out, the answer depends both on the tool and type of geodatabase being used to insert, store, and retrieve records. Presented here are the results for some of the more common tools and types of geodatabases. Table 1 shows what actually gets populated in the SHAPE field when nothing, None, an empty geometry, and a non-empty geometry are inserted into a polygon feature class using three different methods. TABLE 1: SHAPE Field Values in Feature Class Storage Type Insert Method NOTHING NONE EMPTY POLYGON PGDB ArcMap Editor Null N/A N/A Polygon PGDB arcpy.InsertCursor Null Error Empty Polygon PGDB arcpy.da.InsertCursor Null Null Null Polygon FGDB ArcMap Editor Empty N/A N/A Polygon FGDB arcpy.InsertCursor Null Error Empty Polygon FGDB arcpy.da.InsertCursor Null Null Null Polygon SDE(SQL) ArcMap Editor Empty N/A N/A Polygon SDE(SQL) arcpy.InsertCursor Null Error Empty Polygon SDE(SQL) arcpy.da.InsertCursor Null Null Null Polygon SDE(ORA) ArcMap Editor Empty N/A N/A Polygon SDE(ORA) arcpy.InsertCursor Null Error Empty Polygon SDE(ORA) arcpy.da.InsertCursor Null Null Null Polygon NOTE: Storage Type: PGDB := personal geodatabase FGDB := file geodatabase SDE(SQL) := SQL Server enterprise geodatabase SDE(ORA) := Oracle enterprise geodatabase Insert Method: ArcMap Editor := edit session in ArcMap arcpy.InsertCursor := original/older ArcPy insert cursor arcpy.da.InsertCursor := ArcPy Data Access insert cursor Insert Geometry: NOTHING := no geometry is specified. In ArcMap edit session, table is populated with no geometry In ArcPy insert cursors, SHAPE field is not specified with cursor NONE := Python None object is passed to SHAPE field EMPTY := empty polygon is passed to SHAPE field POLYGON := non-empty polygon is created or passed to SHAPE field SHAPE Value: N/A := not applicable, i.e., not possible to insert or attempt to insert type of geometry or object Error := error is generated attempting to insert type of geometry or object Null := NULL value/marker in SHAPE field Empty := empty polygon or empty collection in SHAPE field Polygon := non-empty polygon in SHAPE field Table 2 shows what gets returned by search cursors once the records from Table 1 have been inserted into a feature class. Table 2: Retrieved Geometry/Object From SHAPE Field Storage Type Retrieve Method NULL EMPTY POLYGON PGDB arcpy.SearchCursor None Empty Polygon PGDB arcpy.da.SearchCursor None None Polygon FGDB arcpy.SearchCursor None Empty Polygon FGDB arcpy.da.SearchCursor None None Polygon SDE(SQL) arcpy.SearchCursor None Empty Polygon SDE(SQL) arcpy.da.SearchCursor None None Polygon SDE(ORA) arcpy.SearchCursor None Empty Polygon SDE(ORA) arcpy.da.SearchCursor None None Polygon NOTE: Storage Type: PGDB := personal geodatabase FGDB := file geodatabase SDE(SQL) := SQL Server enterprise geodatabase SDE(ORA) := Oracle enterprise geodatabase Retrieve Method: arcpy.SearchCursor := original/older ArcPy search cursor arcpy.da.SearchCursor := ArcPy Data Access search cursor SHAPE Value: NULL := NULL value/marker in SHAPE field EMPTY := empty polygon or empty collection in SHAPE field POLYGON := non-empty polygon in SHAPE field Retrieve Geometry: None := Python None object Empty := empty polygon or empty collection Polygon := non-empty polygon It is clear there are some differences, inconsistencies one might say, with how different tools insert nothing or empty geometries into a feature class that allows NULL values. Even with the same tool, there are situations where nothing or empty geometries are handled differently between different types of geodatabases. There are also differences with how different search cursors, and likely update cursors, retrieve empty geometries from feature classes. I can't say what it all means, but there are a few items that stuck out for me. Non-empty geometries are handled consistently across tools and types of geodatabases. "Allow NULL Values" for the SHAPE field doesn't mean missing geometries will be NULL, it means missing geometries may be NULL, they could also be empty. The ArcPy Data Access search cursor returns None whether a SHAPE field is NULL or contains an empty geometry, so None doesn't necessarily mean NULL for geometries.
... View more
05-29-2015
04:34 PM
|
3
|
0
|
6582
|
|
POST
|
I agree with Blake T, the use of an asterisk in the table name seems problematic. I am not sure if it is a bug, but I have always run into issues using triple quotes for line continuation within the interactive Python Window in ArcGIS Desktop. Even in other interpreters, the newline character will be preserved in the string, which may or may not be desirable depending on your specific situation. Beyond triple quotes, strings wrapped in parentheses don't need backslashes for continuation either. If you want to use backslashes or parentheses, each line needs to be a complete string literal. For example, >>> 'This is an example of ' \
... 'line continuation using backslashes'
...
'This is an example of line continuation using backslashes'
>>> ('This is an example of '
... 'line continuation using parentheses')
...
'This is an example of line continuation using parentheses' Within the interactive Python Window in ArcGIS Desktop, but not all interactive interpreters, you will need to use Shift+Enter instead of Enter when using backslashes, likely do to the same oddity that causes issues with triple quote line continuations. Line continutation using parentheses doesn't have this issue, using just Enter works fine.
... View more
05-29-2015
02:12 PM
|
1
|
0
|
5409
|
|
POST
|
You can use Add Geometry Attribute to add the geometry attributes you want (more than just area and perimeter) to the in-memory feature classes.
... View more
05-28-2015
07:33 PM
|
1
|
0
|
1998
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | Friday | |
| 2 | 2 weeks ago | |
| 1 | 2 weeks ago | |
| 2 | 06-05-2026 10:30 AM | |
| 1 | 05-29-2026 08:22 AM |
| Online Status |
Online
|
| Date Last Visited |
Friday
|