This file contains 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
# Install Mapshaper | |
npm install -g mapshaper | |
# Install Tippecanoe | |
brew install tippecanoe | |
# Make a directory for your geojson files and convert all the shapefiles in a directory to geojson | |
mkdir ../geojson | |
for f in *.shp; | |
do |
This file contains 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
# install epel repo | |
sudo yum -y install wget | |
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm | |
sudo rpm -Uvh epel-release-latest-7.noarch.rpm | |
wget http://yum.postgresql.org/9.3/redhat/rhel-7-x86_64/pgdg-redhat93-9.3-1.noarch.rpm | |
sudo rpm -Uvh pgdg*.rpm | |
# update (again) | |
sudo yum -y update |
This file contains 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
"""Deal with raster transparency and convert to MBTiles""" | |
import os | |
import re | |
from string import Template | |
from shutil import copyfile | |
from osgeo import gdal | |
import rasterio | |
PATH = 'data/geotiff/' |
This file contains 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 mercantile | |
import requests | |
import settings | |
def getStyle(): | |
r = requests.get('https://api.mapbox.com/styles/v1/axismaps/' + settings.MAPBOX_STYLE + '?access_token=' + settings.MAPBOX_TOKEN) | |
return r.json()['modified'] | |
def download_tile(tileurl, tile, modified): | |
url = tileurl + '/{z}/{x}/{y}.mvt'.format(**tile.__dict__) |
This file contains 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 __future__ import print_function | |
import mercantile | |
import urllib | |
import time | |
import os | |
def download_tile(tileurl, tile, output_dir, pause=1): | |
url = tileurl + '/{z}/{x}/{y}.png'.format(**tile.__dict__) | |
local_path = url.replace(tileurl, output_dir) |
This file contains 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
"""Splits rasters into chunks and creates contours""" | |
import os | |
import argparse | |
import uuid | |
import re | |
from osgeo import gdal | |
def chunk(): | |
"""Splits rasters into 5000 x 5000 chunks.""" |
This file contains 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
DROP VIEW IF EXISTS bivariate; | |
CREATE VIEW bivariate AS | |
SELECT gid, gdp, pop, aal_gdp, aal_pop, aal_gdp / gdp AS gdp_pct, aal_pop / pop AS pop_pct, geom | |
FROM admin1 | |
INNER JOIN ( | |
SELECT aal AS aal_gdp, wb_adm1_co | |
FROM flood | |
WHERE analysis_sector = 'GDP' AND year = 2010 | |
) AS fl ON admin1.adm1_code = fl.wb_adm1_co | |
INNER JOIN ( |
This file contains 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
# Convert shp to topjson and simplify | |
mapshaper -i /Volumes/Storage/Box\ Sync/MapMaster\ data/World/Physical\ Environment/Vector/005_Water_Resources_Vulnerability/005_Water_Resources_Vulnerability.shp -simplify 5% -o data/world/005_water_resources.json format=topojson | |
# Load shapefiles in subdirectories into PostGIS | |
for f in *; do cd $f; for g in *.shp; do shp2pgsql -I -s 4326 $g `basename $g .shp` | psql -d mapmaster; cd ../; done; done |
This file contains 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
# create transparency band | |
for f in *tif; | |
do | |
gdal_translate -b 1 -ot Byte $f red.tif; | |
gdal_translate -b 2 -ot Byte $f green.tif; | |
gdal_translate -b 3 -ot Byte $f blue.tif; | |
gdal_translate -a_nodata none $f no.tif; | |
gdal_calc.py -A no.tif --outfile=mask.tif --calc="(A<=255)*255"; | |
gdal_merge.py -separate -o ../ToCompress/$f red.tif green.tif blue.tif mask.tif; | |
sudo rm red.tif; |
This file contains 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
sudo apt-get update | |
sudo apt-get upgrade | |
sudo apt-get install -y postgis postgresql-9.3-postgis-2.1 imagemagick | |
cd ~rails | |
git clone https://github.com/axismaps/cognita.git | |
cp ~rails/rails_project/config/database.yml ~rails/cognita/config/ |
NewerOlder