This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Taken from https://gis.stackexchange.com/questions/149959/dissolving-polygons-based-on-attributes-with-python-shapely-fiona | |
from shapely.geometry import shape, mapping | |
from shapely.ops import unary_union | |
import fiona | |
import itertools | |
with fiona.open('cb_2013_us_county_20m.shp') as input: | |
# preserve the schema of the original shapefile, including the crs | |
meta = input.meta | |
with fiona.open('dissolve.shp', 'w', **meta) as output: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Show UnionizeMe's latest expenditures with hledger | |
# https://www.unionizeme.org/donate-now#radical-transparency | |
# http://hledger.org/download (0.27 or greater suggested) | |
default: demo | |
unionizeme.csv: | |
curl -s -o unionizeme.csv 'https://docs.google.com/spreadsheets/d/1l1FoWxseOP07fBMauapG3hIX5DNVooGQTpQQC0sBNv4/export?format=csv&id=1l1FoWxseOP07fBMauapG3hIX5DNVooGQTpQQC0sBNv4&gid=0' | |
unionizeme.csv.rules: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List unique values in a DataFrame column | |
# h/t @makmanalp for the updated syntax! | |
df['Column Name'].unique() | |
# Convert Series datatype to numeric (will error if column has non-numeric values) | |
# h/t @makmanalp | |
pd.to_numeric(df['Column Name']) | |
# Convert Series datatype to numeric, changing non-numeric values to NaN | |
# h/t @makmanalp for the updated syntax! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ipdb | |
import numpy as np | |
import numpy.linalg as nl | |
import matplotlib.pyplot as plt | |
from scipy.spatial.distance import pdist, cdist, squareform | |
def makeT(cp): | |
# cp: [K x 2] control points | |
# T: [(K+3) x (K+3)] | |
K = cp.shape[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Pool | |
import sys | |
import fiona | |
from fiona.transform import transform_geom | |
from shapely.geometry import mapping, shape | |
import json | |
def reproject(f, srs_crs, dest_crs): | |
f['geometry'] = transform_geom(srs_crs, dest_crs, f['geometry'], | |
antimeridian_cutting=True, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from geojson import utils, Feature, FeatureCollection | |
import random | |
import json | |
group = [] | |
for i in range(0, 1000): | |
feature = utils.generate_random(featureType='Point', numberFeatures=1, boundingBox=[144,-37,146,-38.5]) | |
cartons = random.randrange(0, 3000) | |
rev = random.randrange(0, 30000) | |
newFeat = Feature(geometry=feature, properties={"cartons": cartons, "revenue": rev}) |