geocoding and mapping in r - immigration policy labgeocoding using the google api pros: works...

33
Geocoding and Mapping in R Hans Lueders Stanford University [email protected] July 19, 2018 Hans Lueders Geocoding and Mapping in R July 19, 2018 1 / 24

Upload: others

Post on 06-Jul-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Geocoding and Mapping in R

Hans Lueders

Stanford [email protected]

July 19, 2018

Hans Lueders Geocoding and Mapping in R July 19, 2018 1 / 24

Page 2: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Why care?—Data visualization

AK

AL

ARAZ

CA CO

CT

DC DE

FL

GA

HI

IA

ID

ILIN

KS KY

LA

MA

MD

ME

MI

MN

MO

MS

MT

NC

ND

NE

NH

NJ

NM

NV

NY

OH

OK

OR

PA

RI

SC

SD

TN

TX

UTVA

VT

WA

WI

WV

WY

Hans Lueders Geocoding and Mapping in R July 19, 2018 2 / 24

Page 3: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Why care?—Data visualization

Hans Lueders Geocoding and Mapping in R July 19, 2018 2 / 24

Page 4: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Why care?—Data visualization

Hans Lueders Geocoding and Mapping in R July 19, 2018 2 / 24

Page 5: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Why care?—Data visualization

Hans Lueders Geocoding and Mapping in R July 19, 2018 2 / 24

Page 6: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Why care?—Data analysis

⇓Merge geocoded information to data on speciifc geographic units

(e.g., municipalities, counties, districts, regions, states, countries, ...)

What are the characteristics of municipalities targeted by political campaigns?

What is the effect of campaign stops on turnout?

Which city is closest to a particular point?

Where do immigrants from a particular Mexican municipality typically moveto in the US?

What is the effect of climate change on domestic migration or politicalconflict?

...

Hans Lueders Geocoding and Mapping in R July 19, 2018 3 / 24

Page 7: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Outline

1 Motivation

2 Geocoding in Theory

3 Geocoding in Practice

4 Mapping in Theory

5 Mapping in Practice

6 Using GIS for empirical analyses

7 Resources

Hans Lueders Geocoding and Mapping in R July 19, 2018 4 / 24

Page 8: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Outline

1 Motivation

2 Geocoding in Theory

3 Geocoding in Practice

4 Mapping in Theory

5 Mapping in Practice

6 Using GIS for empirical analyses

7 Resources

Hans Lueders Geocoding and Mapping in R July 19, 2018 5 / 24

Page 9: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Longitude and Latitude

Hans Lueders Geocoding and Mapping in R July 19, 2018 6 / 24

Page 10: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Getting geocodes on google maps

Hans Lueders Geocoding and Mapping in R July 19, 2018 7 / 24

Page 11: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Getting geocodes on google maps

Hans Lueders Geocoding and Mapping in R July 19, 2018 7 / 24

Page 12: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Getting geocodes on google maps

Hans Lueders Geocoding and Mapping in R July 19, 2018 7 / 24

Page 13: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Getting geocodes on google maps

Hans Lueders Geocoding and Mapping in R July 19, 2018 7 / 24

Page 14: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Outline

1 Motivation

2 Geocoding in Theory

3 Geocoding in Practice

4 Mapping in Theory

5 Mapping in Practice

6 Using GIS for empirical analyses

7 Resources

Hans Lueders Geocoding and Mapping in R July 19, 2018 8 / 24

Page 15: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Geocoding using the Google API

Pros:

Works worldwide

Accepts any kind of location(i.e., full addresses, cities, counties, countries, ...)

Cons:

Daily limits

Still need to check quality of geocodes

Quality decreases for more remote places

Hans Lueders Geocoding and Mapping in R July 19, 2018 9 / 24

Page 16: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Let’s do some geocoding!

R code

Hans Lueders Geocoding and Mapping in R July 19, 2018 10 / 24

Page 17: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Outline

1 Motivation

2 Geocoding in Theory

3 Geocoding in Practice

4 Mapping in Theory

5 Mapping in Practice

6 Using GIS for empirical analyses

7 Resources

Hans Lueders Geocoding and Mapping in R July 19, 2018 11 / 24

Page 18: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

The Earth is not flat!

Hans Lueders Geocoding and Mapping in R July 19, 2018 12 / 24

Page 19: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

The Earth is not flat!

Hans Lueders Geocoding and Mapping in R July 19, 2018 12 / 24

Page 20: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

The Earth is not flat!

Hans Lueders Geocoding and Mapping in R July 19, 2018 13 / 24

Page 21: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

The Earth is not flat!

Hans Lueders Geocoding and Mapping in R July 19, 2018 13 / 24

Page 22: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Mapping is Politics

Mercator Projection

Hans Lueders Geocoding and Mapping in R July 19, 2018 14 / 24

Page 23: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Mapping is Politics

Lambert Projection

Hans Lueders Geocoding and Mapping in R July 19, 2018 15 / 24

Page 24: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Coordinate Reference Systems (CRS)

Also called Spatial Reference System (SRS)

Coordinate-based local, regional, or global system used to locate geographicalentities

Defines a specific map projection

Important to know when joining different shapefiles or geocoded points ontomaps

Google maps uses the Mercator projection based on WGS84(W[world] G[eodetic] S[ystem] 1984)

Hans Lueders Geocoding and Mapping in R July 19, 2018 16 / 24

Page 25: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

GIS data

GIS: Geographic information systems

Storage of a variety of geographic information:

Points (e.g., Encina Hall)Lines (e.g., Serra St)Polygons (e.g., Santa Clara county)

Hans Lueders Geocoding and Mapping in R July 19, 2018 17 / 24

Page 26: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

GIS data

Data

Shape file (.shp): vectorized geographic coordinate (“shape”) data (points,lines, polygons)Shape index (.shx): positional index of the feature geometry to allow seekingforward and backward quicklyData frame (.dbf): information associated with each point, line, or polygonProjection info (.prj): contains projection data and information on the CRSused

Hans Lueders Geocoding and Mapping in R July 19, 2018 18 / 24

Page 27: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Outline

1 Motivation

2 Geocoding in Theory

3 Geocoding in Practice

4 Mapping in Theory

5 Mapping in Practice

6 Using GIS for empirical analyses

7 Resources

Hans Lueders Geocoding and Mapping in R July 19, 2018 19 / 24

Page 28: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Let’s do some mapping!

R code

Hans Lueders Geocoding and Mapping in R July 19, 2018 20 / 24

Page 29: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Outline

1 Motivation

2 Geocoding in Theory

3 Geocoding in Practice

4 Mapping in Theory

5 Mapping in Practice

6 Using GIS for empirical analyses

7 Resources

Hans Lueders Geocoding and Mapping in R July 19, 2018 21 / 24

Page 30: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Let’s use some of the GIS tools for actual analyses!

R code

Hans Lueders Geocoding and Mapping in R July 19, 2018 22 / 24

Page 31: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Outline

1 Motivation

2 Geocoding in Theory

3 Geocoding in Practice

4 Mapping in Theory

5 Mapping in Practice

6 Using GIS for empirical analyses

7 Resources

Hans Lueders Geocoding and Mapping in R July 19, 2018 23 / 24

Page 32: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Some useful online resources

Nick Eubank’s GIS in R scripts

Making Maps with R

Natural Earth Data shapefile collection

Colors in R

Color Brewer Advice for Cartography

Hans Lueders Geocoding and Mapping in R July 19, 2018 24 / 24

Page 33: Geocoding and Mapping in R - Immigration Policy LabGeocoding using the Google API Pros: Works worldwide Accepts any kind of location (i.e., full addresses, cities, counties, countries,

Thank you!

For questions, please reach out to

[email protected]

Hans Lueders Geocoding and Mapping in R July 19, 2018 24 / 24