|
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
|
1492
|
|
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
|
1201
|
|
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
|
4500
|
|
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
|
1052
|
|
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
|
1052
|
|
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
|
1972
|
|
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
|
471
|
|
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
|
6228
|
|
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
|
3273
|
|
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
|
2394
|
|
POST
|
Make sure you have the correct data types setup for the parameters.
... View more
08-09-2011
07:14 AM
|
0
|
0
|
1696
|
|
POST
|
Before testing this, I would recommend making a copy of your feature dataset as a backup. Here is some sample code that will move your point features based on the GPS fields: import arcpy
from arcpy import env
env.workspace = "C:/Temp/Python/test.gdb"
fc = "Parker_R6_Manhole_1"
pnt = arcpy.Point()
rows = arcpy.UpdateCursor(fc)
for row in rows:
pnt.X = row.GPS_X
pnt.Y = row.GPS_Y
row.shape = pnt
rows.updateRow(row)
del row, rows The tricky part is having the mains move with the manholes. I was able to get this to work by specifying a larger cluster tolerance and setting the rank for the manhole feature class to 1, and the rank for the mains feature class to 2 within the topology. If the distance the points moved is less than the cluster tolerance, the mains will snap to the updated manholes upon validation.
... View more
08-09-2011
06:45 AM
|
0
|
0
|
6228
|
|
POST
|
I believe the problem is with the 'arcpy.ListRasters' function. You will want to specify "TIF" instead of "TIFF". Also, I believe you will want to specify 'os.path.join(OutDir, outname)' within the 'arcpy.Clip_management' function. Ex: rasters = arcpy.ListRasters("*", "TIF")
for raster in rasters:
print raster
outname = raster[:-4] + "_clip.tif"
arcpy.Compression= "LZW"
arcpy.Clip_management(raster, "", os.path.join(outDIR, outname), clipFC, "", "ClippingGeometry")
... View more
08-09-2011
04:01 AM
|
0
|
0
|
1696
|
|
POST
|
Is your data frame coordinate system the same as the raster coordinate system? Also, here is a helpful KB article.
... View more
08-08-2011
09:01 AM
|
0
|
0
|
1384
|
| 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 |
Thursday
|