Skip to content

Instantly share code, notes, and snippets.

@shakythesherpa
shakythesherpa / gist:68915df352fe278ac480
Created December 17, 2014 16:10
Points to line Distance Calculation using R
# Determine the nearest point on a line for a set of points
#
# input:
# output_dir: where result files will be placed
# point_csv_file: csv of points (with Longitude, Latitude columns)
# line_shape_file: shapefile of lines
#
# output (will all be placed in output_dir):
# points_on_line.csv: for each point in point_csv_file, the closest point to
# a line in line_shape_file
@shakythesherpa
shakythesherpa / crawl.py
Last active August 29, 2015 14:07 — forked from csytan/crawl.py
import csv
import json
import os
import time
import urllib
def load(**kwargs):
url = 'http://booths.nigeriaelections.org/getStuff.php'
@shakythesherpa
shakythesherpa / README.md
Last active August 29, 2015 14:07 — forked from tmcw/README.md
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
try:
import simplejson as json
except:
import json
import re
import requests
dir_url = 'http://api.tiles.mapbox.com/v3/modilabs/maps.json'
map_data = json.load(requests.get(dir_url).text)
nmis_exp = re.compile("Nigeria|nigeria|nmis")
import subprocess
import sys, re
MERC = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs'
infile = sys.argv[1]
info_output = subprocess.Popen(['gdalinfo', infile], stdout=subprocess.PIPE).communicate()[0]
size_is_re = re.compile('Size is (?P<width>\d+), (?P<height>\d+)')
size_is = filter(lambda x: x, map(lambda x: size_is_re.match(x), info_output.split('\n')))
from lxml import etree
import urllib2
import urlparse
import sys
# Prevents this script from failing when output is piped
# to another process
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE,SIG_DFL)

Download and convert data from NYC open data portal

curl -o nynta.zip "https://nycopendata.socrata.com/api/geospatial/cpf4-rkhq?method=export&format=Shapefile"
cd nynta_12c

ogr2ogr can't deal with the projection directly. Replace content of nynta.prj with the following projection string:

PROJCS["NAD_1983_StatePlane_New_York_Long_Island_FIPS_3104_Feet",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["lambert_conformal_conic_2sp"],PARAMETER["False_Easting",984250.0],PARAMETER["False_Northing",0.0],PARAMETER["longitude_of_center",-74.0],PARAMETER["Standard_Parallel_1",40.66666666666666],PARAMETER["Standard_Parallel_2",41.03333333333333],PARAMETER["latitude_of_center",40.16666666666666],UNIT["Foot_US",0.3048006096012192]]