Skip to content

Instantly share code, notes, and snippets.

@cindygis
cindygis / viewAGSDataStoreDatabases.py
Created March 23, 2015 09:19
Prints the list of databases registered with the given ArcGIS Server, along with the connection properties (excluding ENCRYPTED_PASSWORD).
#
# @date 23/03/2015
# @author Cindy Williams
#
# Prints the list of databases registered with the
# given ArcGIS Server, along with the connection
# properties (excluding ENCRYPTED_PASSWORD).
#
# For use in the Python window in ArcCatalog.
#
@cindygis
cindygis / generateChainageAlongLineFeatures.py
Created March 25, 2015 08:59
Generates chainage at a set distance along line features and saves it to an existing, empty point feature class.
#
# @date 27/11/2014
# @author Cindy Williams
#
# Generates chainage at a set distance along line features
# and saves it to an existing, empty point feature class.
# The point feature class should have a predefined schema
# in case other attributes need to be transferred.
#
# For use as a standalone script.
@cindygis
cindygis / getDiffApplySelect.py
Last active August 29, 2015 14:17
Gets the difference between two lists of SGs and applies a feature selection containing the difference
drak = [row[0] for row in arcpy.da.SearchCursor("DSG", "SG21Code")]
sga = [row[0] for row in arcpy.da.SearchCursor("SGA", "SGA.ID")]
lr_diff = lambda l, r: list(set(l).difference(r))
rest = lr_diff(sga, drak)
qry = """ SGA.ID IN (\'""" + "\', \'".join(rest) + "\')"
arcpy.management.SelectLayerByAttribute("SGA","NEW_SELECTION", qry)
@cindygis
cindygis / projectFtrsForWeb.py
Last active August 29, 2015 14:17
Projects feature classes to Web Mercator (Auxiliary Sphere) if they are not in it already.
#
# @date 24/03/2015
# @author Cindy Williams
#
# Projects feature classes to Web Mercator (Auxiliary Sphere)
# if they are not in it already.
#
# For use as a standalone script.
#
@cindygis
cindygis / replaceLayerSources.py
Created March 25, 2015 18:16
Replace data sources of layers in a map document using two different methods.
#
# @date 25/03/2015
# @author Cindy Williams
#
# Replace data sources of layers in a mxd using
# two different methods.
#
# For use in the Python window in ArcMap.
#
@cindygis
cindygis / Adding outputs to map.md
Last active August 29, 2015 14:18
Preventing intermediate geoprocessing results from being added to the data frame in ArcMap

When forced to run a script in the Python window in ArcMap, or when it's easier to do so, change the environmental setting to prevent the intermediate layers from being added to the TOC.

######arcpy.env.addOutputsToMap = False

Change it back to True when you want the result to be added e.g

arcpy.env.workspace = r"C:\Some\Arb\Folder\work.gdb"
arcpy.env.addOutputsToMap = False
ftr_list = [arcpy.management.MakeFeatureLayer(ftr) for ftr in arcpy.ListFeatureClasses()]
@cindygis
cindygis / convertVarcharToGeometry.sql
Last active August 29, 2015 14:18
Spatially enables a table in SQL that contains valid coordinates, to create a spatial view for use in ArcMap.
SELECT GIS_ID, GEOMETRY::STPointFromText('POINT(' + CONVERT(varchar(50), Longitude) + ' ' + CONVERT(varchar(50), Latitude) + ' )', 4326) AS Location
FROM tbl_random
WHERE Longitude > 0 # Checks if there are valid coordinates for Eastern Hemisphere
# This is a script that I use to convert geojson to
# features in a file gdb
# Step 1. Use the REST page of an ArcGIS Map Service to
# get the esri json results of the data you want.
# Step 2. I used my EsriJSON to GeoJSON app to convert
# the results to geojson. http://esritogeo.herokuapp.com/
# Step 3. In ArcMap, use the python window to create a
# python dictionary of your geojson.
# Step4. Use the following script to convert that geojson
# into featureclasses and then merge them.
@cindygis
cindygis / outputPointsFromLineToFTR.py
Last active August 29, 2015 14:18
Creates a point feature class for points derived from polyline methods
#
# @date 01/04/2015
# @author Cindy Williams
#
# Creates a point feature class for points derived from
# various polyline methods. This example uses polyline.firstPoint
# but can be replaced with any of the polyline methods which
# generate points.
#
# For use as a standalone script.
@cindygis
cindygis / writeFeatureClassToCSV.py
Last active August 29, 2015 14:19
Writes the contents of a feature class to csv
#
# @date 16/04/2015
# @author Cindy Williams
#
# Writes the contents of a feature class to csv.
# Writing to csv is usually used when quickly
# needing to give file contents to a non-GIS
# person, or in creating a GIS inventory.
#
# For use as a standalone script.