|
POST
|
Sure, no problem. Previously I had the following lines of code: database = arcpy.ListWorkspaces("*", "FileGDB")
arcpy.TableToDomain_management(r"S:\Projects\H107039\GIS\Domains.gdb\Landuse_Description", "Code", "Description", database[0], "Landuse Description", "Aurecon Landuse Description", "REPLACE") Whenever you use an 'arcpy.List....' function, python will return a list of values. To select an individual value from the list you need to specify an index value. That is where 'database[0]' comes into play. The first value in the list begins with index 0, second value index 1, etc. The code above simply specifies the first geodatabase in a directory, but there could be multiple geodatabase (probably why you received the error message). Therefore I changed the code to loop through each database in the list: databases = arcpy.ListWorkspaces("*", "FileGDB")
for database in databases:
arcpy.TableToDomain_management(r"S:\Projects\H107039\GIS\Domains.gdb\Landuse_Description", "Code", "Description", database, "Landuse Description", "Aurecon Landuse Description", "REPLACE") The above code will now loop through every database in each sub directory rather than just finding the first one. If you're interested in learning python I highly recommend the course Introduction to Geoprocessing Scripts Using Python.
... View more
10-27-2011
05:25 AM
|
0
|
0
|
3513
|
|
POST
|
That was my mistake. I made an error in the code and updated it afterwards. Try the following: import arcpy, os
from arcpy import env
folder = r"S:\Projects\H107039\GIS\ModelBuilder\Geodatabases"
for (path, dirs, files) in os.walk(folder):
if ".gdb" not in path.lower():
env.workspace = path
databases = arcpy.ListWorkspaces("*", "FileGDB")
for database in databases:
arcpy.TableToDomain_management(r"S:\Projects\H107039\GIS\Domains.gdb\Landuse_Description", "Code", "Description", database, "Landuse Description", "Aurecon Landuse Description", "REPLACE")
... View more
10-27-2011
04:59 AM
|
0
|
0
|
3513
|
|
POST
|
Hi Peter, It may be easiest to do this using a python script rather than model builder. Here is an example on how to do this. The below script will iterate through each sub directory in your 'H:\Projects\H107039_PeterW\workpackages' workspace: import arcpy, os
from arcpy import env
folder = r"H:\Projects\H107039_PeterW\workpackages"
for (path, dirs, files) in os.walk(folder):
if ".gdb" not in path.lower():
env.workspace = path
databases = arcpy.ListWorkspaces("*", "FileGDB")
for database in databases:
arcpy.TableToDomain_management(r"C:\TEMP\Python\domain.dbf", "Code", "Desc", database, "City") You will just need to update the line "arcpy.TableToDomain_management(r"C:\TEMP\Python\domain.dbf", "Code", "Desc", database[0], "City")". The first variable is the path to the table containing the domain. The second variable is the field containing the domain code. Third variable is the field containing the domain description, and the 5th variable is what you would like to name the domain.
... View more
10-27-2011
03:36 AM
|
0
|
0
|
690
|
|
POST
|
Hi Joseph, Adding attachments to polygon feature classes is supported. Try adding the feature class to a blank map document, start an edit session, and then see if you are able to add an attachment through the attribute window. It may be something corrupt with the MXD that is causing the issue.
... View more
10-27-2011
03:35 AM
|
0
|
0
|
1182
|
|
POST
|
Hi Peter, It may be easiest to do this using a python script rather than model builder. Here is an example on how to do this. The below script will iterate through each sub directory in your 'H:\Projects\H107039_PeterW\workpackages' workspace: import arcpy, os
from arcpy import env
folder = r"H:\Projects\H107039_PeterW\workpackages"
for (path, dirs, files) in os.walk(folder):
if ".gdb" not in path.lower():
env.workspace = path
databases = arcpy.ListWorkspaces("*", "FileGDB")
for database in databases:
arcpy.TableToDomain_management(r"C:\TEMP\Python\domain.dbf", "Code", "Desc", database, "City") You will just need to update the line "arcpy.TableToDomain_management(r"C:\TEMP\Python\domain.dbf", "Code", "Desc", database[0], "City")". The first variable is the path to the table containing the domain. The second variable is the field containing the domain code. Third variable is the field containing the domain description, and the 5th variable is what you would like to name the domain.
... View more
10-27-2011
02:58 AM
|
0
|
0
|
3513
|
|
POST
|
I believe you will want to use the 'raw_input' function to do this. Here is an example: import arcpy, os
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
env.overwriteOutput = 1
county = raw_input("Please type either WARREN, WASHINGTON, OR ESSEX: ")
key = raw_input("Please type the Parcel ID: ")
# User selects COUNTY and then Print Key value, Select by Attribute tool runs
arcpy.MakeFeatureLayer_management("Parcels", "Parcels_feat")
arcpy.SelectLayerByAttribute_management("Parcels_feat", "NEW_SELECTION", "COUNTY = " + "'" + county + "'")
arcpy.SelectLayerByAttribute_management("Parcels_feat", "NEW_SELECTION", "PARCELS_ID = " + key)
arcpy.CopyFeatures_management("Parcels_feat", "Parcels_Selection")
print "Executed succesfully" This will prompt the user for a county name and a parcel ID.
... View more
10-21-2011
09:35 AM
|
0
|
0
|
611
|
|
POST
|
Hi James, I am assuming your shapefile begins with a number since it is based off of the buffer value. This could be causing the problem. When naming a shapefile/feature class, the name should not: 1. Begin with a number 2. Contain special characters (i.e. !, ?, #...) 3. Contain spaces
... View more
10-17-2011
08:00 AM
|
0
|
0
|
1142
|
|
POST
|
Awesome, your method will be much easier! I was having trouble figuring out how to convert a list to a string. Thanks for the syntax: x = ", ".join(myList)
... View more
10-17-2011
06:11 AM
|
0
|
0
|
1703
|
|
POST
|
I was able to do this by appending the feature classes to a list, writing the list to a text file, reading the text file as a string while removing the last comma, and then finally writing the string using the arcpy.AddMessage function. Here is an example of how to do this with a list of feature classes: import arcpy, os
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
# Create an empty list
list = []
# Create a text file
output = open(r"C:\temp\python\list.txt", "w")
lstFCs = arcpy.ListFeatureClasses("*")
for fc in lstFCs:
list.append(fc)
# write each feature class to the text file
for n in list:
output.write(n + " ")
# read the text file and add commas
output = open(r"C:\temp\python\list.txt", "r")
s = output.read()
s = s.rstrip()
s = s.replace(" ", ", ")
arcpy.AddMessage(s)
# close and delete the text file
output.close()
os.remove(r"C:\temp\python\list.txt")
... View more
10-17-2011
05:04 AM
|
0
|
0
|
1703
|
|
POST
|
I could not reproduce the behavior you are experiencing. Placing this syntax outside the loop created no errors, and the script executed successfully. I'm not sure why the script is running in a continuous loop for you. If I placed the 'del row, rows....' inside the while loop I would receive "NameError: name 'row' is not defined" error message. If the script is executing successfully with this error message, you can run an except to pass this error within the while loop:
try:
del row, rows, row2, rows2
except NameError:
pass Though, this may cause the script to skip over some counties and not update the 'URBPOP' field correctly.
... View more
10-17-2011
04:03 AM
|
1
|
1
|
1826
|
|
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
|
1826
|
|
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
|
5457
|
|
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
|
5457
|
|
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
|
5457
|
|
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
|
2053
|
| Title | Kudos | Posted |
|---|---|---|
| 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 | |
| 1 | 12-29-2025 06:27 AM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|