top of page

AMES Plantation Landcover Map by Hunting Units

This project is about map book of Fayette and Hardeman Counties, TN, USA. Each page contains zoomed in view of each grid index.

Python (Arcpy) script for Title-map and  Locator-map generator:

# Ehsan Momeni

# crating a Title map and locater map
# this script has three parts: 1-creating a Title map 2-adding text to title map 3-creating a locator_map

#----------------------------------------------------------------------------------------------------------#
#Part1: Creating map of title map
import arcpy
from arcpy import *
Input_path = r"C:\Users\emomeni\ProjectAMES\\"  # data folder
Mxd = "mapBook.mxd"  # mxd arcGIS file
pdf = r"C:\Users\emomeni\ProjectAMES\title.pdf"  # output pdf file
gridIndexFeatures_symbology = r"C:\Users\emomeni\gridIndexFeatures_symbology.lyr"
arcpy.env.workspace = Input_path
arcpy.env.overwriteOutput = True

gridIndexFeatures = "gridIndexFeatures.shp"  # a name for grid index feature
gridIndexFeatures_extent = "landCover.shp"  # extent of the grid index feature
gridIndexFeatures_width = "2000 meters"  # width of each polygon 2000
gridIndexFeatures_hight = "2000 meters"  # hight of each polygon 2000
arcpy.GridIndexFeatures_cartography(gridIndexFeatures,gridIndexFeatures_extent, "INTERSECTFEATURE", "", "",gridIndexFeatures_width, gridIndexFeatures_hight)  # generating the grid index feature
print("%s created based on %s extent." % (gridIndexFeatures, gridIndexFeatures_extent))


arcpy.MakeFeatureLayer_management(gridIndexFeatures, gridIndexFeatures[:-4])
arcpy.SaveToLayerFile_management(gridIndexFeatures[:-4], gridIndexFeatures[:-4])

arcpy.ApplySymbologyFromLayer_management(gridIndexFeatures[:-4], gridIndexFeatures_symbology)

mapdoc = arcpy.mapping.MapDocument(Input_path+Mxd)  # get the map document
dataframes = arcpy.mapping.ListDataFrames(mapdoc,"*")[0]  # get the data frame
dataframes.zoomToSelectedFeatures()  # to make full extent of layout
for lyr in arcpy.mapping.ListLayers(mapdoc,"",dataframes):  # to test if the grid index is available in th mxd or not
    if lyr.name == gridIndexFeatures[:-4]:
         arcpy.mapping.RemoveLayer(dataframes, lyr)  # if it is available, remove it to add an update of it
         print("\nThe %s was already existed and removed from %s" % (gridIndexFeatures[:-4], Mxd))
addLayer = arcpy.mapping.Layer(gridIndexFeatures[:-4])
arcpy.mapping.AddLayer(dataframes, addLayer, "BOTTOM")

for lyr in arcpy.mapping.ListLayers(mapdoc):  # turning off the label
        if lyr.name ==gridIndexFeatures[:-4]:
            lyr.showLabels = False
        else:
            lyr.showLabels = False

mapdoc.save()  # saving the mxd
arcpy.mapping.ExportToTIFF(mapdoc, Input_path+"title.tif")  # exporting the map to tiff, then we can add title and other texts to it
print("New %s added to the %s and symbologies sat." % (gridIndexFeatures[:-4], Mxd))
print("\n%s created." % "title.tif")


#----------------------------------------------------------------------------------------------------------------------
# Part2: adding title and name to the map and exporint it as a title_map.pdf
from reportlab.platypus import SimpleDocTemplate, Paragraph, Image
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import inch


Title_map = Input_path + "title.tif"  # map that created on line 27

doc = SimpleDocTemplate(pdf)  # reading the pdf
styles = getSampleStyleSheet()  # to set style of the paper

Story = []  # the built-up settings

ptext = '<font size=22>AMES Platation Landcover Map by Hunting Units</font>'  # title text
Story.append(Paragraph(ptext, styles["title"]))

im = Image(Title_map, 8.4*inch, 8.4*inch)  # image to be added to the title text
Story.append(im)

ptext = '<font size=16>Created by: Ehsan Momeni</font>'  # creator text
Story.append(Paragraph(ptext, styles["Normal"]))


doc.build(Story)  # building the title_map (final pdf)

#---------------------------------------------------------------------------------------------------------------------
# Part 3: creating a locator map

Locator_pdf = r"C:\Users\emomeni\Locator.pdf"  # output pdf file

for lyr in arcpy.mapping.ListLayers(mapdoc):  # To add label to gird index feature
        if lyr.name ==gridIndexFeatures[:-4]:
            lyr.showLabels = True
        else:
            lyr.showLabels = False

for lyr in arcpy.mapping.ListLayers(mapdoc):  # to label grids 
    if lyr.supports("LABELCLASSES"):
        if lyr.showLabels:
            for lblClass in lyr.labelClasses:
                lblClass.expression = '"<CLR red=\'255\' green=\'0\' blue=\'0\'><FNT size = \'26\'>"&[PageNumber]&"</FNT></CLR>"'
                arcpy.RefreshActiveView()


arcpy.mapping.ExportToTIFF(mapdoc, Input_path+"Locator.tif")  # exporting the map to tiff, then we can add title and other texts to it

Locator_map = Input_path + "Locator.tif"  # map that created on line

doc = SimpleDocTemplate(Locator_pdf)  # reading the pdf
styles = getSampleStyleSheet()  # to set style of the paper

Story = []  # the built-up settings

ptext = '<font size=22>Locator Map</font>'  # title text
Story.append(Paragraph(ptext, styles["title"]))

im = Image(Locator_map, 8.4*inch, 8.4*inch)  # image to be added to the title text
Story.append(im)

doc.build(Story)  # building the title_map (final pdf)

google_scholar1-300x150.png
ResearchGate.png
Ehsan Momeni ORCID GIS Remote Sensing Ur
Ehsan Momeni LinkedIn GIS Remote Sensing
ncbi-300x150.png
academia.png

(Information on this website may not be up to date)

bottom of page