Skip to content

Instantly share code, notes, and snippets.

View dandye's full-sized avatar

DanDye dandye

View GitHub Profile
@dandye
dandye / fiona_bare_bones.py
Created March 27, 2012 00:13
Bare Bones Fiona Polygon
SCHEMA = {'geometry': 'Polygon', 'properties': {'name': 'str','token': 'str'}}
FEATURE = {'id': '1',
'geometry':
{'type': 'Polygon',
'coordinates': [[(-1.0, -1.0),
(-1.0, 1.0),
(1.0, 1.0),
(1.0, -1.0),
(-1.0, -1.0)]]
},
import gdal2tiles
for zoom in range(3):
west = -179.99
north = 89.99
print "---\nzoom %s" % zoom
gg = gdal2tiles.GlobalGeodetic()
sm = gdal2tiles.GlobalMercator()
tx,ty = gg.LatLonToTile(north, west, zoom)
print 'TMS tx,ty = %s, %s' % (str(tx),str(ty))
@dandye
dandye / multi_render_states.py
Created June 8, 2012 19:17
multi-process shell scripts
import os,sys
import glob
from multiprocessing import Pool
def f(sh):
print sh
os.system(sh)
shs = glob.glob("/mnt/tiger/TIGER2011/wg_fips/tl_2011_*/state_render.sh")
cmds = [open(x).read() for x in shs]
@dandye
dandye / Sample GeoJSON
Created June 11, 2012 21:05
Sample GeoJSON
{
"type" : "FeatureCollection",
"name" : "NewFeatureType",
"features" : [{
"geometry" : {
"type" : "Polygon",
"coordinates" : [[[-97.976886, 33.972862], [-97.48453699999999, 33.972862], [-97.48453699999999, 33.43381899999999], [-97.976886, 33.43381899999999], [-97.976886, 33.972862]]]
},
"type" : "Feature",
"properties" : {
@dandye
dandye / SHP2GeoJSON
Created June 11, 2012 21:07
SHP2GeoJSON
import os,sys
import glob
import json
#
import fiona
shps = glob.glob("./*/*.shp")
for shp in shps:
#head,tail = os.path.split(shp)
@dandye
dandye / walk4counties.py
Created June 18, 2012 14:48
Search for FIPS codes and create files_list.txt files.
import os,sys
import re
counties = [x.strip() for x in open("/mnt/tiger/counties_fips_list.txt").readlines()]
for county in counties:
of = open("/mnt/tiger/TIGER2011/wg_fips/tl_2011_{}/files_list.txt".format(county),"w")
for threetuple in os.walk("/mnt/tiger/TIGER2011/"):
for filename in threetuple[-1]:
@dandye
dandye / mk_county_toc.py
Created June 18, 2012 15:31
Create WeoGeoTableOfContents.json file for each FIPS code.
import os,sys
import math
import json
# 3rd party libs
import fiona
def get_s_swaths():
extent = 20037508.342789244
s_swaths = []
for cnt in range(30):
state_abbrev2fips = {
'WA': '53', 'DE': '10', 'DC': '11', 'WI': '55', 'WV': '54', 'HI': '15',
'FL': '12', 'WY': '56', 'PR': '72', 'NJ': '34', 'NM': '35', 'TX': '48',
'LA': '22', 'NC': '37', 'ND': '38', 'NE': '31', 'TN': '47', 'NY': '36',
'PA': '42', 'AK': '02', 'NV': '32', 'NH': '33', 'VA': '51', 'CO': '08',
'CA': '06', 'AL': '01', 'AR': '05', 'VT': '50', 'IL': '17', 'GA': '13',
'IN': '18', 'IA': '19', 'MA': '25', 'AZ': '04', 'ID': '16', 'CT': '09',
'ME': '23', 'MD': '24', 'OK': '40', 'OH': '39', 'UT': '49', 'MO': '29',
'MN': '27', 'MI': '26', 'RI': '44', 'KS': '20', 'MT': '30', 'MS': '28',
'SC': '45', 'KY': '21', 'OR': '41', 'SD': '46'
@dandye
dandye / WetSaw pre-requisites.sh
Created July 9, 2012 20:55
WetSaw pre-requisites
# instantiate ami-1ae33d07 as micro instace and then ssh to the instance
# install post-release updates
sudo yum -y update
# Network tools
sudo yum -y install ssh*
# Dev Tools
sudo yum groupinstall -y 'Development Tools'
# Python and spatial stuff
sudo yum -y install python-devel gdal gdal-python gdal-devel python-setuptools proj-epsg
# Mapnik and friends
@dandye
dandye / get_counties.py
Created July 9, 2012 21:30
divide data among multiple wetsaws
import os,sys
def get_fips():
lines = open("counties_fips_list.txt").readlines()
fips = [line.strip() for line in lines]
return fips
if __name__ == "__main__":
wetsawn = sys.argv[1] # pass the wetsaw # as an argument
fips = get_fips()