|
POST
|
Try placing the syntax to delete the cursors outside of the while loop: while x <= maxOID:
list2 = []
arcpy.MakeFeatureLayer_management(counties, "counties_feat", "OBJECTID = " + str(x))
arcpy.SelectLayerByLocation_management("cities_feat", "WITHIN", "counties_feat")
rows = arcpy.SearchCursor("cities_feat")
for row in rows:
pop = row.getValue("POP_98")
list2.append(pop)
sumlist = sum(list2)
rows2 = arcpy.UpdateCursor("counties_feat")
for row2 in rows2:
row2.URBPOP = sumlist
rows2.updateRow(row2)
msg = " - " + row2.NAME_1 + " - " + "Urban Population: " + str(sumlist)
arcpy.AddMessage(msg)
x += 1
del row, rows, row2, rows2
arcpy.Delete_management("counties_feat")
arcpy.Delete_management("cities_feat")
... View more
10-14-2011
11:49 AM
|
0
|
0
|
2045
|
|
POST
|
From the looks of your code I believe you are trying to select all cities within a county, sum the population of the cities and update a field in the counties feature class with this value. You can easily do this by creating a spatial join. You can right-click on the counties feature class in ArcMap's table of contents > Joins and Relates > Joins. Specify to join attributes spatially and choose to sum the fields. This will produce a new output feature class with the summed population (and summed outputs of all other numeric fields) of all cities within each county. If you do not want a new feature class, and the other summed numeric fields, you can use python. Here is the code that I was able to get to work: import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
env.overwriteOutput = True
cities = "Cities"
counties = "Counties"
arcpy.MakeFeatureLayer_management(cities, "cities_feat")
list = []
# Get max OBJECTID for loop
rows = arcpy.SearchCursor(counties)
for row in rows:
OID = row.getValue("OBJECTID")
list.append(OID)
maxOID = list[-1]
del row, rows
x = 1
while x <= maxOID:
list2 = []
arcpy.MakeFeatureLayer_management(counties, "counties_feat", "OBJECTID = " + str(x))
arcpy.SelectLayerByLocation_management("cities_feat", "WITHIN", "counties_feat")
rows = arcpy.SearchCursor("cities_feat")
for row in rows:
pop = row.getValue("POPULATION")
list2.append(pop)
sumlist = sum(list2)
rows2 = arcpy.UpdateCursor("counties_feat")
for row2 in rows2:
row2.URBPOP = sumlist
rows2.updateRow(row2)
x += 1
del row, rows, row2, rows2
... View more
10-14-2011
04:29 AM
|
0
|
0
|
5732
|
|
POST
|
I believe you will also need to add another line for the update to occur. for polyRow in polyRows:
firstPart = '"NAME_1" ='
lastPart = "'" + '' + "'"
where_clause = firstPart + lastPart
arcpy.MakeFeatureLayer_management(inPoly,"oneCounty",where_clause)
arcpy.SelectLayerByLocation_management("allPoints", "WITHIN", "oneCounty")
list= []
fc = "allPoints"
rows = arcpy.SearchCursor(fc)
for row in rows:
pop = row.getValue("POP_98")
list.append(pop)
msg = " - " + polyRow.NAME_1 + " - " + "Urban Population: " + sum(list)
UrbanPop= sum(list)
arcpy.AddMessage(msg)
polyRow.URBPOP = int(UrbanPop)
polyRows.updateRow(polyRow)
arcpy.Delete_management("oneCounty")
... View more
10-12-2011
12:13 PM
|
0
|
0
|
5732
|
|
POST
|
Hi Peter, Here is an example on how to do this. The below code will append all the rows from the population field to a list using a search cursor, then it will sum the list. import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
fc = "Cities"
list = []
rows = arcpy.SearchCursor(fc)
for row in rows:
pop = row.getValue("POPULATION")
list.append(pop)
print sum(list)
... View more
10-12-2011
04:16 AM
|
0
|
0
|
5732
|
|
POST
|
The option 'Add Database Server' is only for ArcSDE Workgroup and ArcSDE Personal editions. Both of these versions are only available for SQL Server Express. ArcSDE Workgroup and Personal are pretty much scaled down versions of ArcSDE. You are limited to storage, number of editors, and number of connections. Since you are using Oracle, you are using ArcSDE Standard or Advanced edition.
... View more
10-11-2011
03:40 AM
|
0
|
0
|
2217
|
|
POST
|
Hi Martin, How large is the feature class you are trying to edit (i.e. 10,000 features)? Also, would you be able to create a test feature class, save it in a new MXD, publish the MXD to server and see if you can reproduce this error? I'm wondering if it's something specific to your configuration or something with this specific feature class/service. Thanks, Jake
... View more
10-10-2011
07:30 AM
|
0
|
0
|
1390
|
|
POST
|
Here is an example on how to do this: import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\VECTOR.sde"
for fc in arcpy.ListFeatureClasses("*"):
for field in arcpy.ListFields(fc, "", "GlobalID"):
if field.name == "GlobalID":
print fc + " contains GlobalIDs"
for fd in arcpy.ListDatasets("*"):
for fc in arcpy.ListFeatureClasses("*", "", fd):
for field in arcpy.ListFields(fc, "", "GlobalID"):
if field.name == "GlobalID":
print fc + " contains GlobalIDs" The above code will search all stand-alone feature classes, and feature classes with feature datasets to see if the GlobalID field exists. You will just need to update 'env.workspace' to your SDE connection file.
... View more
10-10-2011
06:26 AM
|
0
|
3
|
2292
|
|
POST
|
Is the client machine able to access the virtual output directory? You can follow the steps in the following KB article to see if they can. If the client cannot, this is most likely why you are receiving the error message.
... View more
10-10-2011
06:08 AM
|
0
|
0
|
1390
|
|
POST
|
Looks like the problem is with your 'df' variable. You will need to reference the MXD and then the data frame. Change it to the following and I believe everything should work: df = arcpy.mapping.ListDataFrames (mxd, "Layers") [0]
... View more
10-05-2011
10:56 AM
|
0
|
0
|
2390
|
|
POST
|
What version of ArcGIS are you using? If you are using ArcGIS 10, I would recommend creating a mosaic dataset.
... View more
10-05-2011
04:52 AM
|
0
|
0
|
658
|
|
POST
|
The web help is incorrect where it states: REQUIRED �??The field is a required field. This means new records must contain a value for the field. Required fields are permanent and can not be deleted. 'This means new records must contain a value for the field' should be removed. Setting a field to 'Required' will only make it permanent, and disable the option to delete it.
... View more
10-05-2011
04:45 AM
|
0
|
0
|
850
|
|
POST
|
Hi gabrisch, You actually cannot have a feature class with the same name, even if it resides in a separate feature dataset.
... View more
10-05-2011
03:48 AM
|
0
|
0
|
2093
|
|
POST
|
I wasn't able to find a way to accomplish this just using the Describe function, but was able to get the full path by combining the Describe function with some OS functions and looping through each feature dataset. Ex: catalogPath = arcpy.Describe("Highway").catalogpath
for FD in arcpy.ListDatasets("*"):
for FC in arcpy.ListFeatureClasses("*", "", FD):
if os.path.basename(catalogPath) in FC:
fullPath = os.path.dirname(catalogPath) + os.sep + FD + os.sep + FC
print fullPath
... View more
10-05-2011
03:46 AM
|
0
|
0
|
1877
|
|
POST
|
Hi Scott, Can you elaborate a little more on what you will be copying (i.e. tables, feature classes, etc)? What is the purpose of a daily copy from your FGD to SDE? Is it to update the SDE feature classes with edits that were created in the FGD? If so, have you considered geodatabase replication? This will allow you to synchronize changes from the FGD to SDE with a click of a button.
... View more
09-30-2011
04:26 AM
|
0
|
4
|
4178
|
|
POST
|
Hi Tim, Here is an example on how to do this using the 'ArcSDESqlExecute' function, as lpugh01 mentioned: import arcpy
sdeConn = arcpy.ArcSDESQLExecute("GIS01", "sde:oracle11g:orcl", "", "vector", "vector")
tableList = ["School_District, "Building_Sites", "Parcels"]
for table in tableList:
print table + " contains the following cities:"
try:
print sdeConn.execute('select distinct City from ' + table)
except AttributeError:
print "None, field does not exist" The above code will run through each table and search for a field named 'City' and return the distinct values.
... View more
09-30-2011
03:47 AM
|
0
|
0
|
1233
|
| Title | Kudos | Posted |
|---|---|---|
| 4 | 05-07-2020 05:14 PM | |
| 1 | 03-25-2026 04:16 AM | |
| 1 | 03-16-2026 01:00 PM | |
| 1 | 12-22-2025 10:39 AM | |
| 1 | 01-20-2026 04:04 AM |
| Online Status |
Offline
|
| Date Last Visited |
Thursday
|