Applied Computational Methods for Social Sciences

Lecture 9: Intro to Geographic Information Systems (GIS)

Bogdan G. Popescu

John Cabot University

What You’ll Learn Today

  1. Planet Earth, its shape, and latitude and longitude
  2. Coordinate reference systems: spheres, ellipsoids, geoids, and datums
  3. Geographic vs. projected coordinate systems
  4. Vector layers: points, lines, polygons
  5. Where to find country shapefiles and how to map them in R

By the end, you’ll understand how locations on Earth become data you can map.

The Earth and the Geographic Coordinates

  • The Earth is not a perfect sphere

The Earth and the Geographic Coordinates

  • The Earth is not a perfect sphere

  • Polar diameter is 12,714 km

The Earth and the Geographic Coordinates

  • The Earth is not a perfect sphere

  • Polar diameter is 12,714 km

  • Equatorial diameter is 12,756 km

The Earth and the Geographic Coordinates

  • The Earth is not a perfect sphere

  • Polar diameter is 12,714 km

  • Equatorial diameter is 12,756 km

  • The Earth is flattened at the poles and elongated at the equator: Oblate Spheroid

Cardinal Points

  • The main cardinal points are: North, South, East, and West

  • These are used for orientation and to express direction on the Earth’s surface

The Cartesian System

  • The Cartesian system is a position reference system

The Cartesian System

  • The Cartesian system is a position reference system

  • We can use the two reference axes to express any position through cartesian coordinates

The Cartesian System

  • The Cartesian system is a position reference system

  • We can use the two reference axes to express any position through cartesian coordinates

  • For example this point is located 4 units on the X axis and 3 units on the Y axis

Position on Earth

The position on Earth can be displayed in a similar way using the geographic coordinate system

Position on Earth

Each position on the earth can be identified in terms of latitude and longitude

Position on Earth

Each position on the earth can be identified in terms of latitude and longitude

Position on Earth

Each position on the earth can be identified in terms of latitude and longitude

Position on Earth

Each position on the earth can be identified in terms of latitude and longitude

Position on Earth

Latitude is used to express how far north or how far south a point is

Position on Earth

Longitude is used to express how far west or how far east a point is

Position on Earth

As in the Cartesian system, two reference axes are used from which latitude and longitudes are measured

Position on Earth

As in the Cartesian system, two reference axes are used from which latitude and longitudes are measured

Position on Earth

These axes divide the earth into four hemispheres

Position on Earth

These axes divide the earth into four hemispheres

Position on Earth

These axes divide the earth into four hemispheres

Position on Earth

These axes divide the earth into four hemispheres

Position on Earth

These axes divide the earth into four hemispheres

Position on Earth

These axes divide the earth into four hemispheres

Latitude and Longitude

Due to the Earth’s size, it is common to use secondary reference lines

  • parallels

  • meridians

Meridians

  • Meridians are semi-circles that join the North and South Poles

  • They are measured in degrees in relation to the prime meridian (Greenwich meridian)

  • These lines are used as reference for the longitude

Parallels

  • Parallels are circles that are parallel to the Equator line

  • They are measured in degrees in relation to the Equator line

  • These lines are used as reference for the latitudes

Geographic Graticule

  • The resulting grid from parallels and meridians is called the geographic graticule (grid)

Latitude

The latitude is the angular distance between the Equator and a point on the Earth’s surface, measured in degrees, minutes, and seconds of an arc

What is an arc?

The latitude measures how far north or how far south a point is

Latitude

  • Latitude is 0 degrees at the equator line

  • It then increases gradually until 90 degrees at each of the poles

Latitude

  • Latitude is 0 degrees at the equator line

  • It then increases gradually until 90 degrees at each of the poles

Latitude

  • Latitude is 0 degrees at the equator line

  • It then increases gradually until 90 degrees at each of the poles

Latitude

  • Latitude is 0 degrees at the equator line

  • It then increases gradually until 90 degrees at each of the poles

Latitude

  • Latitude is 0 degrees at the equator line

  • It then increases gradually until 90 degrees at each of the poles

Latitude

  • Latitude is 0 degrees at the equator line

  • It then increases gradually until 90 degrees at each of the poles

Longitude

The longitude is the angular distance between the prime meridian and point on Earth, measured in degrees, minutes and seconds of arc

The Longitude measures how far east or how far west a point is

Longitude

  • Longitude is 0 degrees at the Greenwich meridian

  • It then increases gradually until 180 degrees on the opposite side

Longitude

  • Longitude is 0 degrees at the Greenwich meridian

  • It then increases gradually until 180 degrees on the opposite side

Longitude

  • Longitude is 0 degrees at the Greenwich meridian

  • It then increases gradually until 180 degrees on the opposite side

Longitude

  • Longitude is 0 degrees at the Greenwich meridian

  • It then increases gradually until 180 degrees on the opposite side

Longitude

  • Longitude is 0 degrees at the Greenwich meridian

  • It then increases gradually until 180 degrees on the opposite side

Longitude

  • Longitude is 0 degrees at the Greenwich meridian

  • It then increases gradually until 180 degrees on the opposite side

Zooming In

  • Between each degree of latitude and longitude, there is a substantial distance

  • To express location within the same latitude and longitude, we use the sexagesimal system

  • Thus, each degree can be divided into 60 minutes of an arc: 1°=60’

Zooming In

  • Between each degree of latitude and longitude, there is a substantial distance

  • To express location within the same latitude and longitude, we use the sexagesimal system

  • Thus, each degree can be divided into 60 minutes of an arc: 1°=60’

Zooming In

  • Similarly, each minute can be divided into 60 seconds: 1’=60’’

Zooming In

  • Similarly, each minute can be divided into 60 seconds: 1’=60’’

Example

Example

Example

Example

Example

Example

Example

Example

Google Maps works with Decimal Degrees

These are different from Degree-Minute-Second units

To calculate Decimal Degrees we can calculate:

Decimal Degrees = degrees + (minutes/60) + (seconds/3600)

For example, 51 degrees, 02 mins, and 00 seconds N is 51.00305556

011 degrees, 01 mins, and 00 seconds E is 11.025

Example

Let us look at a graticule

Example

Let us look at a graticule

Point A has a latitude of 1 and a longitude of 74

Because the latitude increases, this means that the equator line is below A

Point A is in the Northern Hemisphere

Example

Let us look at a graticule

Point A has a latitude of 1 and a longitude of 74

Because the longitude increases to the left, this means that the prime meridian is to the right of A

Point A is in the Western Hemisphere

Example

Example

Example

Coordinate Reference System

To place an object on a map, you need two pieces of information:

  • the coordinates of the object
  • a system of reference for how the coordinates relate to a physical location on Earth.

Coordinate Reference System

A coordinate reference system (CRS) comes to help to accurately represent an element on the Earth’s surface.

It identifies the origin and orientation of the coordinate axes on the ellipsoid, as well as the units of measurement.

Thus a coordinate reference system has three components:

  • Sphere and Ellipsoid description
  • Geoid
  • Datum

CRS: Sphere and Ellipsoid

  • We can assume that the earth is a perfect sphere

  • This simplifies mathematical calculations

  • But if we want more accurate measurements, we may want to go for ellipsoid

    • Calculation of distances will be different for the two types

CRS: Sphere and Ellipsoid

  • We can assume that the earth is a perfect sphere

  • This simplifies mathematical calculations

  • But if we want more accurate measurements, we may want to go for ellipsoid

    • Calculation of distances will be different for the two types

CRS: Geoid

  • We also know that the earth does not have a perfectly smooth surface.

  • These are not visible with the naked eye, but they have implications for local measurements

  • For example, the Earth’s undulations are maximized 4,000 times below

CRS: Datum

  • To reconcile the need to work with a simple mathematical model and the undulating shape of the earth, we can:
  • align the geoid with the ellipsoid (or sphere) representation of the earth
  • map the earth’s surface features onto this ellipsoid/sphere
  • Datum - how one chooses to align the ellipsoid to the geoid

CRS: Datum

There are many local datums

In the US, popular datums in the US include:

  • North American Datum of 1927 (NAD27) - best for continental US
  • European Datum of 1950 (ED50) - best for Western Europe
  • World Geodetic System 1972 (WGS72) - best for the whole world

CRS: Datum

Other Popular Geocentric Datums for the whole world include

  • World Geodetic Survey for 1984 (WGS84)
  • North American Datums of 1983 (NAD83)

These use the WGS84 ellipsoid or the GRS80 ellipsoid.

These share nearly identical semi-major and semi-minor axes: 6,378,137 meters and 6,356,752 meters respectively

Coordinate Systems

There are two types of CRS:

  • geographic
  • projected

World Geodetic System of 1984 or WGS84

The most common geographic coordinate system is WGS84 - World Geodetic System of 1984

It was established as a result of need for global maps for navigation, aviation, and geography.

The following is in the WGS84 coordinate system

Geographic Coordinate Reference System

Here is the information given by the crs:

st_crs(world)
Coordinate Reference System:
  User input: unknown 
  wkt:
GEOGCRS["unknown",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]],
        ID["EPSG",6326]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["Degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["longitude",east,
            ORDER[1],
            ANGLEUNIT["Degree",0.0174532925199433]],
        AXIS["latitude",north,
            ORDER[2],
            ANGLEUNIT["Degree",0.0174532925199433]]]

Geographic Coordinate Reference System

  • In this case “GCS_unknown” is used as a placeholder or default name for the Geographic Coordinate Reference System.
  • Even though the name is shown as “GCS_unknown,” the key information is in the details of the coordinate system, which is WGS 84
  • The WKT (Well-Known Text) representation indicates the use of WGS 84 with the associated parameters such as the datum, ellipsoid, and axis orientation.

Geographic Coordinate Reference System

Here is the information given by the crs:

st_crs(world)
Coordinate Reference System:
  User input: unknown 
  wkt:
GEOGCRS["unknown",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]],
        ID["EPSG",6326]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["Degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["longitude",east,
            ORDER[1],
            ANGLEUNIT["Degree",0.0174532925199433]],
        AXIS["latitude",north,
            ORDER[2],
            ANGLEUNIT["Degree",0.0174532925199433]]]

Geographic Coordinate Systems

Geographic coordinate reference systems represent points on an globe, using units of degrees longitude and latitude.

  • A geographic coordinate system provides a frame of reference for your data to locate features on the surface of the earth, to align your data relative to other data
  • They correspond to angles measured from the center of the Earth as calculated using the given ellipsoid.
  • A projection is necessary to create any two-dimensional map, but it results in the distortion of aspects of the Earth’s surface such as area, direction, distance, and shape.
  • A projected reference systems is useful for geographic analysis, because it uses linear units of measurement such as meters instead of degrees.

Projected Coordinate Systems

  • A projected coordinate system is a reference system for identifying locations and measuring features on a flat (map) surface

  • Going from a GCS to a PCS requires mathematical transformations.

  • To perform spatial analyses correctly, all the data has to have the same coordinate system

Types of Projected Coordinate Systems

Types of Projected Coordinate Systems

Types of Projected Coordinate Systems

Types of Projected Coordinate Systems

Types of Projected Coordinate Systems

Types of Projected Coordinate Systems

Spatial Data Classes in R

  • Spatial entries in GIS can be represented as a vector or as a raster

  • You see below how river can be represented as a vector (left) and as a raster (right)

Vector Layers

Vector layers are sets of geometries associated with non-spatial attributes

The geometries are sequences of one or more coordinates, connected to form lines or polygons

The non-spatial attributes come as a table

Vector layers can be:

  • points
  • lines
  • polygons

Vector Layers

Points

Points are just dots that have a coordinate pair:

(i.e. latitude - X and longitudes - Y)

Points

Here are for example all the restaurants in central Rome

Polylines

Polylines are a sequence of two or more coordinate pairs - vertices.

Roads and rivers are typically stored as polylines in GIS

Polylines

Here are for example all the roads in central Rome

Polygons

Polygons are three or more line segments whose starting and ending coordinate pairs are the same.

Countries are usually depicted as polygons

Polygons

Here are for example all the buildings in central Rome

Polygons

Here are for example all countries in the world

Shapefiles for World

You can download shapefiles for different countries by going to https://gadm.org

Shapefiles for World

You can download shapefiles for different countries by going to https://gadm.org

Shapefiles for World

You can download shapefiles for different countries by going to https://gadm.org

Shapefiles for World

You can download shapefiles for different countries by going to https://gadm.org

Shapefiles for World

You can download shapefiles for different countries by going to https://gadm.org

Shapefiles for World

You can download shapefiles for different countries by going to https://gadm.org

Shapefiles for World

You can download shapefiles for different countries by going to https://gadm.org

Shapefiles for World

You can download shapefiles for different countries by going to https://gadm.org

Creating a Map of the US

This is what we want our final map to look like:

Loading the Shapefile for the US

library(sf)
#"s2" is an enhancement of the "sf" package
#It allows spatial operations with data in a
#geographic coordinate system (degrees)
#However, having it enabled will take
#much longer computation time
sf_use_s2(FALSE)
library(ggplot2)
#Step1: Read country shape
usa_cntry <- st_read(
  dsn="./data/gadm41_USA_shp/gadm41_USA_0.shp",
  quiet = TRUE)

#Step2: Simplify lines
usa_cntry<-st_simplify(usa_cntry,
  dTolerance = 0.05)

#Step3: Map
ggplot()+
  geom_sf(data=usa_cntry)

st_simplify Use

st_simplify allows our computer to map a vector quicker

To see how this affects our output, let’s change it to a different value. The one below is 0.05

#Step1: Read country shape
usa_cntry <- st_read(
  dsn="./data/gadm41_USA_shp/gadm41_USA_0.shp",
  quiet = TRUE)

#Step2: Simplify lines
usa_cntry<-st_simplify(usa_cntry,
  dTolerance = 0.05)

#Step3: Map
ggplot()+
  geom_sf(data=usa_cntry)

st_simplify Use

st_simplify allows our computer to map a vector quicker

To see how this affects our output, let’s change it to a different value. The one below is 5

#Step1: Read country shape
usa_cntry <- st_read(
  dsn="./data/gadm41_USA_shp/gadm41_USA_0.shp",
  quiet = TRUE)

#Step2: Simplify lines
usa_cntry<-st_simplify(usa_cntry,
  dTolerance = 5)

#Step3: Map
ggplot()+
  geom_sf(data=usa_cntry)

Loading the Shapefile for the US

The next step is to decide on a set of coordinates that allow us to zoom onto the US

#Step1: Read country shape
usa_cntry <- st_read(dsn="./data/gadm41_USA_shp/gadm41_USA_0.shp", quiet = TRUE)

#Step2: Simplify lines
usa_cntry<-st_simplify(usa_cntry,  dTolerance = 0.05)

#Define zoom
min_lon_x_us<-(-130)
max_lon_x_us<-(-57)
min_lat_y_us<-(26)
max_lat_y_us<-(53)

Loading the Shapefile for the US

We can now finally create the map

ggplot()+
  geom_sf(data=usa_cntry, linewidth = 0.3, fill = NA)+
  theme_bw()+
  coord_sf(xlim = c(min_lon_x_us-3, max_lon_x_us+3), 
           ylim = c(min_lat_y_us-3, max_lat_y_us+3))

What Have We Learned?

  • The Earth is an oblate spheroid located by latitude and longitude
  • A CRS combines an ellipsoid, a geoid, and a datum
  • Geographic systems use degrees; projected systems use meters — every projection distorts something
  • Vector layers represent the world as points, lines, and polygons
  • Downloaded and mapped real shapefiles with sf and st_simplify

Next: working hands-on with vector data in R.