Skip to content

Instantly share code, notes, and snippets.

View bixb0012's full-sized avatar

Joshua Bixby bixb0012

View GitHub Profile
@bixb0012
bixb0012 / python_get_file_geodatabase_system_properties.py
Last active May 20, 2017 18:07
Python: Get File Geodatabase System Properties
# Reference: 1) https://docs.python.org/3/library/time.html
# 2) https://docs.python.org/3/library/os.path.html
from time import ctime
from os.path import getmtime, getctime, split
gdb = # Path to file geodatabase
# Example 1: Creation and Modficiation Dates
print "{}\t{}\t{}".format(split(gdb)[1],
@bixb0012
bixb0012 / arcpy_arcmap_create_curved_geometries.py
Last active June 29, 2017 19:51
ArcPy (ArcMap): Create Curved Geometries
# Adapted from http://gis.stackexchange.com/questions/66551/can-arcpy-10-1-be-used-to-generate-true-curve-elliptical-polygons-in-a-file-geod
#
# Reference: 1) http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-functions/asshape.htm
# 2) http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Geometry_Objects/02r3000000n1000000
import arcpy
# Example 1: CIRCULARSTRING(1 5, 6 2, 7 3)
esri_json = {
"curvePaths": [[
@bixb0012
bixb0012 / arcpy_arcmap_list_geodatabases_in_database.py
Last active June 29, 2017 19:53
ArcPy (ArcMap): Get List of Geodatabases in Database
# Adapted from http://stackoverflow.com/questions/18141547/display-all-the-names-of-databases-containing-particular-table
#
# Reference: 1) http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/create-database-connection.htm
# 2) http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-classes/arcsdesqlexecute.htm
import arcpy
conn_path = # Output folder for database connection file
conn_name = # Output name of database connection file, including .sde extension
@bixb0012
bixb0012 / python3_generate_english_word_list.py
Last active February 6, 2019 15:19
Python3: Generate English Word List
#!python3
# Reference: 1) https://www.gutenberg.org/ebooks/29765
# Reference: 2) https://wordnet.princeton.edu/download/current-version
from itertools import dropwhile, takewhile
import re
import urllib.request
# Example 1: Project Gutenberg's Webster's Unabridged Dictionary (Webster's Dictionary 1913)
url = r"https://www.gutenberg.org/cache/epub/29765/pg29765.txt"
@bixb0012
bixb0012 / python_lazy_counters.py
Last active July 30, 2019 23:45
Python: Lazy Counters
#!python
# Reference: 1) https://docs.python.org/3/library/collections.html#collections.defaultdict
# Reference: 2) https://www.python.org/dev/peps/pep-0342/
from collections import defaultdict
# Example 1: Using coroutine via generator for multivalue counter
def multi_counter_generator():
cnt = defaultdict(int)
incr = yield cnt.items()
@bixb0012
bixb0012 / arcpy_pro_look_ahead_cursor.py
Last active July 31, 2019 17:46
ArcPy (Pro): Look-Ahead Cursor
#!python3
# Reference: 1) https://pro.arcgis.com/en/pro-app/arcpy/data-access/searchcursor-class.htm
# 2) https://pro.arcgis.com/en/pro-app/arcpy/data-access/updatecursor-class.htm
# 3) https://docs.python.org/3/library/itertools.html
import arcpy
from itertools import chain, zip_longest, tee
fc = # Path to feature class or name of feature layer
flds = # Fields to include in cursor
@bixb0012
bixb0012 / python_data_stream_sampling.py
Last active July 31, 2019 17:47
Python: Data-Stream Sampling
#!python
# Background https://www.springer.com/cda/content/document/cda_downloaddocument/9783540286073-c2.pdf
# Example 1 adapted from https://stackoverflow.com/questions/12581437/python-random-sample-with-a-generator-iterable-iterator/
#
# Reference: 1) https://docs.python.org/3/library/functions.html
# 2) https://docs.python.org/3/library/itertools.html
# 3) https://docs.python.org/3/library/random.html
from itertools import islice
from random import randint
@bixb0012
bixb0012 / arcpy_remove_holes_in_polygons.py
Last active July 31, 2019 17:55
ArcPy: Remove Holes in Polygons
#!python
# Reference: 1) https://pro.arcgis.com/en/pro-app/arcpy/classes/spatialreference.htm
# 2) https://pro.arcgis.com/en/pro-app/arcpy/classes/array.htm
# 3) https://pro.arcgis.com/en/pro-app/arcpy/classes/polygon.htm
# 4) https://pro.arcgis.com/en/pro-app/arcpy/data-access/updatecursor-class.htm
# 5) https://docs.python.org/3/library/itertools.html
import arcpy
from itertools import takewhile
@bixb0012
bixb0012 / arcpy_create_latitude_and_longitude_lines.py
Last active July 31, 2019 18:05
ArcPy: Create Latitude and Longitude Lines
#!python
# Reference: 1) https://pro.arcgis.com/en/pro-app/arcpy/classes/spatialreference.htm
# 2) https://pro.arcgis.com/en/pro-app/arcpy/classes/array.htm
# 3) https://pro.arcgis.com/en/pro-app/arcpy/classes/point.htm
# 4) https://pro.arcgis.com/en/pro-app/arcpy/classes/polyline.htm
import arcpy
SR = arcpy.SpatialReference(4326)
interval = 5 # Interval of latitude and longitude lines, multiple of 1 degree
@bixb0012
bixb0012 / python_dictionary_of_wkt_test_geometries.py
Last active July 31, 2019 18:10
Python: Dictionary of WKT Test Geometries
#!python
# Reference: 1) https://www.opengeospatial.org/standards/sfa
geoms = {
'pt': 'POINT(10 10)',
'ept': 'POINT EMPTY',
'mpt': 'MULTIPOINT((15 15), (25 15))',
'empt': 'MULTIPOINT EMPTY',
'ln': 'LINESTRING(20 20, 30 30)',
'eln': 'LINESTRING EMPTY',