Mapping the geopoint (Latitude & Longitude) to Shapefile

Sometimes you want to know what Kelurahan (Village), Kecamatan (District), Kabupaten (Region), and Province are from latitude and longitude. I did it with R, here the script is.

This is part of the analysis you may need when you handle GeoSpatial Data.

Thank someone who gave me the example from this link.

library(rgdal)
library(sp)

#load shapefile
data.shape <-readOGR(dsn="/nama/direktori/shapefile/anda",
layer="nama_shapefile")
data.shape <- spTransform(data.shape, CRS("+proj=longlat +datum=WGS84"))

#create csv file that want to be mapped into shapefile
csvfile <- data.frame(LONGITUDE = c(106.6882639, 106.7705755),
LATITUDE = c(-6.1342941, -6.1642941))

# convert data frame to SpatialPoints class
coordinates(csvfile) <- ~LONGITUDE+LATITUDE

# make sure the two files share the same CRS
csvfile@proj4string <- data.shape@proj4string

# visual check
plot(data.shape, border = "grey")
points(csvfile, col = "red", cex = 5)
axis(1) # showing the axes helps to check whether the coordinates are what you expected
axis(2)

#mapping
points_in_shape <- over(csvfile, data.shape)

#output
points_in_shape


Wanna support me?

Follow by Email
LinkedIn
Share