POST
|
Thanks, Ruth! The 'replaceDataSource' method was exactly what I needed. I was able to get this working with the following code:
import arcpy
from arcpy import env
from arcpy import mapping
env.workspace = workspace = arcpy.GetParameterAsText(0)
env.overwriteOutput = True
mxdList = arcpy.ListFiles("*.mxd")
for mxd in mxdList:
mxd = workspace + "\\" + mxd
print mxd + " is being processed"
mxd = mapping.MapDocument(mxd)
for df in mapping.ListDataFrames(mxd, "*"):
for lyr in mapping.ListLayers(mxd, "*", df):
lyr.replaceDataSource(arcpy.GetParameterAsText(1), "SDE_WORKSPACE", "")
print "Successfully updated data sources"
mxd.save()
del mxd
... View more
07-19-2011
11:17 AM
|
2
|
4
|
919
|
POST
|
You can use the 'Create File Geodatabase' or 'Create Personal Geodatabase' tool to create a 9.3 geodatabase and then copy the data from your 10 geodatabase to the 9.3 geodatabase using ArcGIS 10.
... View more
07-18-2011
11:59 AM
|
0
|
0
|
168
|
POST
|
It looks you are missing a ',' between OBJECTID and SDE for the -C option. Here is an example on registering a table: SQL> CREATE TABLE building (OBJECTID INTEGER, shape SDE.ST_GEOMETRY);
SQL> INSERT INTO building VALUES (1, SDE.ST_Polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 2));
SQL> INSERT INTO building VALUES (2, SDE.ST_Polygon ('polygon ((20 0, 30 20, 40 0, 20 0))', 2));
SQL> INSERT INTO building VALUES (3, SDE.ST_Polygon ('polygon ((20 30, 25 35, 30 30, 20 30))', 2));
SQL> create index bf_indx on building(shape) indextype is SDE.ST_spatial_index parameters = ('SDE.ST_grids=1,0,0 SDE.ST_srid=2');
$ sdelayer -o regiSDE.STer -l building,shape -e nac+ -C OBJECTID,SDE -P HIGH -t SDE.ST_GEOMETRY -i 5151 -u vector -p vector
... View more
07-18-2011
11:53 AM
|
0
|
0
|
492
|
POST
|
Try removing the 417th file and then re-execute the script to see if it works. The file may be corrupted.
... View more
07-18-2011
11:30 AM
|
0
|
0
|
522
|
POST
|
Is it possible to change the data source of an MXD to another SDE geodatabase? I've tried this, but have only been able to get this to work when switching versions within the same SDE geodatabase. Ex: import arcpy
from arcpy import env
env.workspace = workspace = r"C:\temp\python"
env.overwriteOutput = True
mxdList = arcpy.ListFiles("*.mxd")
for mxd in mxdList:
mxd2 = workspace + "\\" + mxd
mapdoc = arcpy.mapping.MapDocument(mxd2)
mapdoc.findAndReplaceWorkspacePaths(r"C:\TEMP\Python\VECTOR_Default.sde", r"C:\TEMP\Python\VECTOR_QAQC.sde")
mapdoc.save()
del mapdoc The above code works as I am switching from one version (SDE.Default) to another version (SDE.QAQC) within the same VECTOR geodatabase. When I try to switch to another SDE geodatabase that contains the same feature class (same owner and feature class name, just different database), it does not work. Ex: import arcpy
from arcpy import env
env.workspace = workspace = r"C:\temp\python"
env.overwriteOutput = True
mxdList = arcpy.ListFiles("*.mxd")
for mxd in mxdList:
mxd2 = workspace + "\\" + mxd
mapdoc = arcpy.mapping.MapDocument(mxd2)
mapdoc.findAndReplaceWorkspacePaths(r"C:\TEMP\Python\VECTOR_Default.sde", r"C:\TEMP\Python\RASTER_Default.sde")
mapdoc.save()
del mapdoc Thanks for any suggestions!
... View more
07-18-2011
11:14 AM
|
1
|
6
|
4043
|
POST
|
Below is an example on how you can do this using the Field Calculator. Be sure to check 'Python' at the top and 'Show Codeblock'. Under 'Pre-logic Script Code' enter the following: def update():
import arcpy
list = []
rows = arcpy.SearchCursor(r"C:\data\Parcels")
for row in rows:
list.append(row.AREA)
S = sum(list)
del row, rows
rows = arcpy.UpdateCursor(r"C:\data\Parcels")
for row in rows:
row.AREA2 = S
val = row.AREA2
del row, rows
return val Then, under the second block enter: update()
... View more
07-08-2011
05:35 AM
|
0
|
0
|
381
|
POST
|
Below is an example on how to do this. The code adds all the shapefiles first two characters to a list, then removes the duplicates. It will then merge the related shapefiles together to one shapefile. lstFCs = arcpy.ListFeatureClasses("*")
list1 = []
# Append first two characters of each shapefile to list
for fc in lstFCs:
list1.append(fc[0:2])
# Remove duplicates from list
list1 = dict.fromkeys(list1)
list1 = list1.keys()
# Merge feature classes
for n in list1:
m = str(n) + "*"
lstFCs = arcpy.ListFeatureClasses(m)
arcpy.Merge_management(lstFCs, n + "_merge")
... View more
07-07-2011
04:08 AM
|
0
|
0
|
522
|
POST
|
In order to update the symbology for layers within MXD using another MXD as the source, you will need to use the 'arcpy.mapping.ListLayers' function rather the the 'arcpy.mapping.Layer'. Here is an example below on how you can accomplish this:
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\temp\Final_Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
lstLayers = arcpy.mapping.ListLayers(mxd, "Rivers*", df)
mxd2 = arcpy.mapping.MapDocument(r"C:\temp\Source.mxd")
df2 = arcpy.mapping.ListDataFrames(mxd2, "*")[0]
for layer in lstLayers:
updateLayer = layer
sourceLayer = arcpy.mapping.ListLayers(mxd2, "River", df2)[0]
arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True)
mxd.save()
print "Updated symbology successfully"
del mxd You can copy/paste the syntax above to update the Roads and Building layers as well.
... View more
06-27-2011
08:19 AM
|
0
|
0
|
332
|
POST
|
If you have an ArcEditor license for ArcGIS 10 you can use the 'arcpy.FlipLine_edit' function to reverse the direction of your polyline data.
... View more
06-27-2011
06:52 AM
|
0
|
0
|
417
|
POST
|
I would recommend using the arcpy.AddFieldDelimiters function to select the field your using. That way you can be sure you have the expression correct. Ex: fc = "Roads"
Segment_ID = arcpy.AddFieldDelimiters(fc, "Segment_ID")
Expression = "Segment_ID = 'C1'" Give that a go and see if you receive the correct results.
... View more
06-23-2011
09:40 AM
|
0
|
0
|
429
|
POST
|
The append should work inside or outside an edit session. If you perform the append outside of an edit session, make sure the 'Connection Details' within the connection properties of the geodatabase are set to the version you wish to update.
... View more
06-23-2011
03:48 AM
|
0
|
0
|
248
|
POST
|
You can use the arcpy.Append_management command to do this.
... View more
06-23-2011
03:25 AM
|
0
|
0
|
756
|
POST
|
Can you upload your model as well? This will help a lot. Thanks!
... View more
06-17-2011
12:06 PM
|
0
|
0
|
2399
|
POST
|
I'm a little confused on your local variables: # Local variables:
Test = Expression
Test_UnsplitLine = Test
ROUTE_FINAL = Test_UnsplitLine
ROUTE_FINAL__2_ = ROUTE_FINAL
Route_Real_OUTPUT_gdb = "G:\\40\\Scratch\\Real_OUTPUT.gdb" It appears you have variables set to other variables. Could you explain what you would like the code to do and I can figure out the correct syntax? Thanks!
... View more
06-15-2011
12:27 PM
|
0
|
0
|
2399
|
POST
|
For your local variables you have: Test = Expression Test_UnsplitLine = Test The 'Unsplit Line' tool will be looking for feature classes and not variables. Try changing the line to: arcpy.UnsplitLine_management("Test", "Test_UnsplitLine", "Segment_ID", "") The quotes will indicate that 'Test' and 'Test_UnsplitLine" are feature classes rather than variables.
... View more
06-13-2011
07:40 AM
|
0
|
0
|
2399
|
Title | Kudos | Posted |
---|---|---|
1 | 17 hours ago | |
1 | Tuesday | |
1 | a week ago | |
1 | a week ago | |
3 | 12-15-2020 04:55 PM |
Online Status |
Offline
|
Date Last Visited |
13 hours ago
|