POST
|
Yes! I have tried lyr.replaceDataSource(r"\\path\Set1\Set1Test", "SHAPEFILE_WORKSPACE", shape) . It produces an "Unexpected error." I think the dataset name needs to be a variable, but I haven't been able to figure how to do that. Per your suggestion, I added RefreshActiveView() after replaceDataSource and ran the code. It refreshed 10 times, but it's not replacing the data source with the next one. It keeps the first one each time and only prints out one pdf. (Or maybe two pdfs. It created one with an 11:05 timestamp, then the timestamp was 11:06)
... View more
05-19-2017
07:54 AM
|
0
|
1
|
879
|
POST
|
Yes, the ListFeatureClasses() returns a list. I have 11 of the shapefiles in a test directory. Here's what print shapelist returns after running the code: [u'Set1_Plan1.shp', u'Set1_Plan10.shp', u'Set1_Plan11.shp', u'Set1_Plan2.shp', u'Set1_Plan3.shp', u'Set1_Plan4.shp', u'Set1_Plan5.shp', u'Set1_Plan6.shp', u'Set1_Plan7.shp', u'Set1_Plan8.shp', u'Set1_Plan9.shp']
... View more
05-19-2017
07:31 AM
|
0
|
3
|
879
|
POST
|
In ArcGIS (using 10.4) I have my layout set up, shapefile A symbolized and labeled. What I need to do is print this layout to pdf, then change the source of shapefile A to the next in a series of several hundred, have it look the same, change the title, and print the pdf. I'm trying to loop through each shapefile in a folder. The shapefiles are polygon. The legend stays the same because each shapefile has the same number of polygons, symbolized the same way. The labels should stay the same, but move as the polygons they label change shape and position. The extent is constant. This is easy to do interactively in ArcGIS: go into the Layer Properties, Source tab, Set Data Source... In trying to do this in Python, I'm having difficulty. My code maybe isn't looping. It prints one map. I think the replaceDataSource {dataset_name} needs to be a variable, but I can't figure how to do that. >>> import arcpy ... import os ... mxd = arcpy.mapping.MapDocument("CURRENT") ... df = arcpy.mapping.ListDataFrames(mxd, "*")[0] ... lyr = arcpy.mapping.ListLayers(mxd, "*", df)[3] ... output_dir = r"\\path\PDFs" ... arcpy.env.workspace = r"\\path\Set1Test" ... shapelist = arcpy.ListFeatureClasses() ... for shape in shapelist: ... lyr.replaceDataSource(r"\\path\Set1Test", "SHAPEFILE_WORKSPACE", "") ... TextElement = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapTitleText")[0] ... TextElement.text = lyr.datasetName ... arcpy.mapping.ExportToPDF(mxd, r"\\path\PDFs\Map " + lyr.datasetName)
... View more
05-18-2017
01:43 PM
|
0
|
9
|
1228
|
POST
|
Ian, thank you very much for your reply. I looked into your suggestions and tried using Unique Values Symbology. I symbolized on field 'Map00001' using the .lyr file with the desired colors. Then I ran this: >>> import arcpy ... mxd = arcpy.mapping.MapDocument("CURRENT") ... df = arcpy.mapping.ListDataFrames(mxd, "*")[0] ... featureclass = arcpy.mapping.ListLayers(mxd, "*", df)[2] ... if featureclass.symbologyType == "UNIQUE_VALUES": ... featureclass.symbology.valueField = "Map00002" ... featureclass.symbology.addAllValues() ... arcpy.RefreshActiveView() ... arcpy.RefreshTOC() It changed the symbology to match Map00002 polygons, but it did not use the .lyr file symbology. It used the first color ramp available in the pulldown in the symbology tab of layer properties. In other words, the geography is right but none of the correct colors are used at all. I'll attempt to answer your questions. The symbology is RGB. 1= 0, 73, 73. 2= 0, 146, 146. 3= 255, 109, 182. 4= 255, 182, 219. 5= 0, 109, 219. etc. for each of the 13 classes. (color blindness acceptable colors). To create the layer file I opened the layer properties dialog to the symbology tab for the shapefile. I set it up with Categories set to unique values, with the value field set to Map00001. I set the color for each of the 13 classes manually to the RGB values like those above. I then right-clicked on the shapefile in the TOC and chose save as layer file. As for an example of output from the script would you want to see images or pdfs of the layout? I wonder if there's a way to code which RGB value each class 1-13 should be?
... View more
05-18-2017
09:13 AM
|
0
|
4
|
1657
|
POST
|
As a python noob, I'm attempting to create pdfs of layouts in which polygon features are symbolized with the same colors for classes, but the assignments change in each of 1,000 fields in the feature class. That is, I want to loop through each field (00000, 00001, 00002...), symbolize the categories (1-13) as set up in a .lyr file, change the map title to match the field name, print a pdf of the layout, & move to the next field to do it again. What I have will change the map title & print the pdf with the title. The problem is every map is the same, except for the title. The polygons aren't given symbology according to the .lyr file, they're identical to the .lyr file. I don't think it should matter, but the shapefile I'm symbolizing has 2692 rows. I need to display one field at a time, with each polygon (row) in the field shaded a specific color, depending on it's value, 1-13. Help please? >>> import arcpy
... import os
... mxd = arcpy.mapping.MapDocument("CURRENT")
... df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
... featureclass = arcpy.mapping.ListLayers(mxd, "*", df)[2]
... symbologyLyr = arcpy.mapping.Layer(r"\\path\Maps\SymbologyShp.lyr")
... field_names = [f.baseName for f in arcpy.ListFields(featureclass)]
... for f in field_names:
... if f.startswith("Map"):
... arcpy.mapping.UpdateLayer(df, featureclass, symbologyLyr, True)
... TextElement = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapTitleText")[0]
... TextElement.text = f
... arcpy.mapping.ExportToPDF(mxd, r"\\path\outputPDF\Map_" + f)
... View more
05-17-2017
12:36 PM
|
0
|
9
|
2757
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|