POST
|
I added a new layer to my map in AGOL. The data updated successfully in the app, but the search bar is no longer visible. When editing the app, the search bar is still there. When I try to configure the search widget, it just sits there. I don't have access to edit any of the information. The search information does not show up, so I am wondering if it is still trying to load. I had updated map information in March with no problems. This time I used the new viewer.
... View more
04-28-2021
01:04 PM
|
4
|
4
|
2481
|
POST
|
Wayne, You are the best. The script is working beautifully. Thank you for your time and assistance.
... View more
04-04-2013
02:12 PM
|
0
|
0
|
459
|
POST
|
Good morning, I am sorry to be such a needy scripter. If you don't have the time to look at this, I understand. I used the last code that you wrote and put 3 townships in my list. All 3 townships should result in pages with data in the .pdf. The script only outputs the first map, and then shows that the next two maps have zero pages. I have attached a map package. This contains the pole data to be displayed, the index layer, and the pole layer to be used for intersection. It also contains a back cover and 4 cover pages. I included the data for the 3 townships with data and one without (D64). Thank you # PoleDDpages.py
# Author: slw
# Date: XXXXX
# Revisions: XXXXX
# Description: Create Pole map book series using Data Driven Pages and
# insert a cover page
# Import ArcPy
import os,arcpy
# Overwrite existing file
arcpy.env.overwriteOutput = True
try:
# Set up variables
# Location of pole map .mxd document
mxdDoc = r"G:\GEOSPATIAL\Publishing\Pole\Pole_QtrSec.mxd"
# Create the MapDocument object
mxd = arcpy.mapping.MapDocument(mxdDoc)
df = arcpy.mapping.ListDataFrames(mxd)[0]
layer = arcpy.mapping.ListLayers (mxd, "SURVEY_GRID_BNDRY",df)[0]
poleLyr = arcpy.mapping.ListLayers (mxd, "Pole",df)[0]
################
# moved part of code to select grids (layer) intersecting 'Pole' features (poleLyr)
# Create temporary layers to work with the Selection,
# 1st need to assure no prior selections...the sel by loc syntax:
# SelectLayerByLocation_management (in_layer, {overlap_type}, {select_features}, {search_distance}, {selection_type})
# in_layer is the index layer; select_features is the pole layer
SelectBy = [layer, poleLyr]
for lyr in SelectBy:
iniCount = int(arcpy.GetCount_management(lyr).getOutput(0))
if iniCount != 0:
arcpy.SelectLayerByAttribute_management(lyr, 'CLEAR_SELECTION')
# should now be properly 'initialized' with no prior selections, i.e., full complement datasets
arcpy.MakeFeatureLayer_management(layer, "surveyLyr")
arcpy.MakeFeatureLayer_management(poleLyr, "poleLyr_new")
# Select Layer By Location to limit to just maps with data
arcpy.SelectLayerByLocation_management("surveyLyr", "INTERSECT", "poleLyr_new", "", "NEW_SELECTION")
# Susan, check that this works, switching the selection...
# SelectLayerByAttribute_management (in_layer_or_view, {selection_type}, {where_clause})
arcpy.SelectLayerByAttribute_management("surveyLyr", "SWITCH_SELECTION")
# new code to get at OBJECTIDs to modify def query
IDs = []
rows = arcpy.SearchCursor("surveyLyr")
for row in rows:
IDs.append(row.OBJECTID)
del row, rows
subquery = '('
for each in IDs:
subquery = subquery + str(each) + ','
subquery = subquery[0:-1] + ')'
################
# Output directory for the pole maps
outDir = r"G:\GEOSPATIAL\Publishing\Pole"
# Set the workspace
arcpy.env.workspace = outDir
# List of map grids
twpList = ['\"TOWNSHIP_C\" = \'D5\' AND \"RANGE_CD\" = \'5\'',\
'\"TOWNSHIP_C\" = \'C4\' AND \"RANGE_CD\" = \'7\'',\
'\"TOWNSHIP_C\" = \'B8\' AND \"RANGE_CD\" = \'4\'']
for twpName in twpList:
# need to test the twpName with the added subquery for empty return 1st
theQuery = twpName + " AND \"OBJECTID\" NOT IN " + str(subquery)
# create a feature layer on index with which to test theQuery for empty set
# MakeFeatureLayer_management (in_features, out_layer, {where_clause})
arcpy.MakeFeatureLayer_management(layer, "testTheCount", theQuery)
gridsToOutput = int(arcpy.GetCount_management("testTheCount").getOutput(0))
print "Output " + str(gridsToOutput) + " pages"
if gridsToOutput != 0:
# modified the definitionQuery to include the subquery exclusion clause
layer.definitionQuery = theQuery
# refresh() after changing the layer def query to 'redefine' the DDP index limits
print "Refresh DDP"
mxd.dataDrivenPages.refresh()
# The final mapbook name taken from the list
finalPDFfn = outDir + "\\" + twpName [16:18] + twpName [38:39] + "Pole.pdf"
# Create the final PDF -- which is just an empty shell right now
finalPDF = arcpy.mapping.PDFDocumentCreate(finalPDFfn)
# A temporary pdf file for processing
tmpPDF = outDir + "\\PoleMapPages.pdf"
# Let the user know what is happening!
print "Exporting " + twpName [16:18] + twpName [38:39]
# Export the data driven pages in the mxd to a temporary PDF
print "Exporting map pages to the temporary PDF"
ddp = mxd.dataDrivenPages.exportToPDF(tmpPDF)
# Append the temporary pdf to the final pdf
# Cover, map pages, back cover
print "Appending Map Pages"
finalPDF.appendPages (r"G:\GEOSPATIAL\Publishing\Pole\PoleCovers\Covers_"\
+ twpName [16:18] + twpName [38:39] + ".pdf")
finalPDF.appendPages(tmpPDF)
finalPDF.appendPages(r"G:\GEOSPATIAL\Publishing\TwpGrid_BW8x11.pdf")
# Set properties for Adobe Reader and save PDF.
finalPDF.updateDocProperties(pdf_open_view = "USE_THUMBS", pdf_layout = "SINGLE_PAGE")
finalPDF.saveAndClose()
# Deleting temporary layers
arcpy.Delete_management("surveyLyr")
arcpy.Delete_management("poleLyr_new")
arcpy.Delete_management("testTheCount")
except Exception as e:
print e.message
print arcpy.GetMessages(2)
# Clean up
print "Cleaning up"
# Delete the temporary PDF using the ArcPy function
if arcpy.Exists(tmpPDF):
arcpy.Delete_management(tmpPDF)
# Delete objects
del mxd, tmpPDF, ddp
# Finished message
print "Map compilation completed. Please review the final output."
... View more
02-22-2013
09:53 AM
|
0
|
0
|
459
|
POST
|
Just as a follow up. I am working on this between other items. I have added print statements and I have replaced the township that does not have any resulting data with one that does. I get the same result with the last code that you provided. The script will look at D55, print that it has 2 pages, and create the .pdf. It then shows the next township (now using B84) has zero pages. I am working on deciphering some of the code (remember I am a newbie) so maybe I can find out why subsequent townships count as zero pages. Thank you, Susan
... View more
02-21-2013
10:23 AM
|
0
|
0
|
459
|
POST
|
I now have 3 townships in my list. The first and last have data, the middle or second one will result in no map sheets or no poles. The script will create the first .pdf but will not create the third .pdf ... Do we need an elif statement?
... View more
02-20-2013
11:50 AM
|
0
|
0
|
459
|
POST
|
It's working! The only issue is, if there is a map (twp/range) where there are no sheets selected, the mxd.dataDrivenPages.refresh() fails and no other maps are output. Is there a way we can handle this? As an additional note to your last post. The pages that do not have data, really do not have any pole data at all. Nothing on the edges trying to peek through! Thank you, Susan
... View more
02-20-2013
07:22 AM
|
0
|
0
|
541
|
POST
|
Yes, I checked the sheets in the mxd itself. We are working in 10.1, so I need to make everything version 10.0. I'll try to get that out today or tomorrow. Thank you for all of your help, Wayne. Susan
... View more
02-19-2013
09:01 AM
|
0
|
0
|
541
|
POST
|
Did all of that exactly. Still get pages with no data.
... View more
02-19-2013
08:36 AM
|
0
|
0
|
541
|
POST
|
The .mxd was created in version 10.1, so I don't know if that would be the problem. I added the print statement to the script and this was the result (I stripped out the extra statements): "TOWNSHIP_C" = 'D5' AND "RANGE_CD" = '5'AND"OBJECTID"NOT IN(186,226,227,248,271,272,274,275,297,322,347,348) Exporting D55 "TOWNSHIP_C" = 'D6' AND "RANGE_CD" = '4'AND"OBJECTID"NOT IN(186,226,227,248,271,272,274,275,297,322,347,348) Exporting D64 When adding this to the definition query in the original .mxd, it still results in pages without data for both instances. Thank you, Susan
... View more
02-19-2013
08:17 AM
|
0
|
0
|
541
|
POST
|
First you are correct in your statement "To be specific, the code I last posted runs without error and the exported map sheets reflect some index pages without pole data?" I ran the script again with the str modification you noted in the definition query and received the same result. I tried to open the mxd files G:\GEOSPATIAL\Publishing\Pole\Pole_QtrSec1.mxd and Pole_QtrSec2.mxd. The files would not open. Got a large ArcMap error ... Opening the selected Arcmap document failed. The standard document information of the map document could not be read. The data frames of the map document could not be read due to the following error: 0x80040111 (Class factory cannot supply requested class) The last successfully loaded component was: esriDisplay.RgbColor ({7EE9C496-D123-11D0-8383-080009b996cc}) the specified file does not contain a valid ArcMap document ... so I was not able to check the definition query. I did try to open on more than one machine. Before I started trying to add the select by location, the definition query was working and providing only the township/range I was asking for. I still get the correct township/range in the resulting file, it's just that I also have pages (sections) that do not have any data. Looks like I had better research on better error trapping. I guess the beginning class was not enough! Thank you, Susan
... View more
02-19-2013
05:23 AM
|
0
|
0
|
541
|
POST
|
No errors, Wayne, but I still have the map sheets that do not have any data.
... View more
02-18-2013
12:46 PM
|
0
|
0
|
560
|
POST
|
Good morning, Definition query defines the township/range to process and the select by location selects only the sections and quarter sections in the township/range that do not have data. So are you saying to not use the select by location and set it up as a separate definition query or do the select by location first and then the definition query. I appreciate your assistance. This scripting is my trek into unknown waters.
... View more
02-18-2013
05:15 AM
|
0
|
0
|
560
|
POST
|
Thank you, I'll try adding the Traceback to see if I get any information. The definition query works correctly. I got that to work before I added the selection statement. The extra backslash was added so I could put the next 'item' on a new line. It just lets python know that the line continues. Thank you
... View more
02-15-2013
08:13 AM
|
0
|
0
|
560
|
POST
|
I sought assistance with a portion of this code earlier. I have added an additional step, which to me would seem pretty simple, but I am still learning the ups & downs of Python. My script creates data driven pages. I use a list to populate a layer definition query to run a specific township. Now I am trying to do a selection (SelectLayerByLocation) to only find the townships where there is data. I first just added the SelectLayerByLocation command. Did not work. With further reading, it looked like I needed to run a MakeFeatureLayer on the two sets of data involved in the selection. Still did not work. Do I need to use cursors or is the answer much simpler? I do not have any error messages. I have added try/except to see if I can find additional information on what is happening with my script. The data exports just fine, but there are maps that do not have any data. Thank you for any guidance. # PoleDDpages.py # Author: slw # Date: XXXXX # Revisions: XXXXX # Description: Create Pole map book series using Data Driven Pages and # insert a cover page # Import ArcPy import os,arcpy try: # Set up variables # Location of pole map .mxd document mxdDoc = r"G:\GEOSPATIAL\Publishing\Pole\Pole_QtrSec.mxd" # Create the MapDocument object mxd = arcpy.mapping.MapDocument(mxdDoc) df = arcpy.mapping.ListDataFrames(mxd)[0] layer = arcpy.mapping.ListLayers (mxd, "SURVEY_GRID_BNDRY",df)[0] poleLyr = arcpy.mapping.ListLayers (mxd, "Pole",df)[0] # Overwrite existing file arcpy.env.overwriteOutput = True # Output directory for the pole maps outDir = r"G:\GEOSPATIAL\Publishing\Pole" # Set the workspace arcpy.env.workspace = outDir # List of map grids twpList = ['\"TOWNSHIP_C\" = \'D5\' AND \"RANGE_CD\" = \'5\'',\ '\"TOWNSHIP_C\" = \'D6\' AND \"RANGE_CD\" = \'4\''] i=1 for twpName in twpList: layer.definitionQuery = twpName # refresh() after changing the layer def query to 'redefine' the DDP index limits mxd.dataDrivenPages.refresh() # Create temporary layers to work with the Selection arcpy.MakeFeatureLayer_management(layer, "surveyLyr") arcpy.MakeFeatureLayer_management(poleLyr, "poleLyr_new") # Clear the Selection before starting #arcpy.SelectLayerByAttribute_management("surveyLyr", "CLEAR_SELECTION", "") #print "The selection has been cleared" # Select Layer By Location to limit to just maps with data arcpy.SelectLayerByLocation_management("surveyLyr", "INTERSECT", "poleLyr_new", "", "NEW_SELECTION") # refresh() after changing the layer def query to 'redefine' the DDP index limits mxd.dataDrivenPages.refresh() mxd.saveACopy(os.path.splitext(mxdDoc) [0] + str(i) + os.path.splitext(mxdDoc)[1]) i += 1 # The final mapbook name taken from the list finalPDFfn = outDir + "\\" + twpName [16:18] + twpName [38:39] + "Pole.pdf" # Create the final PDF -- which is just an empty shell right now finalPDF = arcpy.mapping.PDFDocumentCreate(finalPDFfn) # A temporary pdf file for processing tmpPDF = outDir + "\\PoleMapPages.pdf" # Let the user know what is happening! print "Exporting " + twpName [16:18] + twpName [38:39] # Export the data driven pages in the mxd to a temporary PDF print "Exporting map pages to the temporary PDF" ddp = mxd.dataDrivenPages.exportToPDF(tmpPDF) # Append the temporary pdf to the final pdf # Cover, map pages, back cover print "Appending Map Pages" finalPDF.appendPages (r"G:\GEOSPATIAL\Publishing\Pole\PoleCovers\Covers_"\ + twpName [16:18] + twpName [38:39] + ".pdf") finalPDF.appendPages(tmpPDF) finalPDF.appendPages(r"G:\GEOSPATIAL\Publishing\TwpGrid_Color8x11.pdf") # Set properties for Adobe Reader and save PDF. finalPDF.updateDocProperties(pdf_open_view = "USE_THUMBS", pdf_layout = "SINGLE_PAGE") finalPDF.saveAndClose() # Deleting temporary layers arcpy.Delete_management("surveyLyr") arcpy.Delete_management("poleLyr_new") except Exception as e: print e.message print arcpy.GetMessages(2) # Clean up print "Cleaning up" # Delete the temporary PDF using the ArcPy function if arcpy.Exists(tmpPDF): arcpy.Delete_management(tmpPDF) # Delete objects del mxd, tmpPDF, ddp # Finished message print "Map compilation completed. Please review the final output."
... View more
02-12-2013
09:45 AM
|
0
|
28
|
2319
|
POST
|
The code ran with the modifications. Adding the refresh makes sense. Thank you all for your assistance. On to the next portion of the code .... selection! Have a good day.
... View more
02-08-2013
06:14 AM
|
0
|
0
|
521
|
Title | Kudos | Posted |
---|---|---|
4 | 04-28-2021 01:04 PM |
Online Status |
Offline
|
Date Last Visited |
12-20-2023
06:19 PM
|