|
POST
|
I'm just guessing here, but try running the Clear Workspace Cache Data Management tool before you delete the version. ArcGIS Help 10.2 - Clear Workspace Cache (Data Management)
... View more
02-19-2015
12:27 PM
|
1
|
1
|
3084
|
|
POST
|
I'm on ArcGIS 10.2.2 and trying to use arcpy.da.Editor and an InserCursor on a versioned feature class. The feature class was registered without the option to move edits to base and resides in a 10.0 SDE on Oracle 11g (will be 10.2.2 SDE soon). I found this helpful post by Leslie Morgan that really details my same situation, but there are no code samples. I would like to know if any of you have used the Python Editor in a similar setup and what your code looks like. More specifically, can the Editor class be used in a with statement like the Esri help article says or do I still have to start and stop the operation and edit session like users say?
... View more
02-17-2015
04:32 PM
|
0
|
8
|
30265
|
|
POST
|
Just for funzies, if you are using a simple counter like you do at the end with ctr, you can also use += 1 to make the code a little simpler. Just know that += might not always be what you want. ctr += 1
... View more
02-17-2015
10:39 AM
|
0
|
0
|
9754
|
|
POST
|
I'll just leave this here while someone in the community works on posting an answer to your question Posting Code blocks in the new GeoNet
... View more
02-13-2015
11:59 AM
|
0
|
1
|
1994
|
|
POST
|
I haven't made an add-in yet, but it seems like you're trying to make your easy button too easy! Just train your users how to add the required tools to the toolbar. At some point you reach diminishing returns trying to code for so many exceptions. Just an observation, I could be way off.
... View more
02-13-2015
11:55 AM
|
0
|
0
|
588
|
|
POST
|
Cool trick about using the global list. I didn't know you could do that in a field calc!
... View more
02-12-2015
03:42 PM
|
0
|
1
|
9890
|
|
POST
|
I have a similar situation. I just tested using truncate and append on a file geodatabase with locks. If it was just a geodatabase lock (like some had it open in ArcCatalog) the truncate/append worked. However, if someone had the feature class being truncated open in ArcCatalog preview, the truncate worked but the append failed with ERROR 000224: Cannot insert features Failed to execute (Append). I tested this on 10.2.2 using Pyhon. EDIT: If the feature class is opened in ArcCatalog with geometry preview, truncate/append works. If it's open with table preview, truncate works but append fails. Same thing happens with ArcMap; if the feature class is open in data view it will truncate/append but if the attribute table is also open it will truncate but fail to append.
... View more
02-12-2015
10:43 AM
|
0
|
0
|
1048
|
|
POST
|
Does this thread have the answer you're looking for? ModelBuilder - Creating a Variable Picklist
... View more
02-12-2015
09:28 AM
|
0
|
0
|
1818
|
|
POST
|
Ah, yes, I follow now. However, I think you have to put an extra comma after the variable inside the parenthesis to make it a true tuple. fld_name = "Particle"
print fld_name
print (fld_name)
print (fld_name,) produces: Particle
Particle
('Particle',)
... View more
02-11-2015
03:38 PM
|
0
|
0
|
955
|
|
POST
|
But the Esri documentation for the Update cursor says: For a single field, you can use a string instead of a list of strings. I'm not trying to be a nit-pick know-it-all, I'm just trying to understand.
... View more
02-11-2015
03:04 PM
|
0
|
1
|
955
|
|
POST
|
In the line where you open the update cursor, why do you have extra parenthesis around fld_name? with arcpy.da.UpdateCursor(fc, (fld_name)) as curs:
... View more
02-11-2015
02:42 PM
|
0
|
5
|
955
|
|
POST
|
Great point Richard. I did a little research and I found the reserved keywords in Python 2.7 Although TABLE is not a Python reserved keyword, it is in SQL and so it should be avoided.
... View more
02-11-2015
02:17 PM
|
0
|
0
|
1230
|
|
POST
|
The PEP8 Style Guide is a great place to start. Now that you a familiar with the syntax, the style guides will make more sense. From the start, the style guides recommend putting each module you import on its own line. So instead of this import time, sys, platform, imp, arcpy Do this import arcpy
import imp
import platform
import sys
import time Inline comments are helpful but can be overdone, so be careful. They should also be separated from the code line by at least two spaces (you only have one). Consider the maximum line length. Super long lines of code are very hard (for a human) to interpret and arcpy functions are notorious for turning into monsters. Try declaring more of your function arguments as variables and take advantage of the multi-line capabilities within the parenthesis. Instead of this arcpy.SelectLayerByAttribute_management(outLayer, "NEW_SELECTION", ' "DCA1" = 80003 OR "DCA2" = 80003 OR "DCA3" = 80003 OR "DCA1" = 11006 OR "DCA2" = 11006 OR "DCA3" = 11006 ') Do this where_clause = ' "DCA1" = 80003 OR "DCA2" = 80003 OR "DCA3" = 80003 OR "DCA1" = 11006 OR "DCA2" = 11006 OR "DCA3" = 11006 '
arcpy.SelectLayerByAttribute_management(
outLayer,
"NEW_SELECTION",
where_clause
) Or you can take advantage of multiline strings and do something like this for the where clause. I used triple double quotes (""") but those are typically used for docstrings so I try to use triple single quotes ('''). However, the GeoNet forums do funny things with triple single quotes in Python syntax highlighting so I had to write this with triple double quotes. where_clause = """
"DCA1" = 80003
OR "DCA2" = 80003
OR "DCA3" = 80003
OR "DCA1" = 11006
OR "DCA2" = 11006
OR "DCA3" = 11006
""" But I would go even further and actually improve the SQL for the where clause and do this where_clause = """
"DCA1" IN(8003,11006)
OR "DCA2" IN(8003,11006)
OR "DCA3" IN(8003,11006)
""" It may also help to declare some smaller local variables at the beginning of the code block it will be used in rather than everything at the beginning. Or you can use comments to group the variables by use, like "connections", "tables", "feature classes", etc. When opening files to read and write (like you've done at the end with the log file), it's better practice to use a with statement so the file is always closed, even if there was an error. If your current code errored after you opened the file and before you closed it, the file would not get closed. Finally, a lot of Python IDEs style two types of comments differently: # and ## I like to use the single hash comment (#) for the heading of a large block of code and the double hash (##) for headings under the main heading or for inline comments. I also try to put one line between the main blocks of code and no lines between code that is all together so you can visually group the major blocks of logic. If a block of code is too long to easily fit this style, then it might be better off written as a function and called from your main(). I'm still learning Python myself and started just like you, Matthew. Please correct me if my assumptions are wrong!
... View more
02-11-2015
12:39 PM
|
3
|
2
|
1339
|
|
POST
|
Sorry for all the trouble but I'm glad you got something to work!
... View more
02-10-2015
02:04 PM
|
0
|
1
|
1027
|
|
POST
|
I should have clarified that you only need the arcpy.ClearWorkspaceCache_management() at the end if you're making an SDE connection. so if you're in a personal or file geodatabase you can get rid of that line.
... View more
02-10-2015
01:55 PM
|
1
|
0
|
1530
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | a month ago | |
| 1 | 07-31-2025 11:59 AM | |
| 1 | 07-31-2025 09:12 AM | |
| 2 | 06-18-2025 03:00 PM | |
| 1 | 06-18-2025 02:50 PM |