3) In general, why is it important to have an accurate system of projection? How could your results be sensitive to this? - The curvature of the earth and units of measure for GCS data makes distance measures uninterpretable and distorts shapes and areas if valid projected coordinate systems are not leveraged.
library(tidycensus)
library(sf)
## Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.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
sa_acs<-get_acs(geography = "tract",
state="TX",
county = c("Bexar"),
year = 2017,
variables=c( "DP05_0001E",
"DP03_0119PE") ,
geometry = T, output = "wide")
## Getting data from the 2013-2017 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]]
#Extract two tracts
twtr1<-sa_acs2%>%
filter(GEOID %in% c(48029181820, 48029110100))
# get centroid coordinates for two tracts
tr_co1<-st_centroid(twtr1)
## Warning in st_centroid.sf(twtr1): st_centroid assumes attributes are constant
## over geometries of x
st_distance(tr_co1)
## Units: [m]
## [,1] [,2]
## [1,] 0.00 20787.28
## [2,] 20787.28 0.00
new_sa<-st_transform(sa_acs2, crs = 2278)
#Extract two tracts
twtr2<-new_sa%>%
filter(GEOID %in% c(48029181820, 48029110100))
# get centroid coordinates for two tracts
tr_co2<-st_centroid(twtr2)
## Warning in st_centroid.sf(twtr2): st_centroid assumes attributes are constant
## over geometries of x
#Measure feet apart
st_distance(tr_co2)
## Units: [US_survey_foot]
## [,1] [,2]
## [1,] 0.00 68091.77
## [2,] 68091.77 0.00