|
POST
|
Your code does appear to work, however teh deletion isn't working
>>> map = arcpy.mapping.MapDocument('C:\test.mxd')
>>> lyr_list = arcpy.mapping.ListLayers(map)
>>> for lyr in lyr_list:
print lyr
# result of the above displays a list of layers correctly
# next to delete the layers in question
>>> for lyr in lyr_list:
if 'Base_Data' in lyr.name:
arcpy.Delete_management(lyr)
<Result 'true'>
<Result 'true'>
<Result 'true'>
<Result 'true'>
however nothing was actually deleted
... View more
08-22-2012
11:54 AM
|
0
|
0
|
2980
|
|
POST
|
If your base data are always in a group layer that has Base_Data in the name somehow then you can query a layer to determine if its a group layer, if it is, then you can inspect its name to see if it has the string 'Base_Data' in it. Unless you need to process this dataframe by data frame I think you can skip the work with ListDataFrames. something like this might work (concept only! hasn't been tested): map = arcpy.mapping.MapDocument('some map name')
lyr_list = arcpy.mapping.ListLayers(map) #leaving out the dataframe argument returns a list of all layers in all dataframes
for lyr in lyr_list:
if lyr.isGroupLayer:
if 'Base_Data' in lyr.name:
continue
else:
... your code to copy to new mxd... you can also examine other attributes of a Layer object such as the name and longname. The name is the name of a layer as it appears in arcmap, the long name will have a reference to a group layer (like base_data\roads where roads is the layer and base_data is the group). You can always check to see if the name and long name are equal, if so, move them, if not, then check to see if the long name contains Base_Data or other string you are interested in filtering with. Thanks Chris, here's what I tried as a test from shell, it "appeared" to work but didn't actually delete anything
mxd = arcpy.mapping.MapDocument("C:\tester.mxd")
lyr = arcpy.mapping.ListLayers(mxd,"14*")[0]
for i in lyr:
arcpy.Delete_management(lyr)
mxd.save()
The delete command returned <Result 'true'> after every iteration I'll try your code next
... View more
08-22-2012
11:10 AM
|
0
|
0
|
2980
|
|
POST
|
The structure of my mxd is a single data frame, which has 14 layer groups, several layers within each group. What I'd like to do is delete the 14th layer group "Base_Data" on a target mxd, I'm having no luck accomplishing this.
... View more
08-22-2012
09:21 AM
|
0
|
0
|
2980
|
|
POST
|
I have a script that moves a group layer from one mxd to others, the layer is saved from the current mxd then written to a list of other mxd???s, the group layer is Base_Data. My script is working well but I???d like to clean it up a bit by first removing any existing Base_Data layer groups in the target mxd before writing the layer source. As it is, if I run the script 3 time I get 3 copies of Base_Data in the target. I???m trying to use the following but am seeing unexpected results. Using the ListDataFrames function I assumed I???d get back a list of the DataFrames in the mxd, such as ???New Data Frame???
df = arcpy.mapping.ListDataFrames(mxd,"")[0]
instead when I iterate the list df I get a list of all the layers.
For i in df:
Print i
So when I try to list the layers to select the Base_Data I just get a list of layers the first group layer
basedata = arcpy.mapping.ListLayers(mxd)[0]
for i in basedata:
arcpy.AddMessage(i)
All I???m really trying to accomplish it to detete any layers in the target mxd that contain ???Base_Data??? Thanks
... View more
08-22-2012
08:41 AM
|
0
|
11
|
4092
|
|
POST
|
You can not "setup" DDP using arcpy. A map document must be authored and saved with DDP enabled (and set up). Once a map document is DDP enabled, then arcpy.mapping can be used to automate whichever pages you need. Jeff Thanks Jeff, that's what I'd expected but hoped I was wrong.
... View more
08-20-2012
09:56 AM
|
0
|
0
|
910
|
|
POST
|
Hi, I'm just starting to look at the mapping module and DDP. I'd like to automate as much of ddp process as possible to make it easier for folks to use this functionality. I'm not seeing many of the options in the help documentation to set ddp values in python. The first screen of Index Layer, Layer, name Field, Sort order. Then the options of map extent and scale. Maybe I'm just looking in the wrong place? If you could point me in the right direction I'd appreciate it Thanks
... View more
08-17-2012
02:29 PM
|
0
|
2
|
1154
|
|
POST
|
There are some tools that need recompiling for 10.1, the GPX Importer, Line Buffer tool etc. These are in the works.
... View more
08-08-2012
07:52 AM
|
0
|
0
|
1040
|
|
POST
|
A very often asked question and one that can take a little digging to answer. Here's a couple of good resources for California data which you can download via ftp then store and use offline for a SAR op. Download these PRIOR to needing the data, so you are familiar with the data you have and not waiting for lengthy downloads when time is of the essence. Spend some time poking around these sites, you'll find lots of good info. atlas.ca.gov Lot;s of good data here CA 24k USGS basemaps /pub/drg Transportation and travel routes, water ways, imagery, NED, landcover etc. /pub/casil /pub/casil/imageryBaseMapsLandCover nhdftp.usgs.gov /DataSets /hydrography There's many more sources for data, these should provide you enough to get started. tip: When displaying Tiff or SID files in ArcMap, change the display properties from Nearest Neighbor to Bilinear Interpolation for a sharper image.
... View more
08-08-2012
07:49 AM
|
0
|
2
|
2296
|
|
POST
|
Thanks that was helpful. The odd behavior in reading strings equal to or longer that 256 is that the entire script fails, not just the one long string. For a field named Description and pulling in 10 rows of data, if just one value is too large all 10 rows fail on that field. You'd think that just the one record would fail not all.
... View more
08-07-2012
11:46 AM
|
0
|
0
|
1548
|
|
POST
|
Hi, I'm reading in text values from xls and csv files, I'm using row.getValue('Field_Name") to read the values in. This method is working well with short sentences but fails once it hits 256 chars. Is there another method that allows more characters to be pulled in? Thanks
... View more
08-06-2012
11:16 AM
|
0
|
3
|
1774
|
|
POST
|
Sometimes it just takes a train ride to rethink the problem. It was actually the arcpy.addmessage that was teh issue, not the query. Sorry to trouble you all Jon
... View more
08-02-2012
08:48 AM
|
0
|
0
|
632
|
|
POST
|
Sorry, yet another frustrating error I'm encountering. I'm reading data from an Excel sheet, first column is xCel_Assignment_Number. Then will be matching the value from xCel_Assignment_Number to FC Assignments, field Assignment_Number. Then updating the information in the FC with data from the spreadsheet. I'm again having trouble with the query and receive the error cannot concatenate 'str' and 'Cursor' objects. Assignment_Number is type short Integer. Here's the code I'm using. rows = arcpy.SearchCursor(xCel) row = rows.next() arcpy.AddMessage("Got Rows" + str(rows) +" from excel") while row: arcpy.AddMessage("Start While Loop processing excel sheet") # Excel Sheet Values eAssignment = row.getValue("xCel_Assignment_Number") eDescription = row.getValue("xCel_Description") eTeam = row.getValue("xCel_Team_Name") fc1="Assignments" vAssignment = '"Assignment_Number"' + "='" + str(int(eAssignment)) + "'" arcpy.AddMessage(eAssignment) iAssignment = arcpy.SearchCursor(fc1,eAssignment) arcpy.AddMessage("iAssignment - " + iAssignment) Thanks in advance for your help
... View more
08-02-2012
06:45 AM
|
0
|
1
|
742
|
|
POST
|
This appears to be working, if I select the worksheet first Assignments$ import arcpy from arcpy import env arcpy.env.overwriteOutput = True xcel = arcpy.GetParameterAsText(0) arcpy.AddMessage("Got Sheet") rows = arcpy.SearchCursor(xcel) row = rows.next() arcpy.AddMessage("Got Rows") while row: arcpy.AddMessage("Start While") # Loop through rowns and pull incident name from Incident_Name field arcpy.AddMessage("Getting Assignment") Assignment = row.getValue("Assignment_Number") Description = row.getValue("Description") arcpy.AddMessage(Assignment) arcpy.AddMessage(Description) arcpy.AddMessage("Received Assignment") row = rows.next() just getting started, thanks
... View more
08-01-2012
12:54 PM
|
0
|
0
|
1621
|
|
POST
|
Hi, I'm reading in an Excel doc (xlsx) with arcpy and want to use row.getValue() to pull in the information by row and cell. I'm looking to use a SearchCursor() to access the excel file. My Excel doc is Assignments.xlsx and the first worksheet is named Assignment, which would be referenced in Arc as Assignment$ I'm not sure how to access/read data in the cells? Thanks
... View more
08-01-2012
12:30 PM
|
0
|
2
|
2658
|
|
POST
|
That did get it! Again I really appreciate your time helping me with this. If you do get a chance to explain the loop in the next few days that'd be great. Jon
... View more
07-31-2012
02:35 PM
|
0
|
0
|
708
|
| Title | Kudos | Posted |
|---|---|---|
| 3 | 07-11-2013 02:09 PM | |
| 2 | 07-31-2012 09:51 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|