|
POST
|
Thanks anyway Dan, but I am familiar with the error number--it's in my original question. I am also aware that using "None" (without the quotes) still works. Again, that is in my original question. I am not clear on your point regarding "math.nan". I would like to understand why this warning message has been added, or what is happening under the hood. What am I even being warned of here? Seems to me, Python's None data type has been the universal "<Null>-setter" for quite some time: numeric fields, text, fields, date fields, etc.
... View more
11-17-2022
07:46 AM
|
4
|
0
|
6152
|
|
POST
|
Experienced this in ArcGIS Pro 3.0.2. Couldn't replicate in 2.9. I was recently setting some values to NULL using Field Calculator. Expression type is Python 3, value I am inputting is None. To be clear, I'm typing in None without quotes or anything extra. Just the Python data type None. This used to set all values in the field to Esri's NULL, represented as <Null>. Standard stuff. However now this operation yields the following: [WARNING 003571: Certain rows set to NULL due to error while evaluating python expression: Cannot be evaluated to value.] To be clear, the operation still works--highlighted rows in the specified field (tested with SHORT and TEXT fields) still evaluate to NULL. I'm just curious what the function of this warning is. Is there now a preferred way of setting values to NULL? If this Python expression results in an evaluation "error," as stated in the warning message, why does it still work? Is there something that has changed here that I should be aware of? Am I missing something? Thanks in advance if anyone has any insight into this bizarre change.
... View more
11-16-2022
04:55 PM
|
4
|
9
|
6215
|
|
POST
|
Ah, I see, that makes sense. Thanks again for sharing your experience with them, very helpful.
... View more
11-02-2022
08:56 AM
|
0
|
0
|
1495
|
|
POST
|
Thanks for adding to the discussion. Seems to me that if I "Click to add a new row." at the bottom of an attribute table with subtypes defined, and then press "Enter" to confirm that new row (even without creating geometry or entering any attributes), the subtype of the feature will be whatever the default is. I guess this is potentially useful if most of my new features are of a particular subtype. Maybe it's as simple as that. It's just weird to me how the creation of the default is implemented. And then you can't remove it. I have not used ArcMap/ArcCatalog for several years, but it sounds like maybe the implementation had greater utility in that software?
... View more
11-02-2022
08:12 AM
|
0
|
0
|
1502
|
|
POST
|
The behavior of setting default subtypes for a geodatabase feature class appears inconsistent. When adding codes manually in the subtypes table, it appears that the first code added automatically becomes the default, which can then be changed as new codes are added. Initial subtype automatically becomes the default. Default can be changed, but not removed. However, when using the geoprocessing tools "Set Subtype Field" followed by "Add Subtype" to do the same thing, a default subtype is not automatically applied. The outcome of using the toolbox interface or ArcPy seems the same. No default subtype automatically applied. Then, once a default subtype is chosen, either using the "Manage Subtypes" window OR the "Set Default Subtype" tool (the GUI or ArcPy), it can't be removed without completely clearing the subtype and starting over (unless there is a "Remove Default" that I cannot find). My question is, "why?" If a feature class can seemingly exist without a default subtype defined, why can't an existing default be removed? Why does the "Manage Subtypes" window automatically assign one, while the geoprocessing tool does not? What is the expected behavior here, and perhaps also, what is best practice?
... View more
11-01-2022
08:53 AM
|
0
|
4
|
1544
|
|
POST
|
Agreed, Field Maps was mostly great, but the offline areas were ALWAYS touch and go when I had field teams using them in poor service areas, which made using them a real pain. I haven’t supported field teams in a little while, it’s a shame to hear the application still isn’t completely reliable. edit: At the bottom of this page, there are still tons of links to folks experiencing issues creating offline areas, so looks like Esri still has some work to do.
... View more
09-21-2022
05:58 AM
|
1
|
0
|
1301
|
|
POST
|
Never did unfortunately, just had to manage any data that was collected “offline” differently than the live stuff.
... View more
09-20-2022
07:20 AM
|
1
|
2
|
1308
|
|
POST
|
Thanks, it does, however this is a pretty clunky solution, and one that is not required in VS Code. My response to @Luke_Pinner below has a bunch of screenshots from the simple "import arcpy" working in VS Code. This feels like a problem specific to PyCharm for whatever reason. Would love to hear if you have other ideas.
... View more
05-11-2022
05:24 PM
|
0
|
1
|
2300
|
|
POST
|
Interesting, thanks for the reply. I might be misunderstanding you, but this is not my experience (at least in VS Code). Using VS Code, I have never imported arcpy.management, arcpy.analysis, arcpy.cartography, etc. in my tools. I have also never seen reference to this import syntax in Esri documentation. This and the anecdotal evidence below make me skeptical that I need to "import arcpy.management". In VS Code, intellisense from base arcpy import: also getting intellisense for management functions with this import style: This is also not how other modules work, at least for me in VS Code. I don't import numpy.random for intellisense regarding "randint". or in PyCharm. Would love to hear other ideas, if you have them. This feels like a PyCharm problem/setting, or something to do with the way ArcPy is written and interpreted by PyCharm, not an import style problem.
... View more
05-11-2022
05:19 PM
|
1
|
0
|
2301
|
|
POST
|
I cannot get intellisense to work with ArcPy's newer syntax style in Pycharm 2021.3.2 (Community Edition). What's odd is that the older-style syntax DOES work: arcpy.CreateFileGDB_management() However, this does not: arcpy.management.CreateFileGDB() To be clear, the code runs fine with the newer style. My interpreter is configured to point to ArcGIS Pro's Anaconda distribution (Python 3.7). My assumption here is that PyCharm is somehow reading from the ArcGIS Desktop (Python 2.7) documentation, which is also installed on my system, but I can't find any references to that interpreter within PyCharm. Any help would be greatly appreciated!
... View more
05-11-2022
02:08 PM
|
0
|
5
|
2350
|
|
POST
|
This appears to be it! I had checked this, but only out to about 6 decimal places, so I was not handling float precision appropriately. I changed the sorting function to round both the X and the Y values, to avoid any issues with tiny differences in position: all_sheet_polys.sort(key=lambda poly: (dir1 * round(getattr(poly.centroid, axis1), 2),
dir2 * round(getattr(poly.centroid, axis2), 2))) Here are the "actual" coordinate values of the bottom row (X-values truncated for display), shown in the following image. When those values are sorted (using raw SN-WE coordinate values), the ordering was somewhat ambiguous along a given row because of your point about precision. 1 X 11,768,434 Y 7,022,867.011901856400
2 X 11,767,927 Y 7,022,867.011901855469
3 X 11,767,421 Y 7,022,867.011901854537
4 X 11,766,914 Y 7,022,867.011901856400
5 X 11,766,407 Y 7,022,867.011901855469
6 X 11,765,901 Y 7,022,867.011901854537
7 X 11,765,394 Y 7,022,867.011901856400
8 X 11,764,887 Y 7,022,867.011901855469
9 X 11,764,381 Y 7,022,867.011901854537
10 X 11,763,874 Y 7,022,867.011901856400
11 X 11,763,367 Y 7,022,867.011901855469 After the rounding, problem solved (example of bottom row): Thanks a ton, I appreciate the assistance.
... View more
01-08-2022
12:29 PM
|
2
|
0
|
1546
|
|
POST
|
I am attempting to use Python's .sort() with a lambda function to spatially sort an existing list of Polygon objects, to then write to a feature class with an InsertCursor. Sorting will be based on user-supplied specifications (north to south first, followed by east to west as a secondary sort, for example). This snippet is part of a larger script that has been pared down so it's easier to look at (the list of polygons and the output feature class are created at an earlier stage, not shown here). # User supplied sort priorities.
sort_1 = 'EW'
sort_2 = 'SN'
# Example: for N to S sorting, sort polygon using centroid.Y attribute, descending.
sort_dict = {"NS": (-1, 'Y'),
"SN": ( 1, 'Y'),
"WE": ( 1, 'X'),
"EW": (-1, 'X'),}
# Getting the direction and axes (primary and secondary) to sort by.
dir1, axis1 = sort_dict[sort_1]
dir2, axis2 = sort_dict[sort_2]
# An existing list of polygon objects, sorted using specifications above.
# "dir" handles ASC/DSC, getattr() gets the appropriate x or y value from the
# centroid.
all_sheet_polys.sort(key=lambda poly: (dir1 * getattr(poly.centroid, axis1),
dir2 * getattr(poly.centroid, axis2)))
# Write sorted polygons to an existing blank feature class.
with ap.da.InsertCursor(out_fc, ['SHAPE@', 'PageNumber']) as icurs:
sheet_count = 1
for sheet in all_sheet_polys:
icurs.insertRow([sheet, sheet_count])
sheet_count += 1 The problem is that the two-part lambda sort does not always work. If the FIRST sorting is along the x-axis (EW/WE), it will. The first image is east to west, then south to north. The second is west to east, then north to south. Both are created as expected. East to West, then South to North. West to East, then North to South. The problem occurs when x-axis sorting is done as a SECONDARY priority. Here is an example using inputs "SN" and "WE" as inputs, for south to north followed by west to east. The primary sort, south to north, works fine. However, the west to east does not, and the ordering appears arbitrary. South to North, failed sorting West to East. Any ideas would be appreciated. Seems like something silly I am overlooking, but it has got me stumped.
... View more
01-05-2022
09:40 AM
|
0
|
2
|
1634
|
|
POST
|
To follow up with this, I have had luck simultaneously using an UpdateCursor and an InsertCursor on the same feature class. I had a field with a list of values in it, and I needed to explode that list out so each item was in a single row with it's own point. This meant updating the current row to include only the first value in the list, and then creating new rows in the same feature class for each subsequent value in the list. Using the Editor class enabled me to do this. I don't know exactly what makes this necessary, but I was not able to do it without the Editor. with ap.da.Editor(outgdb):
with UpdateCursor(infc, '*') as ucurs, InsertCursor(infc, '*') as icurs:
... View more
11-04-2021
12:36 PM
|
0
|
0
|
546
|
|
POST
|
This is great, thanks for sharing this. For the fun of it, I rewrote to avoid using the nested cursors. I think a lot of this is a matter of style/opinion, but this separates the reading and editing from the writing, and also only sorts using the lambda function, rather than once with the SQL query and once with the lambda. It's basically the same as yours, it just creates a dictionary of updated values with the OID as the key, which enables writing in the correct order. This only uses two cursors (I believe you are recreating an UpdateCursor with every SearchCursor loop--I don't know how expensive that is). However, this version does have to create the intermediate dictionary. While I still think using the SQL query could be cleaner/easier to read, I assume it is slower because it forces the user to add and calculate a separate coordinate field (unless they have a spatially enabled geodatabase). Because the spirit of the question was specifically about using the SQL query, I am going to leave that as marked correct for posterity, but thanks all the input! from string import ascii_uppercase
from arcpy.da import SearchCursor, UpdateCursor
fc = r'PATH'
# Ensure OID and SHAPE are index 0 and 1.
fld = [f.name for f in ap.ListFields(fc) if f.type not in ['Geometry', 'OID']]
all_fld = [ap.da.Describe(fc)['OIDFieldName'], 'SHAPE@'] + fld
# ['OBJECTID', 'SHAPE@', 'LBL', 'XCOOR', 'YCOOR', 'GRP']
# Indices of fields, used to call specific values in cursor rows.
grp_idx = all_fld.index('GRP')
lbl_idx = all_fld.index('LBL')
# SQL WHERE:
where = f"""GRP IS NOT NULL AND TRIM(BOTH ' ' FROM GRP) <> ''"""
# Use Python sorted w/ lambda funct; update the given row; store in dict w/ OID key.
# Sort by GROUP, then DESC x-coor.
row_dict = {}
with SearchCursor(fc, all_fld, where) as scurs:
scurs_sort = sorted(scurs, key=lambda x: (x[grp_idx], -x[1].centroid.X))
for row in scurs_sort:
row = list(row) # Can't update SCurs tuple, unlike UCurs list
current_group = row[grp_idx]
try:
if current_group != previous_group:
letter_index = 0
except NameError:
letter_index = 0
row[lbl_idx] = ascii_uppercase[letter_index]
row_dict[row[0]] = row[1:]
letter_index += 1
previous_group = current_group
# Write the new row back to the same FC, using the OID as key again.
with UpdateCursor(fc, all_fld, where) as ucurs:
for oid, *_ in ucurs:
new_data = row_dict[oid]
ucurs.updateRow([oid, *new_data])
... View more
11-04-2021
12:29 PM
|
0
|
0
|
548
|
|
POST
|
Thanks for the input! This is close to the approach I would have used had I not gotten my SQL syntax sorted out, but @JoshuaBixby's comments would be issues with the Cursor. I think I would have had to use a SearchCursor, use sorted() with a lambda function (as you have done), and then use a separate UpdateCursor InsertCursor to write the sorted rows to a blank feature class with the same schema. Probably workable, but involves iterating over the same data more times (three total?) than necessary.
... View more
11-04-2021
07:40 AM
|
0
|
7
|
3294
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-09-2024 08:46 AM | |
| 1 | 07-07-2020 01:01 PM | |
| 1 | 10-09-2024 07:22 AM | |
| 1 | 07-17-2024 02:57 PM | |
| 1 | 10-24-2024 07:51 AM |
| Online Status |
Offline
|
| Date Last Visited |
09-30-2025
05:37 AM
|