Skip to content

Instantly share code, notes, and snippets.

View sdearmond's full-sized avatar

Shannon DeArmond sdearmond

View GitHub Profile
@sdearmond
sdearmond / arcpy_exportSequentialImages.py
Created June 1, 2017 06:07
Exports sequential images of time-enabled ArcMap mxd.
import arcpy, os
outDir= r'C:\MyImageFolder'
mxdPath = r'C:\MyMap.mxd'
mxd = arcpy.mapping.MapDocument(mxdPath)
df = mxd.activeDataFrame
counter = 0
myTime = df.time.startTime
#Import python libraries
import arcpy, os
from PyPDF2 import PdfFileWriter, PdfFileReader
#Creates two empty pdf documents
print("Creating pdf document")
myPDFPath = r'C:\MyNewFile.pdf'
myPDFPathArcGIS = os.path.join(os.path.dirname(myPDFPath),'My_Temporary_File.pdf')
myPDFArcGIS = arcpy.mapping.PDFDocumentCreate(myPDFPathArcGIS)
def sequentialByX(lyr, orderFld):
#'lyr' is the name of your layer in ArcMap
#'orderFld' is the name of the field that you want to populate with sequential numbers
#First let's get a list of x coordinates and the corresponding objectid
coordLst = []
idFld = arcpy.Describe(lyr).OIDFieldName
rows = arcpy.da.SearchCursor(lyr,["SHAPE@X", idFld])
for row in rows:
coordLst.append([row[0], row[1]])
@sdearmond
sdearmond / assignSequentialNumbers.py
Created June 18, 2016 18:02
Sorting with cursors for the arcpy data access module
def assignSequentialNumbers(lyr, fldID, fldSort):
#lyr = a point layer in your mxd, such as Cities from the example above
#fldID = the field in lyr to which you would like to assign numbers, such as "Rank" in example above
#fldSort = the field in lyr by which you would like to sort, such as "Name" in the example above
with arcpy.da.SearchCursor(lyr, fldSort) as rows:
myLst = []
for row in rows:
myLst.append(row[0])
myLst.sort()
myDict = {}