[R] Match coordinates to regional polygon

Miluji Sb m||uj|@b @end|ng |rom gm@||@com
Mon Mar 9 23:15:44 CET 2020


Dear all,

I am trying to match a large number of coordinates (attached) sub-national
regions using GADM shapefile.

Coordinates:
https://drive.google.com/file/d/1PUsi4d0wP7hB6Aps6UmpXsnIPSD3I1sT/view?usp=sharing

Shapefile:
https://drive.google.com/drive/folders/1DxyygjQNeg2GIS9doaFM8yM2LvBYZi8E?usp=sharing


This is the code I am using;

###
library(data.table)
library(ncdf4)
library(rgdal)
library(raster)
library(tidyverse)

## 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.

Regards,

Milu

	[[alternative HTML version deleted]]



More information about the R-help mailing list