Skip to content

Instantly share code, notes, and snippets.

#
# @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 / 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

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
@cindygis
cindygis / changeDelimiterInCSV.py
Created July 19, 2016 07:57
Replaces the delimiter in a csv file
'''
@date 19/07/2016
@author Cindy Williams-Jayakumar
Replaces the delimiter in a csv file
using the pathlib library in Python 3
'''
import csv
@cindygis
cindygis / createTableFieldsFromXLS.py
Created May 5, 2016 05:50
Converts a spreadsheet containing field names and aliases into a file geodatabase table.
'''
@date 09/07/2013
@author Cindy Williams
Converts a spreadsheet containing field names and aliases
into a file geodatabase table.
'''
import arcpy
xls = r"C:\Some\Arb\Folder\test.xlsx\Fields$"
@cindygis
cindygis / reverseGeocodeXLScoords.py
Created April 21, 2016 08:05
Quickly reverse geocode coordinates in a spreadsheet
import geocoder
import pandas as pd
xls = r'C:\Some\Arb\Folder\coords.xls'
out_xls = r'C:\Some\Arb\Folder\geocoded.xls'
df = pd.read_excel(xls)
for index, row in df.iterrows():
g = geocoder.google([row[3], row[2]], method='reverse')
df.set_value(index, 'Street Address', g.address)
@cindygis
cindygis / filterDataFrameUsingMask.py
Created December 17, 2015 10:09
Filters a pandas data frame using a mask
import pandas as pd
in_xls = r"C:\Some\Arb\Folder\test.xlsx"
columns = [0, 2, 3, 4, 6, 8]
# Use a function to define the mask
# to create a subset of the data frame
def mask(df, key, value):
return df[df[key] == value]