Skip to content

Instantly share code, notes, and snippets.

Ryan Cooper maptastik

View GitHub Profile
View ubuntu-resolve-host.md

On Ubuntu-flavored Linux distros, there appears to be a bug where when trying to access a URL, the browser gets hung up with a Resolving host... message for a long time. Sometimes the request will just stop and then maybe after a little while longer, the page will load. This seems to have been documented going back a couple major versions of Ubuntu and while there are several workarounds, the one that I found here worked for me:

$ sudo ls -la /etc/resolv.conf
> lrwxrwxrwx 1 root root 29 mar 7 20:20 /etc/resolv.conf -> ../run/resolvconf/stub-resolv.conf
$ sudo rm -f /etc/resolv.conf
$ sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
$ sudo ls -la /etc/resolv.conf
lrwxrwxrwx 1 root root 32 mar 8 07:30 /etc/resolv.conf -> /run/systemd/resolve/resolv.conf
View poly_xy_field.py
import arcpy
# Assume a feature class called polygon_fc with two separate float/double fields, x and y
with arcpy.da.UpdateCursor('polygon_fc', ['SHAPE@', 'x', 'y']) as cursor:
for row in cursor:
geom_4326 = row[0].projectAs(arcpy.SpatialReference(4326))
row[1] = geom_4326.centroid.X
row[2] = geom_4326.centroid.Y
cursor.updateRow(row)
@maptastik
maptastik / arcgis_to_csv.py
Created Nov 26, 2019
A quick method for writing out some rows and a subset of columns from a feature class to a CSV. This is particularly well-suited for when you're working in ArcGIS Desktop or Pro and need to quickly export some rows and a subset of columns from a vect
View arcgis_to_csv.py
import arcpy
import csv
with open('output.csv', 'w', newline = '') as csvfile:
writer = csv.writer(csvfile) # Create writer object
writer.writerow(['Column 1', 'Column 2', 'Column 3', 'Column 4']) # Define the header row
with arcpy.da.SearchCursor('input_layer', ['Field1', 'Field2', 'Field3', 'Field4']) as cursor: # Define cursor object
for row in cursor:
writer.writerow([row[0], row[1], row[2], row[3]]) # Write values from each item in cursor to csv
@maptastik
maptastik / geojson_csv_join.bat
Created Nov 22, 2019
An example of an ETL script that allows you to query a remote spatial data source and join the query result with a CSV. For now, this requires csvs-to-sqlite as ogr2ogr doesn't seem to like working with CSVs with the SQLite dialect for SQL queries. O
View geojson_csv_join.bat
csvs-to-sqlite tbl.csv tbl.db && \
curl "<URL to enpoint and/or query that returns GeoJSON>" | \
ogr2ogr -f geojson -nln input /vsistdout/ /vsistdin/ | \
ogr2ogr -f geojson \
-dialect sqlite \
-sql "select input.*, tbl.* from inputjoin 'tbl.db'.tbl AS tbl on input.<primary key> = tbl.<foreign key>" \
output.geojson /vsistdin/ && \
del tbl.db
@maptastik
maptastik / ebpa_routes_sample.geojson
Created Oct 28, 2019
EBPA sample routes for a single census block
View ebpa_routes_sample.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@maptastik
maptastik / citrix_bike_routes_sample10.geojson
Last active Oct 28, 2019
Sample Citrix Cycle route data
View citrix_bike_routes_sample10.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View gif2mp4_h264.bat
ffmpeg -i animated.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video.mp4
View calculate_pd_column_from_other_columns.py
import pandas as pd
df = pd.DataFrame({'a': [1,2,3], 'b': [2,3,4], 'c':['dd','ee','ff'], 'd':[5,9,1]})
df['e'] = df[['a', 'b', 'd']].sum(axis = 1)
#########################
## RESULT ##
#########################
# a b c d e # COLUMNS
# 0 1 2 dd 5 8 # ROW
View quantile_bins.py
def quantile_bins(quantiles, min = 0, max = 100):
"""Return a list of quantiles including floor and ceiling values
Args:
quantile (list): Quantile values in order
min (numeric): Floor value of data range
max (numeric): Ceiling value of data range
Returns:
list: An inclusive list of quantile bin values
View quantile_percentiles.py
def quantile_percentiles(quantile_count: int = 5) -> list:
"""Return quantile percentile values for a given number of quantiles.
Args:
quantile_count (int): Number of quantiles to generate percentile values for (default 5)
Returns:
list: Equally spaced quantile percentile values based on quantile_count
Examples:
You can’t perform that action at this time.