|
POST
|
I using the below code snippet to create a route event and will eventually set it up to accept input parameters for the route ID, begin MP and End MP. So I was thinking I test setting it up to "build" the in event properties input using string formatting. But the string I have assigned to the props variable does not seem to work. Any ideas out there of what I am missing? import arcpy
import os
arcpy.env.overwriteOutput = 1
arcpy.env.workspace = r"\\itdhq1apt50\GIS_Data\NeedsTracking\Scratch.gdb"
gdb_loc = arcpy.env.workspace
scratch = arcpy.env.scratchWorkspace
scratch_gdb = os.path.join(scratch, 'scratch.gdb')
print "starting this darn task"
arcpy.AddMessage("starting this darn task")
in_line = "Database Connections\CONNECTION SDE 4 MAPPING.sde\sdeProd.SDE.StateHighwayUpdateFile" #sde statehwy data used to create route file
rteID = "RD_NAME" # using this a route ID to create routes base on road number rather than segment no
#rteID = "UNIQUE_ID" # this will create routes based on segment no
outRoute = "StateHwyRouteFile"
outEvent = "lineTemp"
fc = "LineSelection"
#fc_prj = "PointsTestingWM"
fc_prj = os.path.join(scratch,'LineSelectionWM')
csWM = r"Coordinate Systems\Projected Coordinate Systems\World\WGS 1984 Web Mercator (Auxiliary Sphere).prj"
#table = arcpy.GetParameter(0)
table = gdb_loc + os.sep + "locateRoute"
inRoute = "routeID"
inBMP = "BMP"
inEMP = "EMP"
props = '"%s %s %s %s"' % (inRoute, 'LINE', inBMP, inEMP)
arcpy.MakeRouteEventLayer_lr(outRoute, rteID, table, props, outEvent, "#", "ERROR_FIELD")
#arcpy.MakeRouteEventLayer_lr(outRoute, rteID, table, "routeID LINE BMP EMP", outEvent, "#", "ERROR_FIELD") Thanks
... View more
08-24-2012
12:45 PM
|
0
|
1
|
1109
|
|
POST
|
Check out Corpscon. I've used it in the past and works well to take a text file with coordinate pairs + other attribute info and re-project and write to a new file. http://www.tec.army.mil/corpscon/
... View more
06-28-2012
10:44 AM
|
0
|
0
|
984
|
|
POST
|
Apparently it's a bug that's resolved in 10.1. See below for the response from ESRI: The errors you're seeing in regards to using the functions of the Map Document class are because of an existing bug in our system, which is fixed at version 10.1. The way to get around these errors would be to either 1) Remove all layers from your map that don't support the WORKSPACEPATH or DATASOURCE properties (i.e. Basemap layers, Layers from ArcGIS Services, etc.) or to use the Layer class instead of the map document class. Using the layer class solves the issue.
... View more
06-25-2012
10:16 AM
|
0
|
0
|
326
|
|
POST
|
Aparently there is a bug using this method in ArcGIS 10.0. I'm in the process of re-working a script to accomplish this same feat using the layer class instead. Any suggestions or guidance is appreciated. One possible issue is your "TRUE" statement in:
mxd.findAndReplaceWorkspacePaths(r"J:\GIS\JHill\SDE_To_Route", r"\\itdgishq\hqgis\LocalRds\SDE_To_Route", "TRUE")
Try:
mxd.findAndReplaceWorkspacePaths(r"J:\GIS\JHill\SDE_To_Route", r"\\itdgishq\hqgis\LocalRds\SDE_To_Route", True)
or because True is the default value, try:
mxd.findAndReplaceWorkspacePaths(r"J:\GIS\JHill\SDE_To_Route", r"\\itdgishq\hqgis\LocalRds\SDE_To_Route")
Jeff
... View more
06-22-2012
08:20 AM
|
0
|
0
|
1561
|
|
POST
|
Using del mxd at the end of each loop didn't change anything.....still crashing PythonWin. I don't know if this will help, but you should delete your mxd when you're done with it: del mxd
... View more
06-21-2012
09:35 AM
|
0
|
0
|
1561
|
|
POST
|
Thanks Darren for pointing that out. I've revised the script as follows, and now it crashes PythonWin. I know I'm overlooking something, just not sure what it is. import arcpy
import os
#ckFolder = arcpy.GetParameterAsText(0)
ckFolder = r"\\itdhq1apt50\gis_data\testUpdatePaths\FremontCounty"
arcpy.env.workspace = ckFolder
print "Checking Folder: " + ckFolder
arcpy.AddMessage("Checking Folder: " + ckFolder)
for mDoc in arcpy.ListFiles("*.mxd"):
fullPath = os.path.join(ckFolder, mDoc)
mxd = arcpy.mapping.MapDocument(fullPath)
print fullPath
#print mxd
mxd.findAndReplaceWorkspacePaths(r"J:\GIS\JHill\SDE_To_Route", r"\\itdgishq\hqgis\LocalRds\SDE_To_Route", "TRUE")
mxd.save() Why did you comment out the line: #mxd = arcpy.mapping.MapDocument(ckFolder + os.sep + mDoc)? You need a MapDocument to use findAndReplaceWorkspacePaths. The value returned from os.path.join isn't a MapDocument, it's a path to a MapDocument.
... View more
06-21-2012
09:02 AM
|
0
|
0
|
1561
|
|
POST
|
Attempting to use the find and replace workspace path, but it's returning an error message. Any suggestions on why it's not working? import arcpy
import os
ckFolder = r"\\itdhq1apt50\gis_data\testUpdatePaths\FremontCounty"
arcpy.env.workspace = ckFolder
print "Checking Folder: " + ckFolder
arcpy.AddMessage("Checking Folder: " + ckFolder)
for mDoc in arcpy.ListFiles("*.mxd"):
mxd = os.path.join(ckFolder, mDoc)
#print fullpath
#mxd = arcpy.mapping.MapDocument(ckFolder + os.sep + mDoc)
arcpy.AddMessage("MXD Name: " + mxd)
mxd.findAndReplaceWorkspacePaths(r"J:\GIS\JHill\SDE_To_Route", r"\\itdgishq\hqgis\LocalRds\SDE_To_Route", "FALSE")
mxd.save() Traceback (most recent call last): File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 312, in RunScript exec codeObject in __main__.__dict__ File "\\Itdgishq\hqgis\updateDataPaths.py", line 25, in <module> mxd.findAndReplaceWorkspacePaths(r"J:\GIS\JHill\SDE_To_Route", r"\\itdgishq\hqgis\LocalRds\SDE_To_Route", "FALSE") AttributeError: 'unicode' object has no attribute 'findAndReplaceWorkspacePaths'
... View more
06-21-2012
08:13 AM
|
0
|
10
|
6142
|
|
POST
|
From my experience, it is generally a slow process. Due in part to the nature, format and size of the dxf files.
... View more
05-17-2012
07:54 AM
|
0
|
0
|
298
|
|
POST
|
I have a sizable Python script that geoprocesses a bunch of excel tables, creates File GDB tables, creates point events, applies symbology, adds layers to map document and publishes to a map service. Now that that script is working, I though it would be nice to generate the xml file (flex viewer) to display the data. I'm using a previously created config.xml file as a template and am stuck on how to go about populating the various operationallayers in the xml file. In the script I've captured the layer names in a dictionary and would like to loop through it and populate the layers of the XML, etc. I've searched the web and come across a few things that sorta point me in the direction. But being a python newbie I'm kinda lost. Maybe I'm in way over my head. Any ideas or hints? Below is the code I've assembled to this point. import arcpy
import os
arcpy.env.overwriteOutput = 1
mxd = arcpy.mapping.MapDocument(r"\\itdhq1apt50\GIS_Data\Test_MM\Crash_05_10v2.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
# update counter and create list of map layers
layerList = arcpy.mapping.ListLayers(mxd, "", df)
counter = 0
mapLayerList = {}
for layer in layerList:
mapLayer = str(layer)
mapLayerList[counter] = mapLayer
counter = counter + 1
#print mapLayerList
arcpy.env.workspace = r"C:\inetpub\wwwroot\flexviewers\ScriptCrash_05_10v2"
#arcpy.env.workspace = r"\\itdhq1apt50\GIS_Data\Test_MM\CrashScriptTesting"
fileLoc = arcpy.env.workspace
print fileLoc
from xml.dom.minidom import parseString
doc = parseString("""<xml>
<configuration>
<title>Fatal Crash Data 2005 - 2010 v2</title>
<subtitle>IDAHO TRANSPORTATION DEPARTMENT</subtitle>
<logo>assets/images/ITD_officialLogo_Color2.jpg</logo>
<style>
<colors>0x444444,0xEBF4FF,0xEBF4FF,0xDEEBFF,0x444444</colors><!-- SKY BLUE -->
<alpha>0.9</alpha>
</style>
<!-- replace the following url with your own geometryservice -->
<geometryservice url="http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer" useproxy="false"/>
<bing key="Aid71RzdYmlhBMs05qwJaMdd9xgExdRsehTEhqud4kpJJSsBB1oKr9_jhvhGmZ3k"/>
<!-- UI elements -->
<!-- widgets organized into widget containers that manage close/open etc -->
<!-- supported layout property options: horizontal(default)|float|vertical|fix-->
<widgetcontainer layout="horizontal" bottom="220">
<widget label="Street View" icon="widgets/FrStreetView/assets/images/i_gsv.png" config="widgets/FrStreetView/FrStreetView.xml" url="widgets/FrStreetView/FrStreetView.swf"/>
<widgetgroup label="Attribute Help" icon="assets/images/i_resources.png">
<widget label="Crash Data Attribute Help" icon="assets/images/i_help.png" config="widgets/Link/LinkWidget_CrashAttributeHelp.xml" url="widgets/Link/LinkWidget.swf"/>
</widgetgroup>
</widgetcontainer>
<widgetcontainer layout="vertical" top="90">
<widget label="Crash Time Slider" icon="assets/images/i_clock.png" config="widgets/eTime/eTimeWidget_Crash.xml" url="widgets/eTime/eTimeWidget.swf"/>
<widget label="Find an address" icon="assets/images/04_maps.png" config="widgets/Locate/LocateWidget_US.xml" url="widgets/Locate/LocateWidget.swf"/>
<widget label="Draw and Measure" icon="assets/images/i_draw2.png" config="widgets/eDraw/DrawWidget.xml" url="widgets/eDraw/DrawWidget.swf"/>
<widget label="Print" icon="assets/images/i_print.png" config="widgets/Print/PrintWidget.xml" url="widgets/Print/PrintWidget.swf"/>
<widget label="Location Bookmarks" icon="assets/images/i_bookmark.png" config="widgets/Bookmark/BookmarkWidget.xml" url="widgets/Bookmark/BookmarkWidget.swf"/>
<widget label="Map Coordinates" icon="widgets/CoordinateMenu/images/coordinateIcon.png" config="widgets/CoordinateMenu/CoordinateMenuWidget.xml" url="widgets/CoordinateMenu/CoordinateMenuWidget_GUI.swf"/>
<widget label="Legend" icon="assets/images/Legend32.png" config="widgets/Legend/LegendWidget_Legend.xml" url="widgets/Legend/LegendWidget.swf"/>
<widget label="Select Features" icon="assets/images/i_info.png" config="widgets/Selection/SelectionWidget_ITD.xml" url="widgets/Selection/SelectionWidget.swf"/>
<widget label="Enhanced Search" icon="assets/images/i_search.png" config="widgets/eSearch/SearchWidget_ITD.xml" url="widgets/eSearch/SearchWidget.swf" preload="minimized"/>
<widget label="Crash Layers" icon="assets/images/i_layers.png" config="widgets/TOC/TOCWidget.xml" url="widgets/TOC/TOCWidget.swf" preload="minimized"/>
<widget url="widgets/ExportMap/exportMap.swf" config="widgets/ExportMap/exportMap.xml" label="Export to JPG" icon="assets/images/i_map_jpg.png"/>
</widgetcontainer>
<!--<widget url="widgets/GoogleAnalytics/GoogleAnalyticsWidget.swf" config="widgets/GoogleAnalytics/GoogleAnalyticsWidget.xml" />-->
<widget url="widgets/eSearch/SearchWidgetFixedDG.swf" left="0" right="0" bottom="0"/>
<widget url="widgets/CoordinateMenu/CoordinateMenuWidget.swf" config="widgets/CoordinateMenu/CoordinateMenuWidget.xml" left="0" top="0"/>
<widget url="widgets/OverviewMap/OverviewMapWidget.swf" config="widgets/OverviewMap/OverviewMapWidget.xml" right="-2" bottom="-2"/>
<widget url="widgets/eMapSwitcher/MapSwitcherWidget.swf" config="widgets/eMapSwitcher/MapSwitcherWidget.xml" right="15" top="55"/>
<widget url="widgets/HeaderController/HeaderControllerWidget.swf" config="widgets/HeaderController/HeaderControllerWidget.xml" left="0" top="0"/>
<widget url="widgets/Coordinate/CoordinateWidget.swf" config="widgets/Coordinate/CoordinateWidget.xml" label="Coordinate" icon="assets/images/i_globe.png" left="3;" bottom="200"/>
<map esrilogovisible="true" openhandcursorvisible="false" scalebarvisible="true" zoomslidervisible="true" wraparound180="true" center="-12767957.671 5539872.238" scale="6943500" right="0" top="0" bottom="0">
<basemaps>
<layer label="Bing Streets" type="bing" alpha="1.0" visible="true" style="road" culture="en-US"/>
<layer label="Bing Aerial" type="bing" alpha="1.0" visible="false" style="aerial" culture="en-US"/>
<layer label="Bing Hybrid" type="bing" alpha="1.0" visible="false" style="aerialWithLabels" culture="en-US"/>
<layer label="ESRI Streets" type="tiled" alpha="1.0" visible="false" url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
<layer label="ESRI Topo" type="tiled" alpha="1.0" visible="false" url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>
</basemaps>
<operationallayers>
<layer type="feature" label="Test" url="http://itdhq1apt50/ArcGISTest/rest/services/MM_Test/TestScriptCrash/MapServer/78" visible="true"/>
</operationallayers>
</map>
</configuration>
</xml>""")
outFile = fileLoc + os.sep + "config.xml"
print outFile
with open(outFile, "w") as f:
f.write( doc.toxml() )
... View more
05-11-2012
12:00 PM
|
0
|
0
|
1443
|
|
POST
|
Thank you gentlemen! I'm just getting up to speed with Python and this list is great for nudging me over the hurdles. Michael Miller
... View more
05-04-2012
05:27 AM
|
0
|
0
|
636
|
|
POST
|
Any idea why the following code will not work? If I take out the " " and one +, it will run, but not the result I need. #dateTimeExp = "!AccDate! + " " + !AccTime!" dateTimeExp = "str(!AccDate! + " " + !AccTime!)" arcpy.CalculateField_management(outCrash, "AccDT", dateTimeExp, "PYTHON") It returns the following error: ExecuteError: ERROR 000539: Error running expression: str("4/1/2005" + + "7:35:00 AM") <type 'exceptions.TypeError'>: bad operand type for unary +: 'str' Failed to execute (CalculateField).
... View more
05-03-2012
01:44 PM
|
0
|
3
|
785
|
|
POST
|
Thanks for the suggestions Darren. The script now runs, but is not adding the 0's to the left side of the Segment_Code values. Any gotchas that I'm missing here? Michael Just discovered the Segment_Code field was converted to numeric during the TableToTable conversion. Looks like I'll have to figure out a method to preserve the string field type before I can pad the 0's. Thanks all for the help. Michael
... View more
05-03-2012
06:25 AM
|
0
|
0
|
2513
|
|
POST
|
I think you just need quotes: exp = "str(!Segment_Code!).zfill(6)"
arcpy.CalculateField_management(outCrash, exp, "PYTHON") Thanks for the suggestions Darren. The script now runs, but is not adding the 0's to the left side of the Segment_Code values. Any gotchas that I'm missing here? Michael
... View more
05-03-2012
05:50 AM
|
0
|
0
|
2513
|
|
POST
|
You are using the wrong syntax. Check your tool documentation here. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000 The expression is the third variable passed to the tool, the field is the second. Duh.....Thanks for pointing that out Mathew. Michael
... View more
05-03-2012
05:35 AM
|
0
|
0
|
2513
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 03-29-2012 10:22 AM | |
| 2 | 09-17-2018 05:38 AM | |
| 1 | 03-23-2016 06:25 AM | |
| 1 | 06-30-2016 09:13 AM | |
| 1 | 11-23-2015 08:40 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:24 AM
|