Skip to content

Instantly share code, notes, and snippets.

Ryan Cooper maptastik

Block or report user

Report or block maptastik

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
@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:
View update_table.sql
-- ABOUT -----------------------------------------------------------------------
-- This script is meant to outline a procedure for updating a PostgreSQL table
-- with the latest features even if there are views that depend on the table.
-- In other words, this method allows you to update the table without deleting
-- it and recreating it with the latest data. There are definitely some
-- opportunities for improvement - there may be a bit too much redundancy - but
-- this should get the job done, especially on datasets where size is trivial.
--------------------------------------------------------------------------------
-- NOTES -----------------------------------------------------------------------
View activate_run.bat
rem If you want to open CMD and see your script run
@echo
rem Call activate.bat located for your conda installation
call C:\Users\some_user\AppData\Local\Continuum\Miniconda3\Scripts\activate.bat
rem Activate your environment, change directory to location of your script, run script.
activate some_environment && cd C:\Users\some_user\python_script_directory && python python_script.py
rem I can't remember why I added this...You might not need it.
You can’t perform that action at this time.