|
POST
|
If you are just trying to compare between two existing point datasets, you could select by location, then inverse the selection to find non-matches. Can apply search distance (buffer) to handle non-exact values. R_
... View more
07-15-2013
10:39 AM
|
0
|
0
|
2053
|
|
POST
|
Ah I didn't realize I had to do so. That's all of the code referring to the query. The rest of it begins to run the clip function along with others down the line. So I have to define the mxd that this is happening in in order to call upon the attributes of the Ground Zones feature class? Is there a way to run this just in Catalog? I tried defining the mxd as shown in the post at the top of the thread, but am still having problems. Whenever I try to set mxd to the full pathname of the map, I get an error saying Invalid MXD Filename. When just using the keyword "CURRENT" to define the mxd, it at least ran, but then I got that same 'str' object has no attribute 'name'. import arcpy
from arcpy import env
import os
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "RevisedGroundZones", df)[0]
lyr.definitionQuery = ' "Grounds_GSC_Zones" = \'2\'' Think you just need to define the layer. If it is just one layer, no need to iterate. R_
... View more
07-15-2013
10:11 AM
|
0
|
0
|
1573
|
|
POST
|
Believe that error is related to using background geoprocessing. ArcMap, Geoprocessing menu, un-check Enable on Background Processing. R_
... View more
07-15-2013
09:57 AM
|
0
|
0
|
2973
|
|
POST
|
If only I could +10 you for using join()! Well, I can only give you one for it, but done.... R_
... View more
07-11-2013
04:53 PM
|
0
|
0
|
932
|
|
POST
|
For comparison. run multiple times >>> took 5.42300009727 seconds to run using cursors took 14.9790000916 seconds to run using Export_stats took 1.01900005341 seconds to run using da.searchcursor >>> ================================ RESTART ================================ >>> took 5.4279999733 seconds to run using cursors took 15.0590000153 seconds to run using Export_stats took 1.11499977112 seconds to run using da.searchcursor >>> ================================ RESTART ================================ >>> took 6.02999997139 seconds to run using cursors took 15.8759999275 seconds to run using Export_stats took 1.08899998665 seconds to run using da.searchcursor >>> ================================ RESTART ================================ >>> took 5.89599990845 seconds to run using cursors took 15.3450000286 seconds to run using Export_stats took 1.04600000381 seconds to run using da.searchcursor >>> ================================ RESTART ================================ >>> took 6.25199985504 seconds to run using cursors took 15.6540000439 seconds to run using Export_stats took 1.0609998703 seconds to run using da.searchcursor >>> I find it interesting that using a single tool take so much longer... R_
... View more
07-11-2013
01:27 PM
|
0
|
0
|
4481
|
|
POST
|
No, the problem was with something else. Can you please look at this code and tell me why I get the following error message, but I dont't get an error when I run Stacy's original code? Traceback Info: File "D:\ArcGISData\SARS\Python_10April2013\BoundaryReporting_26March2013_changes_july2013_added_domain_changed_again.py", line 260, in <module> sequenceDict2[key] = 1 Error Info: <type 'exceptions.TypeError'>: 'unicode' object does not support item assignment
# Iterate through rows and get highest ID values
sequenceDict = {}
for row1 in cur1:
if sequenceDict[key] < row1.PlanID:
arcpy.AddMessage("TEST")
sequenceDict[key] = row1.PlanID
arcpy.AddMessage(sequenceDict)
filter = 'SequenceNumber IS NULL' #filter for Null values
cur2 = arcpy.UpdateCursor("Stewardship", filter)
# Iterate through rows and update values
sequenceDict2 = {}
sequenceDict2 = sequenceDict
arcpy.AddMessage(sequenceDict2)
for row2 in cur2:
key = str(row2.FFY) + '-' + str(row2.County) # use year/county as the key
if (key in sequenceDict2):
sequenceDict2[key] += 1
else:
sequenceDict2[key] = 1
row2.PlanID = key + '-' + str(sequenceDict2[key]).zfill(3)
cur2.updateRow(row2)
I suspect it is related to trying to compare an entire dictionary to a value, then set the entire dict to a value. Need to have key:value pair for the dict. So, sequenceDict = row1.PlanID would now overwite the setting of sequenceDict as a dictionary and now assigns it as a variable with row1.PlanID as the value. Then later, you set sequenceDict2 equal to a variable (not a dict) and try to use it as a dict ( sequenceDict2[key] = 1). R_
... View more
07-11-2013
11:05 AM
|
0
|
0
|
1452
|
|
POST
|
How do I handle this? I have my Flexview app in the coordinate system of my data. Any excel file that is in the same coordinate system will overlay properly. You could use ArcMap projection tool to re-project your stores FC to webmercator and add coordinates to it, then export the table. that would give you the "lookup table" that you mentioned. R_
... View more
07-11-2013
08:35 AM
|
0
|
0
|
1943
|
|
POST
|
I tried to combine what I had before (sorting by the highest value) with what Stacy has written. But I am getting an error at the end: Traceback Info: File "D:\ArcGISData\SARS\Python_10April2013\BoundaryReporting_26March2013_changes_july2013_added_domain_changed_again.py", line 234, in <module> row.PlanID = key + '-' + str(sequenceDict2[key]).zfill(3) Error Info: <type 'exceptions.RuntimeError'>: ERROR 999999: Error executing function. Does anybody know why? Thank you!!!
filter = 'NOT SequenceNumber IS NULL' #filter for non-Null values
cur1 = arcpy.UpdateCursor("Stewardship", filter, "", "", "SequenceNumber A")
# Iterate through rows and get highest ID values
sequenceDict = {}
for row1 in cur1:
if sequenceDict < row1.PlanID:
sequenceDict = row1.PlanID
filter = 'SequenceNumber IS NULL' #filter for Null values
cur2 = arcpy.UpdateCursor("Stewardship", filter)
# Iterate through rows and update values
sequenceDict2 = {}
sequenceDict2 = sequenceDict
for row2 in cur2:
key = str(row2.FFY) + '-' + str(row2.County) # use year/county as the key
if (key in sequenceDict2):
sequenceDict2[key] += 1
else:
sequenceDict[key] = 1
row.PlanID = key + '-' + str((sequenceDict2[key]).zfill(3))
cur2.updateRow(row2)
Does the change in red above get rid of the error? R_
... View more
07-11-2013
08:31 AM
|
0
|
0
|
1452
|
|
POST
|
Yes, would use a searchcursor to populate the lists. Somthing like this:
yearList = []
countyList = []
with da.SearchCursor(inFc,["years","counties"]) as cursor:
for row in cursor:
year= str(row[0])
county = str(row[1])
yearList.append(year)
countyList.append(county)
del cursor
Of course, this will have the same issue, as if you delete one row (if it was the highest sequence number), the next time the maxValue searchcursor is run on it, the "old" number would be the "new" maxValue again. Also, in the code I provide previously, I should not have put the maxValue SearchCursor within the loop. It is hardcoded to the FC and fields, so no need to run that process each time. would move that just above the loop. R_
... View more
07-11-2013
08:04 AM
|
0
|
0
|
1452
|
|
POST
|
Hello, import arcpy, glob, os, string
import codecs
#ListofLayers = codecs.open("C:\\Users\\34459jm\\Desktop\\DirPrnInfo.txt",encoding = 'utf-16')
ListofLayers = arcpy.ListFeatureClasses()
# loop through the translator file
for line in ListofLayers:
dir = arcpy.GetInstallInfo("desktop\\DirPrnInfo.txt")["InstallDir"]
translator = dir + "Metadata/Translator/ESRI_ISO2ISO19139.xml"
arcpy.ExportMetadata_conversion(line, translator, "c:\\Metadata\\" + os.path.basename(line) + ".xml") If you were to use an arcpy tool to get your list of featureclasses, then using the variable "line" would work. Not sure what you have going on with the DirPrnInfo.txt file that you are extracting from, but if it is for the path/filename information, might want to take a look at arcpy.da.walk. Will give you all in one swoop in a list that can be directly iterated through with your export conversion. R_
... View more
07-10-2013
04:06 PM
|
0
|
0
|
1506
|
|
POST
|
Kind of depends on how many years and counties you have. If not too many, might be best to use a dictionary and populate it with the possible lookup values to extract. Another way might be to: create a new field for the sequencnum create a new field for the new id iterate through and append to a list your years and another list for counties (by number) Then something like:
for year in years:
for county in counties:
lyr.definitionQuery = "years" = year AND "counties" = county # I know this isn't valid syntax, just a basic outline but would only show features in one year and county
maxValue = arcpy.SearchCursor(infc, "", "", "", "sequencnum D").next().getValue(sequencnum) # this would grab the max sequencnum if exists so you know what to start with. if no exist, then set to 1
then do your update cursor and update the newid field to (str(year) + "-" + str(county) + "-" + str(sequencenum)) # may have to .zfill to get the zeros right. something like that should "filter" the table to just one year and county at a time, then you can do the sequence number(s), then it will move onto the same year, next county, then after that year, it will do next year, first county and so on. R_ I see Stacey posted while I was writing this. Both methods should work, but I think Stacey's is more elegant, and probably execute faster.
... View more
07-10-2013
02:37 PM
|
0
|
0
|
2262
|
|
POST
|
Ionara, Don't really have time to try/test this, but here is what I would try. Sort the table by the field you want to update and get the max value with maxValue = arcpy.SearchCursor(infc, "", "", "", sortfield+" D").next().getValue("OBJECTID") or the code you have above. However, make sure the infc is the actuall feature class, not a featurelayer. If in tool, don't pick from dropdown list, click browse and navigate to the FC itself or hardcode in the script) I say to use the FC itself as the selection you have is on the featureLayer (since that is what is supported) and the def query is in the mxd, so you can iterate through all the values, regardless of def query or selection if you use the FC directly. (I think this is true. It works as stand alone, but not positive from within ArcMap, it may on the fly it again, you will have to test) Now you have the max value, you can increment as you did above maxValue += 1 You already have a selection on the feature layer, you now have the next value, so, since it is only one record that you are updating, I'd just use arcpy.CalculateField_management to update that one record. If you have multiple records in your selection, that is where I'd use your UpdateCursor, filtered to null values only AND sorted by OID (that way, they will be "sequential" relative to the order in the table). Then just increment the maxValue each loop and updateRow. Hope this gives you some ideas that actually help, R_
... View more
07-10-2013
10:08 AM
|
0
|
0
|
1656
|
|
POST
|
glad to see you got it working. I noticed that you have: desc = arcpy.Describe("Stewardship")
OIDFieldName = desc.OIDFieldName within the while loop. the Describe function can be pretty intensive operation and I don't see a need to set it within the loop. I suspect it would run considerably faster if you were to move these two lines above and out of the while loop. R_
... View more
07-09-2013
04:22 PM
|
0
|
0
|
1850
|
|
POST
|
I believe so. Not sure, but it is my understanding that, running within arc, arc will on the fly create/substitue a feature layer for tools that require it, so if the FC's are the same, I think the tool will work fine. R_
... View more
07-09-2013
01:50 PM
|
0
|
0
|
1000
|
|
POST
|
I created a toolbox and added the script and I am running from there, when I click on the script. Makes sense. So, Arc is doing the featurelayer for you. Keep in mind that if you ever try to export this out as standalone, you will get the error and have to MakeFeatureLayer first for the selection tool. R_
... View more
07-09-2013
01:46 PM
|
0
|
0
|
1000
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 05-14-2026 04:00 PM | |
| 1 | 09-14-2022 07:53 AM | |
| 1 | 09-14-2022 08:23 AM | |
| 1 | 05-21-2026 08:53 AM | |
| 1 | 05-14-2026 04:28 PM |
| Online Status |
Online
|
| Date Last Visited |
2 weeks ago
|