|
POST
|
Are you attempting to write the new text values to the same field or a new field? I was able to get the code working when writing the values to a new field. I have the 25, 75, 120 values in a field called 'Class' and then I created a new field called 'Description'. Next, I ran the following code: Pre-logic Script Code: def Reclass(SetbackType):
if SetbackType == 25:
return "25 ft Setback"
elif SetbackType == 75:
return "75 ft Setback"
elif SetbackType == 120:
return "120 ft Setback" Description = Reclass(!Class!)
... View more
09-28-2011
08:37 AM
|
0
|
0
|
1740
|
|
POST
|
Sorry, that was a copy/paste error on my end. Here is what it should be: import arcpy, os, glob
from arcpy import mapping
folderPath = r"Z:\ESRI\Figure_Sourcing\Figures\MapSourcingTest"
env.overwriteOutput = True
for filename in glob.glob(os.path.join(folderPath, "*.mxd")):
fullpath = os.path.join(folderPath, filename)
mxd = mapping.MapDocument(filename)
for df in mapping.ListDataFrames(mxd, "*"):
for lyr in mapping.ListLayers(mxd, "*", df):
print lyr.name
new_name = lyr.name + "_IF"
try:
lyr.replaceDataSource(r"Z:\Site\Sitename\D01_IF.gdb", "FILEGDB_WORKSPACE", new_name)
except ValueError:
pass
print "Successfully updated layer"
mxd.saveACopy(r"Z:\ESRI\Figure_Sourcing\Figures\TestFigs\IOR\MapSourcingTest\Test2.mxd")
del mxd
... View more
09-28-2011
02:49 AM
|
0
|
0
|
2271
|
|
POST
|
The problem may be that your not specifying the data frame. Try the following below. It will replace all feature classes within an MXD with its corresponding feature class in the other file geodatabase. import arcpy, os, glob
from arcpy import mapping
folderPath = r"Z:\ESRI\Templates\IOR_2010\TemplateFiles\TemplateFiles.gdb\SOILS"
env.overwriteOutput = True
for filename in glob.glob(os.path.join(folderPath, "*.mxd")):
fullpath = os.path.join(folderPath, filename)
mxd = mapping.MapDocument(filename)
for df in mapping.ListDataFrames(mxd, "*"):
for lyr in mapping.ListLayers(mxd, "*", df):
print lyr.name
new_name = lyr.name + "_IF"
try:
lyr.replaceDataSource(r"Z:\Site\Sitename\D01_IF.gdb\SOILS_IF", "FILEGDB_WORKSPACE", new_name)
except ValueError:
pass
print "Successfully updated layer"
mxd.saveACopy(r"Z:\ESRI\Figure_Sourcing\Figures\TestFigs\IOR\MapSourcingTest\Test2.mxd")
del mxd
... View more
09-26-2011
12:10 PM
|
0
|
0
|
2271
|
|
POST
|
When calculating area or length for a feature class, the units will be based off of the coordinate system. For example, if your feature class is projected to State Plane Feet the calculated area/length will be in feet. If you use the 'arcpy.UpdateCursor' function you can calculate the area/length based off of another coordinate system. A geographic coordinate system (i.e. WGS 1984) will return the area/length as decimal degrees. Here is an example: import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
fc = "Mains"
rows = arcpy.UpdateCursor(fc, "", "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj")
for row in rows:
geom = row.shape
row.Area_DD = geom.area
rows.updateRow(row)
del row, rows The mains feature class is projected to 'NAD_1983_StatePlane_Michigan_South_FIPS_2113_IntlFeet', but I specified the geographic coordinate system 'WGS 1984' within the UpdateCursor function. Now when I calculate the area to field 'Area_DD' it will be in Decimal Degrees rather than feet.
... View more
09-26-2011
05:46 AM
|
0
|
0
|
912
|
|
POST
|
Is your Class field formatted with a ',' or a '.' for the decimal? Try the following instead: def reclass(ICISS):
if (ICISS >= 0 and ICISS <= 0.4):
return "very low"
elif (ICISS > 0.4 and ICISS <= 0.6):
return "medium low"
elif (ICISS > 0.6 and ICISS <= 0.8):
return "medium high"
else:
return "very high"
... View more
09-21-2011
11:06 AM
|
0
|
0
|
1183
|
|
POST
|
What RDBMS are you using (i.e. SQL Server, Oracle, PostgreSQL)? Below is an example on how to do this using SQL Server. You can download the 'pyodbc' library here. This will allow you to connect to SQL Server using python. You can then execute the following code to find all existing domains in your SDE geodatabase: import pyodbc
cnxn = pyodbc.connect('Driver={SQL Server Native Client 10.0};UID=<username>;PWD=<password>;SERVER=<server name>;DATABASE=<database>;')
cursor=cnxn.cursor()
cursor.execute("SELECT items.Name AS 'Domain Name', items.Definition.value('(/*/Owner)[1]','nvarchar(max)') \
AS 'Owner' FROM sde.GDB_ITEMS AS items INNER JOIN sde.GDB_ITEMTYPES AS itemtypes ON \
items.Type = itemtypes.UUID WHERE itemtypes.Name IN ('Coded Value Domain', 'Range Domain')")
rows = cursor.fetchall()
for row in rows:
print row[0]
cursor.close()
cnxn.close() You will need to update the connection string (cnxn = pyodbc.connect('Driver={SQL Server Native Client 10.0};UID=<username>;PWD=<password>;SERVER=<server name>;DATABASE=<database>;') with the correct username, password, server, and database.
... View more
09-20-2011
03:21 AM
|
0
|
0
|
2601
|
|
POST
|
I believe 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 make it permanent, and disable the option to delete it. As a workaround you could create a script to check all 'required' fields for empty values. Here is an example: import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
fc = "Req_Test"
lstFields = arcpy.ListFields(fc, "*")
for field in lstFields:
if field.required == True:
field_name = field.name
rows = arcpy.SearchCursor(fc, "", "", field_name)
for row in rows:
val = row.getValue(field_name)
if val == " ":
print field_name + " contains a blank row for OBJECTID " + str(row.OBJECTID)
del row, rows
... View more
09-19-2011
12:11 PM
|
0
|
0
|
1345
|
|
POST
|
Here is an example of the script. I could not find a way to list networks (i.e. geometric, topology, etc) within the database. The below script will list all feature datasets, feature classes (including geometry and data type), and tables and write the output to a txt file. You will just need to change the 'env.workspace' variable to the path of your GDB and the 'outtable' variable to a directory. The text file will automatically be created. import arcpy, os
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
outtable = open(r"C:\temp\python\results.txt", "w")
for dataset in arcpy.ListDatasets("*"):
desc = arcpy.Describe(dataset)
outtable.write(dataset + " " + desc.datasetType + "\n")
for fc in arcpy.ListFeatureClasses("*", "", dataset):
desc = arcpy.Describe(fc)
outtable.write(fc + " " + desc.datasetType + " " + desc.featureType + " " + desc.shapeType + "\n")
for fc in arcpy.ListFeatureClasses("*"):
desc = arcpy.Describe(fc)
outtable.write(fc + " " + desc.dataType + " " + desc.featureType + " " + desc.shapeType + "\n")
for table in arcpy.ListTables("*"):
desc = arcpy.Describe(table)
outtable.write(table + " " + desc.dataType + "\n")
outtable.close()
... View more
09-14-2011
09:26 AM
|
0
|
0
|
634
|
|
POST
|
How is the TIFF image added to your map document? Is it added using the 'Add Data' button, or is it added using 'Insert > Picture'? Have you tried converting the TIFF to a different format (i.e. JPEG) and see if it that works?
... View more
09-14-2011
08:30 AM
|
0
|
0
|
2391
|
|
POST
|
You will not need to add quotes to each item in the list. Python will already read it as a string. Ex:
tableList = arcpy.ListTables()
for table in tableList:
print table
# how many tables are there
leta = len(tableList)
print leta
x=0
# loop through all tables
while x < leta:
Listfieldx = tableList
fieldList = arcpy.ListFields(Listfieldx,"*","*")
for field in fieldList:
print field.name
x += 1
... View more
09-13-2011
11:02 AM
|
0
|
0
|
3270
|
|
POST
|
You could accomplish this by intersecting the sites and floodplain layer, perform a join and then calculate the percent coverage using the 'Shape_Area' fields. Here is an example: import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
env.overwriteOutput = True
fc1 = "DevelopmentSites"
fc2 = "FloodPlain"
# Add field to DevelopmentSites
arcpy.AddField_management(fc1, "Percentage", "Double")
# Perform an intersect between DevelopmentSites & FloodPlain feature classes
arcpy.Intersect_analysis([[fc1], [fc2]], "Intersect")
# Join intersecting feature class with DevelopmentSites
arcpy.MakeFeatureLayer_management(fc1, "development_layer")
arcpy.AddJoin_management("development_layer", "OBJECTID", "Intersect", "FID_DevelopmentSites")
# Calculate Percentage of flood plain coverage
arcpy.CalculateField_management("development_layer", "DevelopmentSites.Percentage", "!Intersect.Shape_Area! / !DevelopmentSites.Shape_Area! * 100", "PYTHON")
# Delete Intersect feature class
arcpy.Delete_management("Intersect") The result will be a new field called 'Percentage' within the DevelopmentSites feature class with the percent coverage of the flood plain feature class.
... View more
09-13-2011
08:49 AM
|
0
|
0
|
1639
|
|
POST
|
I was able to compare two annotation feature classes using the Shape fields. Below is an example of the code I used: fc = "AirportsAnno"
fc2 = "AirportsAnno_1"
y = str(arcpy.GetCount_management(fc))
x = 1
while x <= int(y):
rows = arcpy.SearchCursor(fc, "OBJECTID = " + str(x))
rows2 = arcpy.SearchCursor(fc2, "OBJECTID = " + str(x))
for row in rows:
geom = row.shape
for row2 in rows2:
geom2 = row2.shape
if geom.equals(geom2):
print "OBJECTID " + str(row.OBJECTID) + " matches"
else:
print "OBJECTID " + str(row.OBJECTID) + " does not match"
x += 1
del row, rows, row2, rows2 I tested this on the annotation feature class when a feature's text was updated, and when the annotation was moved. In both cases the script reported that the features do not match.
... View more
09-13-2011
04:27 AM
|
0
|
0
|
651
|
|
POST
|
If I am understanding you correctly, you are trying to sum the two distance fields from 'Table_2' & 'Table_3' and show the sum in 'Table_1'. To do this, you can add a new field to 'Table_1' called 'Distance' and then use a python script to update this field by summing the Distance fields from 'Table_2' & 'Table_3'. Here is an example on how to do this: import arcpy, os
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
env.overwriteOutput = True
# Add Distance field if it does not exist
lstFields = arcpy.ListFields("Table_1")
for field in lstFields:
if field.name == "Distance":
""
else:
arcpy.AddField_management("Table_1", "Distance", "Double")
# Join tables
arcpy.MakeTableView_management("Table_1", "Table_1_View")
arcpy.AddJoin_management("Table_1_View", "Name_ID", "Table_2", "Name_ID")
arcpy.AddJoin_management("Table_1_View", "Table_1.Name_ID", "Table_3", "Name_ID")
# Update Distance field
arcpy.CalculateField_management("Table_1_View", "Table_1.Distance", "!Table_2.Distance! + !Table_3.Distance!" , "PYTHON")
print "Successful"
... View more
09-12-2011
04:02 AM
|
0
|
0
|
503
|
|
POST
|
You can add a domain to a feature class without creating a subtype. If your feature class has a subtype, the domain must be applied at the subtype level. If it has no subtype, you can apply the domain directly to the field(s). Take a look at the following links on how to create a domain and apply it to a feature class: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001s00000004000000.htm http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Associating_default_values_and_domains_with_tables_and_feature_classes/001s00000009000000/
... View more
09-08-2011
10:41 AM
|
0
|
0
|
1698
|
| 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 |
Online
|
| Date Last Visited |
yesterday
|