Skip to content

Instantly share code, notes, and snippets.

@josecarlosgonz
josecarlosgonz / writeShapeFile.R
Created August 7, 2014 17:26
Create a shapefile from a csv with latitude and longitude coordinates
# Create a shapefile from a csv with latitude and longitude coordinates in
# decimal degrees
# Install and load rdgal
install.packages(rdgal)
require(rgdal)
# Load data
data <- read.csv("Coordinates.csv")
head(data)
@josecarlosgonz
josecarlosgonz / .gitignore
Created June 4, 2014 17:55 — forked from octocat/.gitignore
Gist to gitignore files
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@josecarlosgonz
josecarlosgonz / mx_states.json
Created June 1, 2014 20:55
Map of Mexican States
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<script src='http://d3js.org/d3.v3.min.js' type='text/javascript'></script>
<script src='http://d3js.org/topojson.v1.min.js' type='text/javascript'></script>
<script src='http://datamaps.github.io/scripts/datamaps.all.min.js' type='text/javascript'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.min.js' type='text/javascript'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js' type='text/javascript'></script>
@josecarlosgonz
josecarlosgonz / index.html
Created May 29, 2014 18:41
Map of Mexico with d3
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.municipalities {
fill: #222;
}
.municipalities :hover {
fill: orange;
@josecarlosgonz
josecarlosgonz / Makefile
Last active August 29, 2015 14:01
Interactive map of ENVIPE 2010, 2011 and 2012
.PHONY: all clean
all: estados.zip mx_states.json clean
estados.zip:
curl -o estados.zip http://mapserver.inegi.org.mx/MGN/mge2010v5_0.zip
mx_states.json: estados.zip
unzip -o estados.zip
ogr2ogr states.shp Entidades_2010_5.shp -t_srs "+proj=longlat +ellps=WGS84 +no_defs +towgs84=0,0,0"
## id-property needed so that DataMaps knows how to color the map
topojson -o mx_states.json -s 1e-7 -q 1e5 states.shp -p state_code=+CVE_ENT,name=NOM_ENT --id-property NOM_ENT
@josecarlosgonz
josecarlosgonz / index.html
Last active August 29, 2015 14:01
Map of Mexican States
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.states {
fill: #222;
}
.states :hover {
fill: orange;
@josecarlosgonz
josecarlosgonz / merge_shapefile.R
Created May 6, 2014 18:45
Merge a shapefile with a csv and save it using UTF-8
### Load a shape file and merge it with a csv
### Author: Jose Gonzalez
### www.jose-gonzalez.org
# This script shows how to load a shapefile, merge it with a csv and save it with the proper
# encoding
### Load rgdal
require(rgdal)
@josecarlosgonz
josecarlosgonz / README.md
Last active August 29, 2015 13:58 — forked from ramnathv/README.md
Homicidios por estado 1997 -2013

This code was orginally posted by Ramnath

The original code starts below:

This is a rewrite of the mapping code used in this post by Diego Valle. It basically replaces all the boilerplate code with the ichoropleth function in rMaps, which wraps it, allowing easier reuse. Please follow the code from the original post to the get the shapefiles, topojson and data. My note will start with the dataset hom.

d1 <- ichoropleth(rate ~ name, data = hom, ncuts = 9, pal = 'YlOrRd', 
  animate = 'year',  map = 'states'
)
@josecarlosgonz
josecarlosgonz / .gitignore
Last active August 29, 2015 13:58 — forked from mbostock/.block
Map of Mexican Municipalities
build
node_modules
.DS_Store