Closed cenuno closed 5 years ago
I revised LabelPointsWithinPolygons
so that it stores the results of splancs::inpip()
for each polygon as a named integer vector in a list rather than in a data frame. To fix this issue, please install the latest version of pointdexter
(0.1.1) from CRAN and re-run your script:
install.packages("pointdexter")
stack
dropping integer(0)
records from data frameMoving from data frame to a list for storing the output of splancs::inpip()
allowed for edge cases where a polygon does not have a single point laying inside of it (returning a value of integer(0)
) to be tracked and subsequently dropped.
Here's a brief example:
stack(list("valid" = 1:3, "invalid" = integer(0)))
# note: notice how the integer(0) result from 'invalid' is not returned in the data frame
# values ind
# 1 1 valid
# 2 2 valid
# 3 3 valid
By stacking the list of named integer vectors into a data frame, these edge cases are dropped from the data frame prior to LabelPointsWithinPolygons()
finishing its execution.
After updating pointdexter
from CRAN to version 0.1.1, the code ran without an error message. Here's a look into the first few records:
head(cps_sy1819[, c("school_id", "school_longitude", "school_latitude", "census_tract")])
school_id | school_longitude | school_latitude | census_tract |
---|---|---|---|
609760 | -87.59062 | 41.65629 | 540102 |
609780 | -87.72174 | 41.91604 | 222900 |
610304 | -87.68696 | 41.87912 | 280800 |
610513 | -87.63276 | 41.82814 | 340600 |
610390 | -87.66579 | 41.98902 | 030500 |
609754 | -87.61922 | 41.83055 | 839600 |
Overview
This issue is courtesy of my colleague Noah who was getting an error message when using
pointdexter
with 2010 census tract boundaries for the City of Chicago.Issue
LabelPointsWithinPolygons()
fails when no points exist within a polygon. By using smaller geographies (i.e. census tracts) rather than larger ones (i.e. community areas),pointdexter
's current method of labeling does not account for instances where a polygon has no points laying inside of it.Here is the error message:
Reproducible Example
Session Info
sessioninfo::session_info()