This script uses RCurl and RJSONIO to download data from Google's API to get the latitude, longitude, location type, and formatted address
library(RCurl)
library(RJSONIO)
library(plyr)
#Write geojson | |
#==== | |
#Load libraries | |
library(rgdal) | |
#dataMap is a dataframe with coordinates on cols 11 (LATITUDE) and 12 (LONGITUDE) | |
#Transfor coordinates to numeric | |
dataMap$LATITUDE <- as.numeric(dataMap$LATITUDE) | |
dataMap$LONGITUDE <- as.numeric(dataMap$LONGITUDE) |
### 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) |
# 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) |
# Compiled source # | |
################### | |
*.com | |
*.class | |
*.dll | |
*.exe | |
*.o | |
*.so | |
# Packages # |
<!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> |
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.municipalities { | |
fill: #222; | |
} | |
.municipalities :hover { | |
fill: orange; |
.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 |
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.states { | |
fill: #222; | |
} | |
.states :hover { | |
fill: orange; |