Here is the code:
def make_map(wl_id, well_label_text, well_label_nbr, well_label_lat_dd , well_label_long_dd , x_coord , y_coord, trsqq_key , address_of_well , submitted_by , location_source 😞
# ----------- IMPORTS ----------------------------------------------------------
import datetime, sys, arcpy, os, shutil, time
# ------------------------------------------------------------------------------------
#===================================================================
# PATHNAMES AND OTHER VARIABLES
#===================================================================
blah, blah
#===================================================================
# CREATE POINT
#===================================================================
spatialRef = arcpy.Describe(dataset).spatialReference
if arcpy.Exists(temp_well_point):
arcpy.Delete_management(temp_well_point)
print "Old version of well point was deleted."
ptx = float(x_coord)
pty = float(y_coord)
well_point = arcpy.Point(ptx, pty)
pointGeometry = arcpy.PointGeometry(well_point, spatialRef)
logfile.write("\n... Geometry of point is created...\n")
arcpy.CopyFeatures_management(pointGeometry, temp_well_point)
arcpy.AddField_management(temp_well_point, "MAP_LABEL", "TEXT", "", "", 20)
map_label = "\"" + well_label_nbr + "\""
arcpy.CalculateField_management(temp_well_point, "MAP_LABEL", map_label, "PYTHON")
#===================================================================
# CREATE MAP
#===================================================================
# Process: Delete pre-existing png...
if os.path.exists(well_location_map):
os.remove(well_location_map)
# .... Change the extent to the selected area ...
df = arcpy.mapping.ListDataFrames(well_mxd,"Layers") [0]
newExtent = df.extent
newExtent.XMin, newExtent.YMin = xmin, ymin
newExtent.XMax, newExtent.YMax = xmax, ymax
df.panToExtent(newExtent)
#... Add the Layer and Change the Cartography .....
wellLayer = arcpy.mapping.Layer(well_layer)
wellLayer.replaceDataSource(workspace_temp, "SHAPEFILE_WORKSPACE", wl_id)
arcpy.mapping.AddLayer(df, wellLayer, "TOP")
wellLayer.showLabels = True
# change the text of the map
for elm in arcpy.mapping.ListLayoutElements(well_mxd, "TEXT_ELEMENT"):
if elm.text == "latitude_text":
elm.text = lat_line
if elm.text == "longitude_text":
elm.text = long_line
if elm.text == "trsqq_text":
elm.text = trsqq_line
if elm.text == "well_label":
elm.text = well_label_line
if elm.text == "address_of_well_text":
elm.text = address_of_well_line
if elm.text == "source_text":
elm.text = location_source
# ... refresh the map .....
arcpy.RefreshActiveView()
arcpy.mapping.ExportToPNG(well_mxd, well_location_map)
#===================================================================
# CLEANUP
#===================================================================
# ended up deleting the temp point to get rid of the locked files.
# in other applications, I may not want to do this.
#---------------------------------------------------------------------------------------------------------------------
if arcpy.Exists(temp_well_point):
arcpy.Delete_management(temp_well_point)
del well_mxd
del arcpy