Last active
August 29, 2015 14:24
-
-
Save PhillRob/a30b5a8e2d5154ce3c35 to your computer and use it in GitHub Desktop.
match point data to country/state/region boundary polygon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Matching point records to polygones boundaries of a country, state or | |
# region polygones for regions of NZ | |
require(maptools) | |
library(maps) | |
library(SDMTools) | |
# obtain lon/lat boundaries for north and south island of NZ | |
nz.n.poly <- cbind(map("nz", regions = "North.Island")$x, map("nz", regions = "North.Island")$y) | |
nz.s.poly <- cbind(map("nz", regions = "South.Island")$x, map("nz", regions = "South.Island")$y) | |
# match to points where d[(6:5)] are the columns of a dataframe containing lon/lat data | |
d1$north <- as.factor((pnt.in.poly(d[(6:5)], nz.n.poly))$pip) | |
d1$north <- gsub(1, "north", d1$north) | |
d1$south <- as.factor((pnt.in.poly(d[(6:5)], nz.s.poly))$pip) | |
d1$south <- gsub(1, "south", d1$south) | |
d2 <- d1[which((d1$north == "north") | (d1$south == "south")), ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment