0

I am trying to export single point file maps to PDF. My maps are exporting fine, but I'm having trouble centering the point file in the middle of the map, it's always outside of the data frame. Any suggestions?

import arcpy

mxd = arcpy.mapping.MapDocument(r'P:/Python/test.mxd')
substation = 'Mcarthur.shp'

add_substation = arcpy.mapping.Layer('mcarthur.lyr')

df = arcpy.mapping.ListDataFrames(mxd, 'Data_Frame')[0]  

for df in arcpy.mapping.ListDataFrames(mxd):
  df.rotation = 0
  df.scale = 250000

sub = arcpy.mapping.AddLayer(df, add_substation, 'AUTO_ARRANGE')


north_arrow = arcpy.mapping.ListLayoutElements(mxd, 'MAPSURROUND_ELEMENT', 
'North*')
narrow = north_arrow[0]
narrow.elementPositionX = 4.25
narrow.elementPositionY = 1.25

map_legend = arcpy.mapping.ListLayoutElements(mxd, 'LEGEND_ELEMENT', 
'Map_L*')
legend = map_legend[0]
legend.elementPositionX = 0.5
legend.elementPositionY = 1.33

map_scale_bar = arcpy.mapping.ListLayoutElements(mxd, 'MAPSURROUND_ELEMENT', 
'Scale*')
scalebar = map_scale_bar[0]
scalebar.elementPositionX = 4.25
scalebar.elementPositionY = 0.33

map_title = arcpy.mapping.ListLayoutElements(mxd, 'TEXT_ELEMENT', 'Map_T*')
title = map_title[0]
title.elementPositionX = 4.25
title.elementPositionY = 10.75
title.text = substation

map_data_frame = arcpy.mapping.ListLayoutElements(mxd, 'DATAFRAME_ELEMENT', 
'Data_F*')
dataframe = map_data_frame[0]
dataframe.elementPositionX = 4.25
dataframe.elementPositionY = 2.75
dataframe.elementHeight = 7.5
dataframe.elementWidth  = 7.5

mpc_image = arcpy.mapping.ListLayoutElements(mxd, 'PICTURE_ELEMENT', 'MPC*')
mpcimage = mpc_image[0]
dataframe.elementpositionX = 8.0
dataframe.elementpositionY = 1.55


copy = mxd.saveACopy(r'P:/Python/mapoutput.mxd')
arcpy.mapping.ExportToPDF(mxd, r'P:/Python/mapoutput.pdf')

del mxd
  • The posted script seems unrelated. It's moving map elements around. Where is/are your point(s)? – Emil Brundage Jun 5 at 17:28
  • @EmilBrundage The last part of the script organizes the map elements for the initial .mxd file I have. The first part of the script adds the 'mcarthur.lyr' (point file) to the test.mxd and puts it on top of the other layers (basemap) in the test.mxd. I want the exported PDF to center the map on this point file. – Mark1994 Jun 5 at 17:40
  • Do you want all points in the layer shown in the data frame? – Emil Brundage Jun 5 at 18:33
  • Have you tried using the Data Driven Pages feature? Check these links: esri.com/arcgis-blog/products/arcgis-desktop/mapping/… and gis.stackexchange.com/questions/35091/… – Carlos MSF Jun 6 at 10:55
  • I haven't but I'll look into it, that could be very useful for what I'm trying to do. Thank you – Mark1994 Jun 6 at 16:08
1

You'll want to make use of an extent object. Get the extent of your layer. Next set your data frame extent to the layer's extent.

add_substation = arcpy.mapping.Layer('mcarthur.lyr')
df = arcpy.mapping.ListDataFrames(mxd, 'Data_Frame')[0]
#set data frame extent to layer's extent
df.extent = add_substation.getExtent ()
  • This solved my problem, the point layer is now centered on my PDF map. Thank you. – Mark1994 Jun 6 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.