|
POST
|
Jake, 1. while y < 7: === this loop creates a shp file with the extents of each dataframe? I guess I can use the same loop to also add in the scale and name of the dataframe into the shp file? 2. for fc in lstFCs: ==== take all the "polygon_extent_*.shp" files and merge them into extents.shp? 3. for item in list: ==== delete the "polygon_extent_*.shp"? The script is intended to create feature classes within the Extents.gdb, which you will need to create before running the script. This is why you were receiving errors referencing shapefiles. I believe since the file geodatabase did not exist, the script attempted to create a shapefile. The 'env.workspace' is set to the Extents.gdb, so all output should be written here. 1. The while loop with iterate through each mxd starting with the first dataframe , where x = 0. X will then increase by 1 and iterate through each mxd with the next dataframe[1]. If the dataframe does not exist, for example the mxd does not contain dataframe[4], the script will execute the 'except' and pass the index error. Yes, you could use the same loop to add the scale and dataframe name to the feature class, but this will take some more coding. 2. This will take all 'polygon_extent' feature classes and merge them into one feature class. 3. After the 'polygon_extent' feature classes are merged into one, it will delete the individual 'polygon_extent' feature classes. Hope this helps!
... View more
05-11-2011
02:44 AM
|
0
|
0
|
2348
|
|
POST
|
Thanks for sending your code and MXDs. I didn't take into consideration that you had multiple dataframes within your MXDs. I've updated the code to work with this. There were a few small syntax errors within the code you sent. For example: env.workspace = path + 'extents.gdb' There is a '\' missing. Should be: env.workspace = path + '\extents.gdb' Another error: for mxd in mxdList:
mxd = mapping.MapDocument(mxd)
print mxd # Printing status for error checking
dataframe = mapping.ListDataFrames(mxd2, "*")[0] Need to change the second 'mxd' to 'mxd2': for mxd in mxdList:
mxd2 = mapping.MapDocument(mxd)
print mxd # Printing status for error checking
dataframe = mapping.ListDataFrames(mxd2, "*")[0] I also removed the 'Tempfile' from the code. This isn't really needed, but the code may still work with it added (did not test though). Below is the updated code. This code will also iterate through all dataframes in each MXD: import arcpy, glob, os
from arcpy import env
from arcpy import mapping
env.overwriteOutput = True
path = os.getcwd() # Script in same directory as files being processed
mxdList = glob.glob(path + "\*.mxd")
env.workspace = path + '\extents.gdb' # Directory as files being processed
print env.workspace
x = 0
y = 1
z = 1
while y < 7:
for mxd in mxdList:
mxd2 = mapping.MapDocument(mxd)
try:
dataframe = mapping.ListDataFrames(mxd2, "*")
frameExtent = dataframe.extent
XMAX = frameExtent.XMax
XMIN = frameExtent.XMin
YMAX = frameExtent.YMax
YMIN = frameExtent.YMin
pnt1 = arcpy.Point(XMIN, YMIN)
pnt2 = arcpy.Point(XMIN, YMAX)
pnt3 = arcpy.Point(XMAX, YMAX)
pnt4 = arcpy.Point(XMAX, YMIN)
array = arcpy.Array()
array.add(pnt1)
array.add(pnt2)
array.add(pnt3)
array.add(pnt4)
array.add(pnt1)
polygon = arcpy.Polygon(array)
arcpy.CopyFeatures_management(polygon, "Polygon_Extent" + "_" + str(z))
z = z + 1
except IndexError:
pass
x = x + 1
y = y + 1
list = []
lstFCs = arcpy.ListFeatureClasses("Polygon_Extent*")
for fc in lstFCs:
list.append(fc)
arcpy.Merge_management(list, "Extent")
for item in list:
arcpy.Delete_management(item)
For "while > 7:", the number can be any value that is larger than the max amount of dataframes in any individual MXD. For example, if you had an MXD that has 10 dataframes you should increase this number to 10 (dataframe indexing begins at 0).
... View more
05-10-2011
08:29 AM
|
0
|
0
|
2348
|
|
POST
|
To set the environment workspace, you will use arcpy.env.workspace. Ex: arcpy.env.workspace = r"C:\data\Philadelphia.gdb" It will still help to post all of your code. I can check to see if there are any errors with the changes you made.
... View more
05-09-2011
02:22 AM
|
0
|
0
|
2528
|
|
POST
|
Here is some sample code if interested: list = []
# Specify feature class whose features you want to rotate
# Append to list to find the Max OBJECTID/FID
lstFCs = arcpy.ListFeatureClasses("Parcels")
for fc in lstFCs:
rows = arcpy.SearchCursor(fc)
for row in rows:
list.append(row.OBJECTID)
del row, rows
maxOID = list[-1]
x = 1
y = 1
# Loop through each feature, convert to a feature layer, then to raster, rotate raster, convert back to polygon feature class
while y <= maxOID:
for fc in lstFCs:
feat_lay = arcpy.MakeFeatureLayer_management(fc, fc + str(x), "OBJECTID = " + str(x))
ras_lay = arcpy.PolygonToRaster_conversion(feat_lay, "OBJECTID", fc + str(x) + "_ras") # Can improve processing time by specifying a larger cell size
feat_lay2 = arcpy.Rotate_management(ras_lay, "ras_rotate" + str(x), 45)
arcpy.RasterToPolygon_conversion(feat_lay2, fc + "_rotate_" + str(x))
y = y + 1
x = x + 1
# Print extent of rotated feature classes
lstFCs2 = arcpy.ListFeatureClasses("*rotate*")
for fc2 in lstFCs2:
rows2 = arcpy.SearchCursor(fc2)
for row2 in rows2:
geom = row2.Shape
Extent = geom.extent
print Extent
del row2, rows2
# Deleted rasters
lstRasters = arcpy.ListRasters("*ras*")
for raster in lstRasters:
arcpy.Delete_management(raster)
... View more
05-06-2011
12:22 PM
|
0
|
0
|
2933
|
|
POST
|
There is a Rotate GP tool, but this is only for raster datasets. You could create a script to convert the features to a raster dataset (Polygon to Raster), rotate the raster datasets (Rotate), then convert the rasters back to a feature class (Raster to Polygon). You will then be able to retrieve the new extent of the rotated feature.
... View more
05-06-2011
05:08 AM
|
0
|
0
|
2933
|
|
POST
|
Do you have your env.workspace set to a File Geodatabase? Can you post the entire code you are using?
... View more
05-06-2011
02:48 AM
|
0
|
0
|
2528
|
|
POST
|
You can also add 'arcpy.env.overwriteOutput = True' at the start of your code. This will overwrite the feature layer.
... View more
05-05-2011
08:22 AM
|
0
|
0
|
1453
|
|
POST
|
Here is some sample code that I was able to get working. You will need to create an array and add the XMAX, XMIN, etc to the array to create the polygon feature. Then you can create a feature class/shapefile from this array. I had trouble getting the Append tool to work with the array feature so I created a feature class for each extent, merged them together, and then deleted the original extent feature classes. import arcpy, glob, os
from arcpy import env
from arcpy import mapping
env.overwriteOutput = True
path = r"C:\temp"
mxdList = glob.glob(path + "\*.mxd")
env.workspace = r"C:\temp\Test.gdb"
y = 1
for mxd in mxdList:
mxd2 = mapping.MapDocument(mxd)
dataframe = mapping.ListDataFrames(mxd2, "*")[0]
frameExtent = dataframe.extent
XMAX = frameExtent.XMax
XMIN = frameExtent.XMin
YMAX = frameExtent.YMax
YMIN = frameExtent.YMin
pnt1 = arcpy.Point(XMIN, YMIN)
pnt2 = arcpy.Point(XMIN, YMAX)
pnt3 = arcpy.Point(XMAX, YMAX)
pnt4 = arcpy.Point(XMAX, YMIN)
array = arcpy.Array()
array.add(pnt1)
array.add(pnt2)
array.add(pnt3)
array.add(pnt4)
array.add(pnt1)
polygon = arcpy.Polygon(array)
arcpy.CopyFeatures_management(polygon, "Polygon_Extent" + "_" + str(y))
y = y + 1
list = []
lstFCs = arcpy.ListFeatureClasses("Polygon_Extent*")
for fc in lstFCs:
list.append(fc)
arcpy.Merge_management(list, "Extent")
for item in list:
arcpy.Delete_management(item)
... View more
05-05-2011
07:10 AM
|
0
|
0
|
2528
|
|
POST
|
You can register a feature class via command line using the 'sdetable -o alter_reg' command with the '-V MULTI' option. Ex:
sdetable -o alter_reg -t building -V MULTI -i sde:sqlserver:esri -D vector -u vector -p **** You could also register a feature class as versioned using python. Ex: import arcpy
from arcpy import env
env.workspace = r"Database Connections\SQL.sde"
fc = "Parcels"
arcpy.RegisterAsVersioned_management(fc)
... View more
05-04-2011
11:20 AM
|
0
|
0
|
1137
|
|
POST
|
Here is an example on how you can sum the Area field into a new field (SUM_Area). From there you can calculate the percentage. list = []
lstRasters = arcpy.ListRasters("*")
for raster in lstRasters:
rows = arcpy.SearchCursor(raster)
for row in rows:
list.append(row.Area)
S = sum(list)
arcpy.CalculateField_management(raster, "SUM_Area", S)
list = []
del row, rows
... View more
05-04-2011
04:40 AM
|
0
|
0
|
1124
|
|
POST
|
The code above is attempting to multiply two strings together. I believe that is why you are receiving the error. When multiplying rasters, try using the spatial analyst Times function. This will successfully multiply two rasters together.
... View more
05-04-2011
03:56 AM
|
0
|
0
|
1894
|
|
POST
|
After running the Build Raster Attribute Table tool, the attribute table of the raster will contain a field called Value representing the pixel value, and a field called Count representing how many pixels of that Value. You can then use the following code to write these value to an output text file: lstRasters = arcpy.ListRasters("*")
logfile = open(r"c:\temp\pixels.txt", "w")
for raster in lstRasters:
rows = arcpy.SearchCursor(raster)
for row in rows:
logfile.write("Value of " + str(row.value) + " = " + str(row.count) + " pixels" + "\n")
logfile.close()
... View more
05-03-2011
12:48 PM
|
0
|
0
|
842
|
|
POST
|
I ran a test with this scenario. I created a two-way replica from one sql server database to another. I added the child geodatabase feature class to ArcMap, added a join, updated a field based off of the join, did not remove the join, and then executed the 'Export Data Changes Message' tool from the Distributed Geodatabase toolbar. I was able to successfully create the XML file and import this into parent geodatabase. So, the join/relate should not be affecting the replica. What is the error message you are receiving?
... View more
05-03-2011
06:30 AM
|
0
|
0
|
579
|
|
POST
|
What service pack are you running for SQL Server 2005? You can run the following query to find out: SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
... View more
05-03-2011
05:58 AM
|
0
|
0
|
3421
|
|
POST
|
Try building pyramids using a direct connection. You will just need to replace '-i' with 'sde:sqlserver:<server name>. Also, make sure you are attempting to build pyramids with the raster dataset owner (GIS_ADMIN). I would also specify '-1' for the -L option. This will build all necessary pyramid levels. Ex: sderaster -o pyramid -l HRES_COLOR_MRSID_MOSAIC_2010,RASTER -v 1 -L -1 -I bilinear -D RASTER -i sde:sqlserver:<server name> -u GIS_ADMIN -p *****
... View more
05-02-2011
11:52 AM
|
0
|
0
|
3421
|
| 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 |
Friday
|