degauss-org / st_census_tract

link geocoded coordinates with date ranges to corresponding census tracts from the appropriate vintage
https://geomarker.io/st_census_tract
GNU General Public License v3.0
2 stars 0 forks source link

Use `st_make_valid` to fix all polygons #8

Closed erikarasnick closed 2 years ago

erikarasnick commented 2 years ago

To Do:

use st_make_valid on all polygons before saving the rds file to s3, then use this new version of the file in the container.

Background

st_join will fail for a point when largest = TRUE if a nearby geometry is not valid (i.e. contains a self-intersecting ring).

example <- tibble::tribble(
 ~location_id,  ~address, ~start_date, ~end_date,      ~lat,       ~lon, ~score, ~precision, ~geocode_result,
1090960, "302 SMITH DR FORT WALTON BEACH FL 32548",   "4/19/10",  "7/1/10", 30.417158, -86.595944,  0.886, "range", "geocoded" )
Screen Shot 2021-12-22 at 2 38 56 PM

If largest = FALSE, the one overlapping tract shown above is chosen with no error.

Screen Shot 2021-12-22 at 2 46 41 PM

If largest = TRUE, the large polygon above is (apparently...) included for consideration, and this polygon is not a "valid" polygon.

st_is_valid(all_tracts$`2010`[all_tracts$`2010`$census_tract_id == "12091020800",], reason = TRUE)
[1] "Ring Self-intersection[894508.042800001 865389.710577341]"
erikarasnick commented 2 years ago

@cole-brokamp Not exactly what I thought was going on, but I think I can fix it!