Skip to content

Instantly share code, notes, and snippets.

@paulopperman
paulopperman / extract_od.py
Created December 14, 2019 15:50
an inelegant script to melt state origin/destination data into files for SUMO model
# an inelegant script to melt state data into files for SUMO model
import pandas as pd
def build_od_list(od_file):
od = pd.read_csv(od_file, header=None, index_col=0)
od.columns = od.index
# clean matrix
@paulopperman
paulopperman / random turtle 3d.nlogo3d
Created October 5, 2018 15:05
Random Turtle Walk in 3d
;; extending random walk 2d example into 3d
turtles-own
[
xc ; next x coordinate
yc ; next y coordinate
zc ; next z coordinate
]
to setup
clear-all
import requests
import pandas as pd
# API documentation is at https://www.ncdc.noaa.gov/cdo-web/webservices/v2
NOAA_API_TOKEN = '<from NOAA>'
headers = {'token':NOAA_API_TOKEN}
# get stations in Newport, RI
@paulopperman
paulopperman / get_streetview_image.py
Last active January 4, 2018 16:11
get streetview images of points in a geojson file
import requests
from PIL import Image
from io import BytesIO
import os
import pandas as pd
# get crosswalk dataset
newport_crossings_url = 'https://raw.githubusercontent.com/NewportDataPortal/sidewalk-map/development/npt-sidewalk-street-intersections.geojson'
crossing_response = requests.get(newport_crossings_url)
crossing_json = crossing_response.json()
@paulopperman
paulopperman / simple_streetview.py
Created December 24, 2017 18:20
Basic Google Street View Imagery API calls
import requests
from PIL import Image
from io import BytesIO
import json
url = 'https://maps.googleapis.com/maps/api/streetview'
key = STREETVIEW_API_KEY
out_file = 'streetviewimg.jpg'
@paulopperman
paulopperman / shp2geopandas.py
Last active May 14, 2017 18:36
workaround for importing shapefile into geopandas
import shapefile
import geopandas as gp
def convert_shapefile(filepath, crs=None):
# Function to read an ESRI shapefile and return a geopandas GeoDataFrame
reader = shapefile.Reader(filepath)
# Extract the column names for the data
fields = reader.fields[1:]
field_names = [field[0] for field in fields]
@paulopperman
paulopperman / geopy-geocoding.py
Created April 13, 2017 20:55
Geocoding with geopy
# snippet from github.com/geopy/geopy/blob/master/README.md
from geopy.geocoders import Nominatim
geolocator = Nominatim()
location = geolocator.geocode("175 5th Avenue NYC")
print(location.address)
print((location.latitude, location.longitude))