Skip to content

Instantly share code, notes, and snippets.

Joshua Bixby bixb0012

Block or report user

Report or block bixb0012

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View icon_sisyphean.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bixb0012
bixb0012 / python_lazy_counters.py
Last active Jul 30, 2019
Python: Lazy Counters
View python_lazy_counters.py
#!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 / python3_generate_english_word_list.py
Last active Feb 6, 2019
Python3: Generate English Word List
View python3_generate_english_word_list.py
#!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 / arcpy_pro_look_ahead_cursor.py
Last active Jul 31, 2019
ArcPy (Pro): Look-Ahead Cursor
View arcpy_pro_look_ahead_cursor.py
#!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 Jul 31, 2019
Python: Data-Stream Sampling
View python_data_stream_sampling.py
#!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 Jul 31, 2019
ArcPy: Remove Holes in Polygons
View arcpy_remove_holes_in_polygons.py
#!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_arcmap_modify_layer_symbology_expanded.py
Last active Jul 31, 2019
ArcPy (ArcMap): Modify Layer Symbology, Expanded
View arcpy_arcmap_modify_layer_symbology_expanded.py
#!python2
# Example 1a adapted from https://www.reddit.com/r/gis/comments/4rhvhh/map_automation_arcpymapping_make_lyr/
#
# Reference: 1) http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/layer-class.htm
# 2) https://docs.python.org/2/library/json.html
import arcpy
import json
lyr = # Layer object, typically from arcpy.mapping.ListLayers (arcpy._mapping.Layer)
@bixb0012
bixb0012 / arcpy_create_latitude_and_longitude_lines.py
Last active Jul 31, 2019
ArcPy: Create Latitude and Longitude Lines
View arcpy_create_latitude_and_longitude_lines.py
#!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 Jul 31, 2019
Python: Dictionary of WKT Test Geometries
View python_dictionary_of_wkt_test_geometries.py
#!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',
@bixb0012
bixb0012 / arcpy_add_dataset_property_as_data_attribute.py
Last active Jul 31, 2019
ArcPy: Add Dataset Property as Data Attribute
View arcpy_add_dataset_property_as_data_attribute.py
#!python
# Reference: 1) https://pro.arcgis.com/en/pro-app/arcpy/functions/describe.htm
# 2) https://pro.arcgis.com/en/pro-app/tool-reference/data-management/add-field.htm
# 3) https://pro.arcgis.com/en/pro-app/tool-reference/data-management/calculate-field.htm
import arcpy
# Example 1: Adding path attribute for tables and feature classes in workspace (ArcMap and Pro compatible)
workspace = # Workspace containing feature classes
You can’t perform that action at this time.