library(tidycensus)
library(sf)
## Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
(Seem familiar? We did this chunk below before in Lab 1/Homework 2.)
sa_acs<-get_acs(geography = "tract",
state="TX",
county = c("Bexar"),
year = 2019,
variables=c( "DP05_0001E",
"DP03_0119PE") ,
geometry = T, output = "wide")
## Getting data from the 2015-2019 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using the ACS Data Profile
#create a county FIPS code - 5 digit
sa_acs$county<-substr(sa_acs$GEOID, 1, 5)
#rename variables and filter missing cases
sa_acs2<-sa_acs%>%
mutate(totpop= DP05_0001E, ppov=DP03_0119PE) %>%
# st_transform(crs = 102740)%>%
na.omit()
st_crs(sa_acs2)
## Coordinate Reference System:
## User input: NAD83
## wkt:
## GEOGCRS["NAD83",
## DATUM["North American Datum 1983",
## ELLIPSOID["GRS 1980",6378137,298.257222101,
## LENGTHUNIT["metre",1]]],
## PRIMEM["Greenwich",0,
## ANGLEUNIT["degree",0.0174532925199433]],
## CS[ellipsoidal,2],
## AXIS["latitude",north,
## ORDER[1],
## ANGLEUNIT["degree",0.0174532925199433]],
## AXIS["longitude",east,
## ORDER[2],
## ANGLEUNIT["degree",0.0174532925199433]],
## ID["EPSG",4269]]
We see these tracts are in a Geographic Coordinate System (GCS) called North American Datum 1983 (NAD83).
The NAD83 has units of meters.
library(tmap)
library(tmaptools)
tm_shape(sa_acs2)+
tm_polygons("ppov", title="% in Poverty",
palette="Blues",
style="quantile",
n=5 )+
tm_format("World",
main.title="San Antonio Poverty Estimates (2019) - Quintile Breaks",
main.title.position=c('center','top'),
main.title.size=1.5,
title="Source: ACS 2019",
legend.title.size=1.7,
legend.outside=T,
legend.text.size=1.2)+
tm_scale_bar(position = c("left","bottom"))+
tm_compass()
Click here
for more tmap
aesthetic features.
Click here for a quick discussion on quantile vs. quintile.
(Remember 2278 from the QGIS portion of Lab 2?)
Find other coordinate references here.
new_sa<-st_transform(sa_acs2, crs = 4269)
#Extract two tracts
twtr<-new_sa %>%
filter(GEOID %in% c(48029181820, 48029110600))
# get centroid coordinates for two tracts (these two tracts are where UTSA Main and Downtown Campuses are)
tr_co<-st_centroid(twtr)
## Warning in st_centroid.sf(twtr): st_centroid assumes attributes are constant
## over geometries of x
head(tr_co)
## Simple feature collection with 2 features and 9 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -98.61502 ymin: 29.43017 xmax: -98.50751 ymax: 29.57909
## Geodetic CRS: NAD83
## GEOID NAME DP05_0001E DP05_0001M
## 1 48029181820 Census Tract 1818.20, Bexar County, Texas 8305 833
## 2 48029110600 Census Tract 1106, Bexar County, Texas 5293 423
## DP03_0119PE DP03_0119PM geometry county totpop ppov
## 1 15.2 9.1 POINT (-98.61502 29.57909) 48029 8305 15.2
## 2 37.8 15.2 POINT (-98.50751 29.43017) 48029 5293 37.8
library(gt)
st_distance(tr_co)
## Units: [m]
## [,1] [,2]
## [1,] 0.00 19555.86
## [2,] 19555.86 0.00
`Distance (m)` <- c(19555.86,19519.73,19536.16)
`Distance (ft)`<- `Distance (m)`*3.28084
`Distance (mi)`<- `Distance (ft)`/5280
Projection <- c("EPSG:4269","EPSG:2278","EPSG:3083")
Description <- c("NAD83","NAD83 / Texas South Central (ftUS)","NAD83 / Texas Centric Albers Equal Area")
cbind(Projection, Description, `Distance (m)`, `Distance (ft)`, `Distance (mi)`) %>% as.data.frame() %>%
gt() %>%
tab_header(title = "CRS Projection and Distance")
CRS Projection and Distance | ||||
Projection | Description | Distance (m) | Distance (ft) | Distance (mi) |
---|---|---|---|---|
EPSG:4269 | NAD83 | 19555.86 | 64159.6477224 | 12.1514484322727 |
EPSG:2278 | NAD83 / Texas South Central (ftUS) | 19519.73 | 64041.1109732 | 12.1289982903788 |
EPSG:3083 | NAD83 / Texas Centric Albers Equal Area | 19536.16 | 64095.0151744 | 12.1392074193939 |
Questions
Repeat this process, but use the NAD83 (4269) layer instead. What is the distance between the two points? Is this distance interpretable?
If using unprojected NAD83, the distance would be in degrees and not be interpretable. The data from get_acs() is already projected. The Projected NAD83 layer has a centroid distance of 12.15 mi. This is different from the Texas South Central layer (12.13 mi) and NAD83 / Texas Centric Albers Equal Area (12.14 mi).
Reproject the layer into a new coordinate system, use NAD83 / Texas Centric Albers Equal Area (3083). Re-measure the distance. How does it compare to the one you got using the Texas South Central projection (2278)?
The NAD83 / Texas Centric Albers Equal Area (12.139 mi) is longer than NAD83 / Texas South Central (ftUS) (12.129 mi). This distance is approximately 52 feet.
In general, why is it important to have an accurate system of projection? How could your results be sensitive to this?
The correct projection system is important to correct and account for distortions in the shapes of polygons that occur due to the curvature of the Earth’s surface. It’s also important to have an accurate system of projection for accuracy in surveying, construction, planning, and general GIS research. Using the correct coordinate system will ensure that the locations of entities is communicated consistently.