hypertidy / toposhop

2 stars 0 forks source link

fix-it vignette #10

Open mdsumner opened 7 years ago

mdsumner commented 7 years ago

title: "Vignette Title" author: "Vignette Author" date: "r Sys.Date()" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Fixing problems in spatial data} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8}

Problems in spatial data are fairly common.

library(maptools)
data(wrld_simpl)

rgeos::gIsValid(wrld_simpl)

What does that mean?

ii <- integer()
for (i in seq_len(nrow(wrld_simpl))) {
  if (!rgeos::gIsValid(wrld_simpl[i, ])) ii <- c(ii, i)
}
print(ii)
plot(wrld_simpl[ii, ])

There are r length(ii) features that present the same kind of message. We can't really use these messages as they are so let's start extracting the information.

parse_self_intersection <- function(x) {
  as.numeric(unlist(strsplit(gsub("Ring Self-intersection at or near point) ", "", x), " ")))
}

for (i in seq_len(nrow(wrld_simpl))) {
  withCallingHandlers(rgeos::gIsValid(wrld_simpl[24, ]), warning = function(w) parse_self_intersection(w))
}