Skip to content

Instantly share code, notes, and snippets.

Avatar

Jesse Crocker JesseCrocker

View GitHub Profile
@JesseCrocker
JesseCrocker / ogr_value_summary.py
Created Oct 27, 2017
Print summary of string fields and values from a shapefile(or anything else OGR can read)
View ogr_value_summary.py
#!/usr/bin/env python
import logging
from optparse import OptionParser
import os
from osgeo import ogr
def log_file_fields(filename):
print("File: " + filename)
source = ogr.Open(filename)
@JesseCrocker
JesseCrocker / load.py
Created Oct 19, 2017
Load AWS ALB logs into a postgres database for analysis.
View load.py
#!/usr/bin/env python3
import os
import psycopg2
import re
import sys
from urllib.parse import urlparse
try:
conn = psycopg2.connect(dbname=os.environ.get("DB"), user=os.environ.get("DB_USER"), host=os.environ.get("DB_HOST"))
@JesseCrocker
JesseCrocker / cleanup_edges.py
Created May 30, 2017
Set any pixels adjacent to a nodata pixel to nodata
View cleanup_edges.py
#!/usr/bin/env python
import numpy
import sys
import gdal
def cleanup_edges(source, nodata_value, mask_filename="mask.tiff"):
band_data = source.GetRasterBand(1).ReadAsArray()
y_size, x_size = band_data.shape
@JesseCrocker
JesseCrocker / profile-source.py
Last active May 16, 2017
Profile a tm2source for slow queries
View profile-source.py
#!/usr/bin/env python
import logging
from optparse import OptionParser
import os
import sys
import mercantile
import psycopg2
import yaml
@JesseCrocker
JesseCrocker / test.py
Created Apr 14, 2017
fiona gdalwarp error test case
View test.py
#!/usr/bin/env python
import subprocess
def _main():
source_image = "source.tiff"
subprocess.call("gdalwarp -t_srs epsg:3857 -r cubic " + source_image + " pre-import.tiff", shell=True)
import fiona
subprocess.call("gdalwarp -t_srs epsg:3857 -r cubic " + source_image + " post-import.tiff", shell=True)
View StyleTemplate.json
{
"version": 8,
"name": "OpenHuntingData",
"center": [
-118.291995,
36.578581
],
"zoom": 12,
"bearing": 0,
"pitch": 0,
@JesseCrocker
JesseCrocker / set_s3_metadata.py
Last active Mar 31, 2017
Bulk update metadata on s3 keys
View set_s3_metadata.py
#!/usr/bin/env python
import logging
from optparse import OptionParser
import os
from urlparse import urlparse
from boto.s3.connection import S3Connection
def _main():
@JesseCrocker
JesseCrocker / sort_last_token.py
Last active Mar 14, 2017
Sort lines by last word
View sort_last_token.py
#!/usr/bin/env python
import sys
seperator = " "
def getLastToken(item):
return item.split(seperator)[-1].replace("*", "")
lines = []
for line in sys.stdin:
@JesseCrocker
JesseCrocker / betterthanboto.py
Last active Feb 21, 2017 — forked from mekza/betterthanboto.py
Signed URLs and Signed Cookies for CloudFront in Python with boto
View betterthanboto.py
from boto.cloudfront.distribution import Distribution
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
import base64
class BetterThanBoto(Distribution):
def sign_rsa(self, message):
@JesseCrocker
JesseCrocker / process.sh
Created Feb 15, 2017
Process USFS motor vehicle use data into vector tiles
View process.sh
#!/bin/bash
set -e -u
wget https://data.fs.usda.gov/geodata/edw/edw_resources/shp/S_USA.Road_MVUM.zip
wget https://data.fs.usda.gov/geodata/edw/edw_resources/shp/S_USA.Trail_MVUM.zip
unzip S_USA.Road_MVUM.zip
unzip S_USA.Trail_MVUM.zip
TRAILS_MBTILES=`pwd`/trails.mbtiles
ROADS_MBTILES=`pwd`/roads.mbtile