Skip to content

Instantly share code, notes, and snippets.

@cindygis
cindygis / exportDDPtoJPEG.py
Created March 25, 2015 09:11
Basic export of data driven pages to multiple jpegs
import arcpy
import os
mxd = arcpy.mapping.MapDocument(r"C:\Some\Arb\Folder\Test.mxd")
fld = r"C:\Some\Arb\Folder\jpegs"
ddp = mxd.dataDrivenPages
for i in range(1, ddp.pageCount + 1):
ddp.currentPageId = i
name = os.path.join(fld, ddp.pageRow.getValue(ddp.pageNameField) + ".jpg")
@cindygis
cindygis / convertListToCVD.py
Last active July 29, 2018 11:06
Extracts a unique list of values from an attribute table and converts it into an coded value domain.
#
# @date 31/05/2013
# @author Cindy Williams
#
# Extracts a unique list of values from an attribute table
# and converts it into an coded value domain.
#
# For use as a script tool in an ArcGIS Toolbox.
#
#
# @author Cindy Jayakumar
# @date 21/07/2018
#
# Extract domains from a field in one feature class, and apply
# it to matching fields in another feature class.
#
import arcpy
@cindygis
cindygis / attachGoogleMapsURL.py
Created May 2, 2018 11:50
Adds a field to a point feature class containing a link to launch Google Maps with directions from the current location of the device to the destination point.
#
# @author Cindy Jayakumar
#
# @date 12/05/2018
#
# Adds a field to a point feature class containing a link
# to launch Google Maps with directions from the current
# location of the device to the destination point.
#
# Can be used for navigating to sites while in the field,
@cindygis
cindygis / splitLineAtInteractivePoint.py
Created October 6, 2015 13:39
Uses an arcpy FeatureSet to allow the user to interactively create points on a line which will be used to split that line into parts, while retaining all attributes.
'''
@date 06/10/2015
@author Cindy Williams
@version 1.0
Uses an arcpy FeatureSet to allow the user to interactively create
points on a line which will be used to split that line into parts,
while retaining all attributes.
Requirements:
@cindygis
cindygis / getUniqueFieldValues.py
Created November 15, 2017 12:56
Methods to get a unique list of values from a field in a feature class
import arcpy as ap
import numpy as np
import timeit
lyr = ap.mapping.Layer(r"C:\Some\Arb\Folder\test.gdb\test")
field_name = "NAME"
# Method 1: Python
unique_values = list(set(row[0] for row in ap.da.SearchCursor(lyr, field_name)))
@cindygis
cindygis / alterCamelCaseAlias.py
Last active October 5, 2017 05:54
How to insert a space between camel case, lest I ever forget again
#
# @date 05/10/2017
# @author Cindy Jayakumar
#
# Change the alias of feature classes to the
# title case version of the CamelCase name
#
# e.g. WaterPumpStation => Water Pump Station
import arcpy
@cindygis
cindygis / convertMultiPagePDFtoTIFF.py
Created August 18, 2015 07:47
Converts a range of pages from a pdf to separate tiff files using the PDF to TIFF tool added at ArcGIS 10.3.
#
# @date 18/08/2015
# @author Cindy Williams
#
# Converts a range of pages from a pdf to separate tiff
# files using the PDF to TIFF tool added at ArcGIS 10.3.
# For very basic conversion, with minimal error handling.
#
# For use as a standalone script.
#

http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/make-query-table.htm

When inputting the optional SQL clause, ArcGIS automatically adds quotation marks "" to the field names in the dialog box. This will pass the tool's error checking successfully but will cause the tool to fail with an error.

If you verify the SQL clause in the dialog box, it will give a SQL error with no specifics. When adding the clause, remember to remove the quotation marks.

e.g. If you want to join Layer1 to Layer 2 on common field ID and where Layer 1 contains "Cape Town", ArcGIS will format your expression in the following way:

@cindygis
cindygis / duplicatePoint.py
Created February 9, 2017 09:24
Uses the geometry of a selected point in one layer to insert new points with selected attributes from a different layer.
'''
@author Cindy Jayakumar
@date 31/01/2017
- Inserts a new point with the selected geometry in to_lyr
- Adds attributes to that point from from_lyr
- Updates the record in from_lyr
Uses selected features