|
POST
|
I would try printing each version name while looping over them, just to make sure all the expected versions are getting iterated over. print "Target: {0}".format(versionName)
for version in arcpy.da.ListVersions(sdeConnection):
print "Found - {0}".format(version.name.split(".")[0])
if version.name.split(".")[0] == versionName:
print(userVersion)
versionFound = True
break
... View more
02-21-2018
10:28 AM
|
0
|
3
|
6305
|
|
POST
|
I think you need to dedent the code block starting at line 72. For every version in the ListVersions, the second if statement will get executed within the for loop. And, since you're already specifying that versionFound = False (64), the CreateVersion will try to execute. try:
for version in arcpy.da.ListVersions(sdeConnection):
if version.name.split(".")[0] == versionName:
print(existingVersion)
versionFound = True
break
#Execute CreateVersion
if not versionFound:
arcpy.CreateVersion_management(sdeConnection, parentVersion, versionName, "PROTECTED")
print(createVersion)
except arcpy.ExecuteError:
print(arcpy.GetMessages())
... View more
02-21-2018
09:01 AM
|
1
|
7
|
6305
|
|
POST
|
You're going to want to wrap your path string in a r to make it "raw". Also, you have a dangling '/'. Please remove that, and the env setting (you're not using any of it's powers here) in line 6 and try again. Does that table actually exist? # Set local variables
datasource = r"D:\Work\Everything\trial"
inTable = os.path.join(datasource,"Murray Sp2")
fieldName = "DipDir"
... View more
01-12-2018
11:53 AM
|
0
|
1
|
3806
|
|
POST
|
You're getting that error because the datasource you're trying to get to it being used by another application (probably ArcMap or ArcCatalog). I edited the code snippet to include: A total datasource path (perhaps you just didn't include in the snippet) You can AddFieldDelimiters so you can query different datasources Use can use the built-in format function when writing strings Change 'Shape@' to 'SHAPE@' in line 23 Make sure to delete the cursor after you've exhausted it to ensure no future data locks Have you tested the cursor? I don't think it will work since you're assigning a row value to a function which seems to return two in-mem layers. Please explain. Lastly, this code doesn't show the in-memory layers being used anywhere. What is the purpose of making the layers exactly? I hope this helps. I can't be too sure this will work without seeing the entire code. datasource = r'path/to/datasource/folder/or/geodatabase'
inTable = os.path.join(datasource,"Murray Sp2")
fidField = arcpy.AddFieldDelimiters(datasource, 'FID')
def Strike(shape, fid):
if length >= 183 and length <= 185:
arcpy.MakeFeatureLayer_management(inTable, 'shapelyr', "{0} = {1}".format(fidField, str(fid)))
arcpy.MakeFeatureLayer_management(inTable, 'PairedCheck6', "{0} <> {1}".format(fidField, str(fid)))
cursor = arcpy.da.UpdateCursor(inTable, ['SHAPE@','FID',fieldName])
for row in cursor:
row[2] = Strike(row[0], row[1])
cursor.updateRow(row)
del cursor
... View more
01-12-2018
07:02 AM
|
1
|
0
|
3806
|
|
POST
|
I deleted the relationship class to the attached table, and the following code worked for me. I haven't tested it with the relationship intact. import arcpy
#Trigger: When it sees a change in date, it will then add frequency to that date
#What needs to be populated: compound, maintenance task, and park
#Attributes for Each Maintenance Task feature
CompAttribs = {
"Mississippi Shelter": [(751925.962298,279303.484179) ,"Mississippi Shelter", "Walter Chandler"],
"Willow Road": [(815946.106614, 815946.106614), "Willow Road", "Hickory Hill Park"],
"MLK Riverside": [(747845.301725, 301161.452951),"MLK Riverside", "King"],
"City Center Armory":[(771656.687393, 309099.380722),"City Center Armory", "Glenview"],
"Armory":[(791820.996015, 313373.492286),"Armory","Galloway"],
"Kennedy":[(800029.764326, 336054.100493),"Kennedy","Kennedy"],
"Frayser":[(769122.906674, 359343.580918),"Frayser","Firestone"]}
MaintFreq = {
"Empty Trash Receptacle": ["Maint",2],
"Inventory Report": ["Maint",30],
"Leaf Mulching": ["Maint",14,],
"Litter Pick Up":["Maint",2],
"Mow Edge Trim Blow": ["Maint",1],
"Pruning Hedges": ["Maint",14],
"Safety Assessment": ["MaintOps",30],
"Asset Inspection": ["MaintOps",30],
"Playground Inspection": ["MaintOps",30]}
arcpy.env.workspace =r""
workspace = r""
fc = r""
Fields = ["SHAPE@XY","Compound_Name","Maintenance_Task","Maintenance_Task_MandO"]
#Opening Editing Session
try:
print "Editing Session Opened"
edit = arcpy.da.Editor(workspace)
edit.startEditing(True, False)
edit.startOperation()
newMaintTask = arcpy.da.InsertCursor(fc,Fields)
for Comps in CompAttribs:
for Task in MaintFreq:
if MaintFreq[Task][0] == "Maint":
row = [CompAttribs[Comps][0],CompAttribs[Comps][1],Task,""]
#print row
newMaintTask.insertRow(row)
elif MaintFreq[Task][0] == "MaintOps":
row1 = [CompAttribs[Comps][0],CompAttribs[Comps][1],"",Task]
#print row1
newMaintTask.insertRow(row1)
except Exception as e:
print e
finally:
edit.stopOperation()
edit.stopEditing(True)
... View more
01-10-2018
12:22 PM
|
1
|
1
|
2084
|
|
POST
|
I don't understand what's going on in this code snippet. You're iterating over two dictionaries, but they don't seem to be related at all. try:
newMaintTask = arcpy.da.InsertCursor(fc,Fields)
for Comps in CompAttribs:
for Task in MaintFreq:
if MaintFreq[Task][0] == "Maint":
newMaintTask.insertRow([CompAttribs[Comps][0],CompAttribs[Comps][1],Task,""])
else:
newMaintTask.insertRow([CompAttribs[Comps][0],CompAttribs[Comps][1],"",Task]) I assume the output would be nine points (nine iterations of the MainFreq dict) at each X,Y from CompAttribs. Can you explain how these two dictionaries are related?
... View more
01-10-2018
11:35 AM
|
0
|
1
|
2084
|
|
POST
|
os.path.join literally joins two strings together to make a complete file path. The documentation states, Join one or more path components intelligently. See here
... View more
01-02-2018
11:04 AM
|
1
|
0
|
3465
|
|
POST
|
I assume you want to do this process for each FeatureClass in the database? But, you're right that the 'full_path_to_fc' is incorrect. You need to pass two arguments to the os.path.join function in order to get a combined path to the feature class. The below code should get you started. I added a database variable and set the workspace to that. You don't need to use the 'AddXY_management', because you can access geometry values with tokens. All point FeatureClass names are in a list to iterate over. There were some slight indentation problems (line 9, 14, 15). I added a line to delete the "rows" generator object after it's exhausted. import arcpy
import os
database = r'C:\Users\ANCGIS\Desktop\ANC\Resources\Test\MartinezUtiliyData.gdb'
arcpy.env.workspace = database
arcpy.env.overwriteOutput = True
#Python list of all point FC names
fclist = [x.name for x in arcpy.ListFeatureClasses(feature_type='Point')]
for fc in fclist:
full_path_to_fc = os.path.join(database, fc)#join database and fc name
with arcpy.da.UpdateCursor(full_path_to_fc, ["coordinateX","coordinateY","SHAPE@XY"]) as rows:
for row in rows:
row[0] = row[2][0]
row[1] = row[3][1]
rows.updateRow(row)
del rows
arcpy.DeleteField_management(full_path_to_fc, 'POINT_X')
arcpy.DeleteField_management(full_path_to_fc, 'POINT_Y')
... View more
01-02-2018
09:22 AM
|
0
|
2
|
3465
|
|
POST
|
I can't help there, Greg. I'm not familiar with the "Address Standardization" process.
... View more
12-19-2017
11:30 AM
|
0
|
0
|
2101
|
|
POST
|
Is the data set standardized in some way? Does 'Unit' always come before the unit #?
... View more
12-19-2017
09:18 AM
|
1
|
2
|
2101
|
|
POST
|
I understand... but, what does "lowest available address" mean? The southern-most address?
... View more
12-19-2017
07:49 AM
|
0
|
0
|
2503
|
|
POST
|
I would use a spatial join. What do you mean by "lowest available address"?
... View more
12-19-2017
07:30 AM
|
0
|
0
|
2503
|
|
POST
|
Could you try creating a layers out of the rasters before processing them. The below code creates layers for the target and input rasters. target_features = r'C:\Users\mmoore\Documents\ArcGIS\COA.gdb\PlanningUnit_Hex10acre'
#target raster layer
arcpy.MakeRasterLayer_management(target_features, "targetLyr")
for sdm in sdms:
print sdm + " started at: " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
sdm_path = os.path.join(sdm_folder,sdm)
arcpy.MakeRasterLayer_management(sdm_path,"{0}Lyr".format(sdm))#makes in-mem raster
rastTable = r"{0}_{1}".format(os.path.join(outTable, "tab_area_temp"),
str(sdm)
)
tab_area = TabulateArea("targetLyr",
"unique_id",
"{0}Lyr".format(sdm),
"Value",
rastTable,
30
)
arcpy.Delete_management("{0}Lyr".format(sdm))
... View more
12-14-2017
06:41 AM
|
1
|
0
|
1039
|
|
POST
|
See if this works for you. As Joshua mentioned, if the table you're showing in your post is sorted on the data field, you'll need to add a sql_clause to sort. If not, the cursor will run in OID order (I think ). import arcpy
ds = r'complete\path\to\dataset'
switch = ''
with arcpy.da.UpdateCursor(ds, ['event']) as cursor:
for row in cursor:
if row[0] == 'Brushes On':
pass
switch = 'on'
elif row[0] == 'Brushes Off':
pass
switch = 'off'
elif switch == 'off':
cursor.deleteRow()
else:
pass
del cursor
... View more
12-13-2017
02:20 PM
|
2
|
1
|
6979
|
|
POST
|
Try specifying the processing cell size as an integer and not as a string. Also, if you're looping over multiple rasters, you're going to need a specific output for each one. Right now, you're looping over the rasters and saving the TabulateArea output table as a single name. I would try something like this: rastTable = r"{0}_{1}".format(os.path.join(outTable, "tab_area_temp"),
str(sdm))
tab_area = TabulateArea(target_features,
"unique_id",
sdm,
"Value",
rastTable,
30)
... View more
12-13-2017
01:53 PM
|
1
|
3
|
2352
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-28-2024 11:43 AM | |
| 1 | 09-12-2025 07:32 AM | |
| 1 | 10-26-2018 06:50 AM | |
| 1 | 10-26-2018 08:43 AM | |
| 1 | 02-25-2016 07:50 PM |
| Online Status |
Offline
|
| Date Last Visited |
4 weeks ago
|