|
POST
|
Here is a link to some ESRI training courses: http://training.esri.com/gateway/index.cfm?fa=search.results&searchterm=python+arcpy I highly recommend 'Introduction to Geoprocessing Scripts Using Python'.
... View more
08-29-2011
08:47 AM
|
0
|
0
|
681
|
|
POST
|
If you are using ArcGIS 10, the new Transpose Fields tool may be of some help.
... View more
08-29-2011
07:25 AM
|
0
|
0
|
575
|
|
POST
|
Here is an example on how to do this. The code uses the Summary Statistics tool to summarize the Area field in each polygon feature class within feature datasets, then writes the feature class name and Area sum to a previously created table. import arcpy
from arcpy import env
env.overwriteOutput = True
env.workspace = r"C:\MapsandGeodatabase\LocalGovernment.gdb"
arcpy.CreateTable_management(env.workspace, "AREA_SUM")
arcpy.AddField_management("AREA_SUM", "Name", "Text", "75")
arcpy.AddField_management("AREA_SUM", "SUM_Shape_Area", "Double")
for dataset in arcpy.ListDatasets("*"):
lstFCs = arcpy.ListFeatureClasses("*", "", dataset)
for fc in lstFCs:
desc = arcpy.Describe(fc)
if desc.shapeType == "Polygon":
rows = arcpy.InsertCursor("AREA_SUM")
row = rows.newRow()
row.Name = fc
sumArea = arcpy.Statistics_analysis(fc, "Stats", [["Shape_Area", "SUM"]])
rows2 = arcpy.SearchCursor(sumArea)
for row2 in rows2:
totArea = row2.getValue("SUM_Shape_Area")
row.SUM_Shape_Area = totArea
rows.insertRow(row)
totArea = 0
del row, rows, row2, rows2
arcpy.Delete_management("Stats")
... View more
08-26-2011
04:26 AM
|
0
|
0
|
681
|
|
POST
|
You could do this using a 'while' loop. Ex: x = 4
while x < 10:
lstRasters = gp.ListRasters("*" + str(x))
for raster in lstRasters:
print raster
x += 1
... View more
08-23-2011
07:05 AM
|
1
|
0
|
754
|
|
POST
|
Sorry for the misunderstanding. Here is an example on how to change the layer names: import arcpy, os
from arcpy import env
from arcpy import mapping
env.workspace = r"C:\temp\python"
env.overwriteOutput = True
for (path, dirs, files) in os.walk(env.workspace):
for file in files:
if ".mxd" in file.lower():
mxd = os.path.join(path, file)
mxd = mapping.MapDocument(mxd)
for df in mapping.ListDataFrames(mxd, "*"):
for lyr in mapping.ListLayers(mxd, "*", df):
if " " in lyr.name:
lyr.name = lyr.name.replace(" ", "")
for lyr in mapping.ListLayers(mxd, "*", df):
if "," in lyr.name:
lyr.name = lyr.name.replace(",", "")
mxd.save()
del mxd
... View more
08-23-2011
06:24 AM
|
0
|
0
|
1038
|
|
POST
|
Here is an example on how to do this: import os
workspace = r"C:\temp\python"
for (path, dirs, files) in os.walk(workspace):
for file in files:
if ".mxd" in file.lower():
if "," in file:
str = os.path.join(path, file)
new = str.replace(",", "")
os.rename(str, new)
elif " " in file:
str = os.path.join(path, file)
new = str.replace(" ", "")
os.rename(str, new) You will just need to update 'workspace = r"C:\temp\python"' with the directory that contains the MXDs. The example above will also loop through all sub directories.
... View more
08-22-2011
06:32 AM
|
0
|
0
|
1038
|
|
POST
|
I would recommend migrating from Image Server to Mosaic Datasets. You can very easily access Mosaic Datasets using arcpy. Note: ArcGIS 10 is the last release of Image Server. http://resources.esri.nl/downloads/ArcGIS_10_Deprecation_Plan.pdf ArcGIS 10.0 is the last release of the stand-alone ArcGIS Image Server product. This product has been replaced with the ArcGIS Server Image Extension. Any existing users of the stand-alone Image Server product or technology (using ISDef files), should plan their migration to the ArcGIS Server Image extension. Existing ArcGIS Image Server users should migrate from using ISDef file to using the Mosaic Datasets, a new data model in the geodatabase for managing collections of imagery and rasters. Mosaic Datasets are created and edited with ArcGIS Desktop (ArcEditor and ArcInfo) and published using ArcGIS Server with the Image Extension. Existing ISDef files can be added to Mosaic Datasets for conversion.
... View more
08-17-2011
06:09 AM
|
0
|
0
|
943
|
|
POST
|
hzhu is correct. You are specifying a shapefile rather than a feature class. Change: inFeature = "soilmu_in.shp" to inFeature = "soilmu_in"
... View more
08-17-2011
06:02 AM
|
0
|
0
|
3618
|
|
POST
|
You can use the arcpy.mapping.ListLayers function to access the dataSource property. Next you can append this to a list, convert the layers to the new geodatabase, and update the MXD. Ex: import arcpy
from arcpy import env
from arcpy import mapping
env.workspace = r"C:\temp\python"
list = []
mxd = mapping.MapDocument(r"C:\temp\python\test.mxd")
for df in mapping.ListDataFrames(mxd, "*"):
for layers in mapping.ListLayers(mxd, "*", df):
list.append(layers.dataSource)
for n in list:
arcpy.FeatureClassToGeodatabase_conversion(n, r"C:\temp\Test2.gdb")
mxd.replaceWorkspaces(r"C:\Temp\Python", "SHAPEFILE_WORKSPACE", r"C:\Temp\test2.gdb", "FILEGDB_WORKSPACE")
mxd.findAndReplaceWorkspacePaths(r"C:\temp\python\test.gdb", r"C:\temp\test2.gdb")
# mxd.replaceWorkspaces(r"C:\temp\python\test.gdb", "FILEGDB_WORKSPACE", r"C:\temp\python\test.gdb", "FILEGDB_WORKSPACE")
mxd.saveACopy(r"C:\Temp\Project2.mxd")
print "Save Successful"
... View more
08-17-2011
05:59 AM
|
0
|
0
|
666
|
|
POST
|
If all your shapefiles reside in one folder, and your feature classes within a single geodatabase you can use the 'arcpy.ListFeatureClasses' function to list all shapefiles and feature classes then append them to a list. Next, you can use the 'arcpy.FeatureClassToGeodatabase_conversion' function to convert the shapefiles/feature classes to a new geodatabase. Finally, you can run the 'replaceWorkspaces' and 'replaceDataSource' methods to remap the datasources and save it as a new MXD. Ex: import arcpy, os
from arcpy import env
from arcpy import mapping
folder = r"C:\temp\python"
env.workspace = folder
fcList = []
lstFCs = arcpy.ListFeatureClasses("*")
for fc in lstFCs:
fcList.append(os.path.join(folder + "\\" + fc))
database = r"C:\temp\python\test.gdb"
env.workspace = database
lstFCs = arcpy.ListFeatureClasses("*")
for fc in lstFCs:
fcList.append(database + "\\" + fc)
for fc in fcList:
print fc
arcpy.FeatureClassToGeodatabase_conversion(fc, r"C:\temp\test2.gdb")
print "Successfully converted"
mxd = mapping.MapDocument(r"C:\temp\python\test.mxd")
mxd.replaceWorkspaces(r"C:\Temp\Python", "SHAPEFILE_WORKSPACE", r"C:\Temp\test2.gdb", "FILEGDB_WORKSPACE")
mxd.findAndReplaceWorkspacePaths(r"C:\temp\python\test.gdb", r"C:\temp\test2.gdb")
mxd.saveACopy(r"C:\Temp\Project2.mxd")
print "Save Successful" If your data resides in multiple folders/geodatabase I would recommend looking into the os.walk function.
... View more
08-15-2011
11:54 AM
|
0
|
0
|
666
|
|
POST
|
You will need to specify which files to search for in the 'arcpy.ListFiles' function. Also, you will need to specify the Sheet # when executing the 'arcpy.TabletoTable_conversion' tool when working with Excel files. Ex: lstFiles = arcpy.ListFiles("*.xls")
for file in lstFiles:
arcpy.TableToTable_conversion(file + "\\" + "Sheet1$", outpath, "test.dbf")
... View more
08-12-2011
11:18 AM
|
0
|
0
|
1616
|
|
POST
|
You can run any tool in batch. Simply right-click on the 'Clip' tool in ArcToolbox > Data Management Tools > Raster Processing. You will see the option 'Batch'. Right-click under 'Input Raster' and choose 'Browse'. You can select multiple rasters here.
... View more
08-11-2011
05:06 AM
|
0
|
0
|
366
|
|
POST
|
Hi Amy, I looked into updating the polylines using python, but this may not be possible. A polyline object's properties are all read-only. Therefore I could not find a way to write new coordinate values to the end points of the mains. Something you can do to possibly help you is to write some code to obtain the OBJECTIDs of the mains that need to be moved. This will provide you a list with the feature's end points that are not snapped to a manhole. Ex: import arcpy
from arcpy import env
env.overwriteOutput = True
env.workspace = r"C:\Temp\Python\test.gdb"
fc = "swManhole"
fc2 = "swGravityMain"
pnt = arcpy.Point()
# Move Manholes to GPS location
rows = arcpy.UpdateCursor(fc)
for row in rows:
pnt.X = row.POINT_X
pnt.Y = row.POINT_Y
row.shape = pnt
rows.updateRow(row)
del row, rows
# Convert Main endpoints to points feature class
arcpy.FeatureVerticesToPoints_management(fc2, "Main_EndPts", "END")
# Find all Main endpoints within 5 feet of manholes
arcpy.Near_analysis("Main_EndPts", fc, "5")
# Create a layer of all Main endpoints within 5 feet of manholes
lyr = arcpy.MakeFeatureLayer_management("Main_EndPts", "Main_EndPts_Lyr", "NEAR_DIST > 0")
list = []
# Append X & Y values of Main endpoints to list
rows = arcpy.SearchCursor(lyr)
for row in rows:
list.append(float(row.shape.centroid.X) + float(row.shape.centroid.Y))
del row, rows
OBJECTIDs = []
# Find OBJECTIDs of the Mains that need to be moved
rows = arcpy.SearchCursor(fc2)
for row in rows:
geom = row.shape
XY = float(geom.lastPoint.X) + float(geom.lastPoint.Y)
if XY in list:
OBJECTIDs.append(row.OBJECTID)
del row, rows
arcpy.Delete_management("Main_EndPts")
print OBJECTIDs
... View more
08-11-2011
04:05 AM
|
0
|
0
|
4691
|
|
POST
|
Take a look at the example script below. Also, be sure to execute the make a feature layer before executing the 'arcpy.SelectbyAttribute_management' function. where_clause = ("Status = 'U'")
arcpy.MakeFeatureLayer_management("Crimes", "Crimes_Lyr")
arcpy.SelectLayerByAttribute_management("Crimes_Lyr", "NEW_SELECTION", where_clause)
print arcpy.GetCount_management("Crimes_Lyr") You can also use the 'arcpy.FieldDelimiters' function to get the correct syntax of the field:
fld = arcpy.AddFieldDelimiters("Crimes", "Status")
where_clause = (fld + " = 'U'")
arcpy.MakeFeatureLayer_management("Crimes", "Crimes_Lyr")
arcpy.SelectLayerByAttribute_management("Crimes_Lyr", "NEW_SELECTION", where_clause)
print arcpy.GetCount_management("Crimes_Lyr")
... View more
08-10-2011
10:01 AM
|
0
|
0
|
2479
|
|
POST
|
What is you initial coordinate system, and which coordinate system are you attempting to re-project to?
... View more
08-09-2011
12:09 PM
|
0
|
0
|
1760
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 3 weeks ago | |
| 1 | 12-01-2025 05:58 AM | |
| 1 | 11-21-2025 03:55 AM | |
| 1 | 11-14-2025 09:01 AM | |
| 1 | 11-13-2025 12:28 PM |
| Online Status |
Online
|
| Date Last Visited |
5 hours ago
|