Skip to content

Instantly share code, notes, and snippets.

@cindygis
cindygis / createRandomPointsInPoly.py
Last active October 14, 2015 06:29
Creates random points in each polygon feature. Bypasses the Advanced licence needed to run the Create Random Points tool in ArcMap.
#
# @date 06/08/2015
# @author Cindy Williams
#
# Creates random points in each polygon feature
# without the need for an Advanced licence to run
# the Create Random Points tool.
#
# For use in the Python window in ArcCatalog.
#
@cindygis
cindygis / segmentLineByMeasures.py
Last active August 29, 2015 14:26
Creates segments along a selected line feature by splitting it according to a table of measures and saving it in a new feature class.
#
# @date 04/08/2015
# @author Cindy Williams
#
# Creates segments along a selected line feature
# by splitting it according to a table of measures
# and saving it in a new feature class.
#
# For use as a standalone script.
#
@cindygis
cindygis / convertSheetsAndDisplayXY.py
Created July 28, 2015 07:10
Converts all the sheets in a spreadsheet to file gdb tables and displays the XY coordinates in ArcMap.
#
# @date 28/07/2015
# @author Cindy Williams
#
# Converts all the sheets in a spreadsheet
# to file gdb tables and displays the XY
# coordinates in ArcMap.
#
# Assumes the spreadsheet has been formatted
# according to GIS standards.
@cindygis
cindygis / autoIncrementUniqueID.py
Created July 14, 2015 18:51
Populates the next highest numbers for a feature class based on the previous max
import arcpy
lyr = arcpy.management.MakeFeatureLayer(r"C:\Some\Arb\Folder\work.gdb\ftr_wrp_Pipe")
field = "GIS_ID"
def getWhereQry(exp):
return """ "{0}" IS {1} """.format(field, exp)
# Gets the previous highest GIS ID value. Set n = 0 for new feature class
n = max(int(row[0].split("-")[1]) for row in arcpy.da.SearchCursor(lyr, field, where_clause=getWhereQry("NOT NULL")))
@cindygis
cindygis / sortFeatureClassByExtent.py
Created July 14, 2015 18:28
Sorts a polygon feature class by descending X and ascending Y, to obtain the spatial order of the polys from left to right, top to bottom. Bypasses the Advanced licence needed to do this in the Sort tool.
#
# @date 13/07/2015
# @author Cindy Williams
#
# Sorts a polygon feature class by descending X and ascending Y,
# to obtain the spatial order of the polys from left to right,
# top to bottom. Bypasses the Advanced licence needed to
# do this in the Sort tool.
#
# For use in the Python window in ArcMap.
@cindygis
cindygis / selectVisibleFeaturesForDDPExport.py
Last active August 29, 2015 14:24
Intersects feature layers with the index layer for selected data driven export to a multi-page PDF with embedded layers.
#
# @date 13/07/2015
# @author Cindy Williams
#
# Intersects feature layers with the index layer
# for selected data driven export to a multi-page
# PDF with embedded layers.
#
# For use as a standalone script.
#
@cindygis
cindygis / createAssetFolderStructure.py
Created July 13, 2015 16:45
Creates the folder structure for asset management GIS data. Must still be optimised
import os
folder_assetarea = r"C:\Assets\AreaA" # The main folder for Area A
year = "2015" # The year to create the structure for
folder_year = os.path.join(fld_mun, year)
folder_list = [["conversion", ["cad_gis", "ftr_shp", "kml_gdb",
"pdf_jpg", "shp_gdb", "tbl_xls",
"xls_tbl",] "jpg_gis", "gps_gis",
@cindygis
cindygis / createRandomPointsAsJSON.py
Created July 9, 2015 07:55
Creates a point feature class in memory containing random points within a predefined extent, and posts the points as ESRI JSON to a REST endpoint.
#
# @date 13/05/2015
# @author Cindy Williams
#
# Creates a point feature class in memory containing
# random points within a predefined extent, and posts
# the points as ESRI JSON to a REST endpoint.
#
# For use as a standalone script
#
@cindygis
cindygis / sortArcMapTOC.py
Created July 3, 2015 06:32
Sorts the TOC in ArcMap alphabetically by using a temporary group layer for reference.
#
# @date 03/07/2015
# @author Cindy Williams
#
# Sorts the TOC in ArcMap alphabetically using
# a temporary group layer for reference. This group
# layer should be empty, and can be created anywhere
# in the TOC.
#
# For use in the Python window in ArcMap.
@cindygis
cindygis / genAttachmentMatchTable.py
Created July 1, 2015 09:32
Generates a file gdb table containing the paths of photos to be attached to matching points as feature attachments..
#
# @date 01/07/2015
# @author Cindy Williams
#
# Generates a file gdb table containing the paths
# of photos to be attached to matching points as feature
# attachments.
#
# For use as a standalone script.
#