|
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:46 AM
|
0
|
0
|
1232
|
|
POST
|
Hi J, You can do this using the '.rsplit' method. Ex: !Details_Primary_Address1!.rsplit(',', 1)[0]
... View more
09-29-2011
02:35 AM
|
0
|
0
|
1012
|
|
POST
|
What are you attempting to update with the 'UpdateCursor' function? The field names will be different with a temporary join. Can you post the rest of your code?
... View more
09-28-2011
11:34 AM
|
0
|
0
|
532
|
|
POST
|
Hi Casey, I was able to get this to work with the following code. It will loop through each feature in a feature class and create a 2x2 fishnet for each feature. import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
env.overwriteOutput = True
fc = "Airports"
rows = arcpy.SearchCursor(fc)
for row in rows:
x = row.OBJECTID
arcpy.MakeFeatureLayer_management(fc, "fc_lyr", "OBJECTID = " + str(x))
rows2 = arcpy.SearchCursor("fc_lyr")
for row2 in rows2:
XMIN = row2.shape.extent.XMin
YMIN = row2.shape.extent.YMin
XMAX = row2.shape.extent.XMax
YMAX = row2.shape.extent.YMax
YMIN2 = row2.shape.extent.YMin + 10
orig_coord = str(XMIN) + " " + str(YMIN)
y_axis = str(XMIN) + " " + str(YMIN2)
corner_coord = str(XMAX) + " " + str(YMAX)
arcpy.CreateFishnet_management("Fishnet_" + str(x), orig_coord, y_axis, "0", "0", "2", "2", corner_coord, "NO_LABELS", "", "POLYGON")
del row, rows, row2, rows2
... View more
09-28-2011
11:01 AM
|
0
|
0
|
1014
|
|
POST
|
I would recommend using the 'Create Fishnet' tool to create a polygon envelope of 4 equal pieces. You can use a feature class as the extent and then simply specify the number of columns and rows.
... View more
09-28-2011
08:44 AM
|
0
|
0
|
1014
|
|
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
|
1829
|
|
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
|
2539
|
|
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
|
2539
|
|
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
|
1010
|
|
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
|
1297
|
|
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
|
2741
|
|
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
|
1435
|
|
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
|
704
|
|
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
|
2672
|
|
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
|
3530
|
| 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
|