[R] Match coordinates to regional polygon
bgunter@4567 @end|ng |rom gm@||@com
Tue Mar 10 00:13:03 CET 2020
I believe this would be better posted on r-sig-Geo .
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Mon, Mar 9, 2020 at 3:16 PM Miluji Sb <milujisb using gmail.com> wrote:
> Dear all,
> I am trying to match a large number of coordinates (attached) sub-national
> regions using GADM shapefile.
> This is the code I am using;
> ## Read coordinates
> coords <- read.csv("coords.csv")
> ## Read shapefile
> world <-readOGR(dsn = "/gadm36_levels_shp", layer = "gadm36_2")
> ## Convert to spatial points
> pts <- coords
> coordinates(pts) <- ~lon+lat
> ## Provide the same CRS to the coordinates as the shapefile
> proj4string(pts) <- proj4string(world)
> ## Use over function to match coordinates to polygons
> pts_district <- over(pts, world)$NAME_1
> However, less than 20% of the coordinates are matched to a polygon. What am
> I doing wrong? Any help will be greatly appreciated.
> [[alternative HTML version deleted]]
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help