hrbrmstr / albersusa

Tools, shapefiles & data to work with an "AlbersUSA" composite projection in R
Other
77 stars 16 forks source link

Updating shapefile #10

Open rdinter opened 7 years ago

rdinter commented 7 years ago

There's some strange behavior with the default shapefiles in the package that appears to have occurred when the rds files (which have the .rda extension but are rds files...why is that?) were updated with https://github.com/hrbrmstr/albersusa/commit/ac3cdf3b2f589fa28e115975a7efb034a316132b. It looks like both the county and state shapefiles are of fairly poor quality and produce poor graphics. Let me show the examples and then what I think is happening:

# Splotchy shapefile example

library(albersusa)
library(ggplot2)
library(maptools)
library(sp)

us      <- counties_composite("aeqd")
us_map  <- fortify(us)

ggplot(us_map, aes(long, lat, group = group)) +
  geom_polygon(fill = "blue")

shapefile_issue

(It might be a bit difficult to see, but if you zoom in slightly then the dead pixels become very clear)

This issue is further exacerbated if I try to take the original shapefile, aggregate up to a different level (say states) and create a geom_path:

states <- fortify(us, region = "state")

ggplot(us_map, aes(long, lat, group = group)) +
  geom_polygon(fill = "blue") +
  geom_path(data = states)

shapefile_path_issue

The same performance issues occur with the usa_composite() function for states:

us      <- usa_composite("aeqd")
us_map  <- fortify(us)

ggplot(us_map, aes(long, lat, group = group)) +
  geom_polygon(fill = "blue")

shapefile_issue_states

And if I attempt to create a path for a subset of states:

south_east <- c("AL", "FL", "GA", "NC", "SC")
us$region <- ifelse(us$iso_3166_2 %in% south_east, "SOUTHEAST", "REST")

states <- fortify(us, region = "region")

ggplot(us_map, aes(long, lat, group = group)) +
  geom_polygon(fill = "blue") +
  geom_path(data = states)

shapefile_path_issue_states

Issue

When I went through https://github.com/hrbrmstr/rd3albers to create the Alaska and Hawaii bounding boxes, I noticed that there were two types of formats used for the spatial objects in the repository: the classic .shp/.shx/.dbf shapefile which and also a GeoJSON file. What I am pretty sure is happening is that the current .rda files for counties/states are based off of the GeoJSON file, which has some funky resolution. I'd bet that the previous .rda files were based off of the .shp/.shx/.dbf shapefile, which doesn't appear to produce the funky path lines and splotches while filling in the map.

Are the .rda/.rds files based off of that rd3albers repository? If so, I can put in a pull request here for the objects which uses that repository's data. But further, is there a reason why the counties/states have the .rda extension but are actually .rds based files? That seems a bit confusing to me, but there might be a reason for it that I'm missing.