POST
|
I looks to me that your workspace is not path to the folder containing the shapefiles but rather pointing to the shapefile itself. Don't you want to use data_path instead? Here is an example. I have a workspace ("C:\Temp") with two shapefiles: "Lakes.shp" and "NewLakes.shp". My MXD has a LAKES layer that points Lakes.shp and I want to change it to NewLakes.shp. Here is the code:
mxd = arcpy.mapping.MapDocument(path to mxd)
lyr = arcpy.mapping.ListLayers(mxd, "LAKES")[0]
lyr.replaceDataSource(r"C:\Temp", "SHAPEFILE_WORKSPACE", "NewLakes")
mxd.save()
The first parameter is the path to the shape file folder (c:\temp), the third parameter is to the NewLakes shapefile, notice I'm not using the ".shp". Do have to because it is a shapefile workspace. Jeff Jeff, Thank you so much, that did the trick. The code works exactly as expected now. -Ben
... View more
02-08-2013
06:17 AM
|
0
|
0
|
272
|
POST
|
Hello, I have created a Python toolbox to makes a set of three maps for projects within user specified township, range and section. On one of these maps I wanted like to replace a statewide sections layer with a definition query set to show only the project section with a the same layer pointing to a shapefile of the single section created within the script itself. The reason I am doing this is that I would like the users to later package the maps and I would prefer them not to have to package sections for a good chunk of the state. The code to create the shapefile itself runs fine, however when I try and replace the data source of the layer file I have set up for this layer with the script generated shapefile (using the replaceDataSource method), it fails every time. I have tried every combination of feeding the the work space path and dataset name to the method but nothing seems to work. Here is the code that creates the shapefile and sets up the path to it to a variable:
#Create a shapefile of the selected section gird
data_path = os.path.dirname(params[7].valueAsText)
arcpy.FeatureClassToFeatureClass_conversion("grid_layer", data_path,refgridno+'.shp')
shp_path = os.path.join(data_path, refgridno+'.shp')
Here is the code that sets up the project sections layer and should (hypothetically) replace the layers data source with the newly created shapefile.
#Set the project section label layer to the selected T.,R.,Sec value and add it to the main dataframe
prj_sec = arcpy.mapping.Layer(layerPath+"\\"+"Project Section Label.lyr")
prj_sec.replaceDataSource(os.path.dirname(shp_path),"SHAPEFILE_WORKSPACE", os.path.basename(shp_path),0)
arcpy.mapping.AddLayer(df, prj_sec, "AUTO_ARRANGE")
Anyone out there had an issue like this before? Thanks, Ben Z
... View more
02-07-2013
05:45 AM
|
0
|
2
|
2615
|
POST
|
I am having this same issue running the viewshed tool from a geoprocessing script. I tried calculating statistics, setting the extent environment, pointing to a different DEM but nothing seems to be working. I have a different script that uses viewshed that seem to run just fine. I don't understand what difference betwen the two scripts is causing the problem. If anyone has worked this out I would appreciate the help. -Ben
... View more
12-11-2012
08:27 AM
|
1
|
0
|
959
|
POST
|
I realize this is a little late to help Dan, but here is a another simple function that constrains the map extent to a user specified area: dojo.connect(map, "onExtentChange", function (){
var extent = map.extent.getCenter();
if(initialExtent.contains(extent)){}
else{map.setExtent(initialExtent)}
}); The event handler listens for the map "onExtentChange" event. When the event occurs the center of the current map extent is passed to a variable called extent the extent.contains method is used to verify if the center point falls within the initial map extent. If it does nothing happens, if it doesn't the map extent is set back to the initial extent. Hopefully somebody searching on this topic will be able to make use of this. Cheers, Ben
... View more
05-04-2012
09:54 AM
|
0
|
0
|
1806
|
POST
|
Shuping, Thank you so much for this post! I have been trying to figure out how to do this for weeks and this works perfectly. Thanks again, Ben
... View more
03-16-2012
11:44 AM
|
0
|
0
|
505
|
POST
|
Hello, I have created a application and have used the bookmarks widget to add 20 some odd custom bookmarks to the map within a "dijit.TooltipDialog" drop-down list (as the online sample shows). I can connect to the esri.dijit.Bookmarks onClick event to run functions when the user selects a bookmark from the list. What I would like to do to do extract the "name" of the BookmarkItem that was selected by the user after each on click event and pass it into a variable. Does anyone know if this is possible? Thanks, Benjamin Zank
... View more
02-10-2012
01:13 PM
|
0
|
1
|
716
|
POST
|
Heming, I have a script that does something similar, but rather than creating a feature class in the scratch.gdb, my script creates a new file geodatabase in the the scratch folder and uses feature class to feature class to populate features while applying a query. The geodatabase is then zipped so it can be downloaded by a user. You could try creating a new file GDB in the scratch folder and populate the feature class using Feature Class to Feature Class in the new GDB rather than using the sratch.gdb. Alternately, rather than populating with Feature Class to Feature Class. You could create a new empty feature class in the sratch.gdb using Create Feature Class, setting your input or feature set as the template feature class (so the schemas match) . You could then use the Append to add the feature set (or a feature layer to which you apply your query) to the newly created feature class. Not sure why what you are trying wouldn't work, but it my be worth trying a work around. Best of luck, BZ
... View more
08-11-2011
02:14 PM
|
0
|
0
|
1132
|
POST
|
I have created a geoprocessing script tool that accepts a feature class and folder as inputs. When I add the tool ArcToolbox in ArcMap and try and drag a feature class from the table of contents I get an "Invalid drop item" pop-up with the message, one or more dropped items were invalid and will not be added to the control."
... View more
08-03-2011
09:09 AM
|
0
|
5
|
6174
|
POST
|
Hello, I was wondering if anyone out there know's when (at what version of release) the Vertical and Horizontal factor parameters were added to the Path Distance tool in Spatial Analyst. Thanks, Benjamin Zank
... View more
11-01-2010
01:14 PM
|
0
|
1
|
636
|
Title | Kudos | Posted |
---|---|---|
1 | 12-11-2012 08:27 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|