POST
|
I need to re-structure my script so the line & feature class creation happen in functions rather than the being spelled out in the main part of my script. I then, need to separate the function into a separate file and make the adjustments necessary in the main script to allow it to still utilize the functions. My script; # Use a .txt file to generate a line shapefile import arcpy from collections import defaultdict import pandas as pd outFolder = "C:\\Data" arcpy . env . workspace = outFolder #Read textfile and store in dictionary df = pd . read_csv ( r "C:\\Data\\WalkingPaths.txt" , header = None , names =[ "WalkingPath" , "X" , "Y" ]) d = defaultdict ( list ) for index , row in df . iterrows (): d [ row [ "WellPath" ]]. append ( arcpy . Point ( row [ "X" ], row [ "Y" ])) #Create feature class fc = "WalkingPaths.shp" spatRef = arcpy . SpatialReference ( 26913 ) arcpy . CreateFeatureclass_management ( out_path = outFolder , out_name = fc , geometry_type = "POLYLINE" , spatial_reference = spatRef ) arcpy . AddField_management ( in_table = fc , field_name = "WalkingPath" , field_type = "TEXT" ) #Insert polylines and attribute insertCursor = arcpy . da . InsertCursor ( fc , [ "SHAPE@" , "WalkingPath" ]) for ranch , points in d . iteritems (): #d.items() in python 3 insertCursor . insertRow ([ arcpy . Polyline ( arcpy . Array ( points )), ranch ]) del insertCursor
... View more
11-12-2018
03:28 PM
|
0
|
1
|
215
|
POST
|
Jim, I work with Data Driven Pages quite a bit and understand how they work. However, what I'm looking for here; is assistance/guidance with Python, Arcpy and working with an .mxd, it's linked data layers and creating a mapbook without any previously setup Data Driven Pages. Thank you,
... View more
11-05-2018
01:22 PM
|
0
|
0
|
60
|
POST
|
Yes, what you have is correct. The last line needs to be be indented back though. Thank you.
... View more
11-05-2018
07:39 AM
|
0
|
2
|
60
|
POST
|
Through a plethora of trials and research, I finally was able to get a script to work. My original question encompassed me needing to take an .mxd and create a PDF mapbook document that will contain a map for each county in the counties FC. Then, I needed to change the title of each map to the name of the county being shown. Lastly, I need to scale the map a bit so it shows an area just a bit larger than the actual extent. The following script works great. I hope this will help others in the future; import arcpy , os from arcpy . mapping import * countiesPath = "C:\\Data\\COUNTIES.shp" pdfPath = "C:\\Data\\COCounties.pdf" mxdPath = "C:\\Data\\Counties.mxd" mxd = MapDocument ( mxdPath ) dataFrame = ( mxdPath , "COUNTIES" )[ 0 ] listLayers = ListLayers ( mxd ) finalPDF = PDFDocumentCreate ( pdfPath ) df = ListDataFrames ( mxd , "Layers" )[ 0 ] for layer in listLayers : if layer . name == "COUNTIES" : with arcpy . da . SearchCursor ( layer , "COUNTY" ) as cursor : for row in cursor : countyName = row [ 0 ] whereClause = "COUNTY='" + countyName + "'" arcpy . SelectLayerByAttribute_management ( layer , "NEW_SELECTION" , whereClause ) df . zoomToSelectedFeatures () arcpy . SelectLayerByAttribute_management ( layer , "CLEAR_SELECTION" ) df . scale *= 1.5 titleItem = ListLayoutElements ( mxd , "TEXT_ELEMENT" , "title" )[ 0 ] titleItem . text = "Map of: " + countyName + " COUNTY" countyPDF = r "C:\\Data" + countyName + ".pdf" ExportToPDF ( mxd , countyPDF , "PAGE_LAYOUT" , resolution = 600 , df_export_width = 1100 , df_export_height = 800 ) finalPDF . appendPages ( countyPDF ) os . remove ( countyPDF ) finalPDF . saveAndClose () del finalPDF del mxd
... View more
11-04-2018
09:18 AM
|
0
|
7
|
1411
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:25 AM
|