{"id":599,"date":"2018-07-16T16:31:08","date_gmt":"2018-07-16T09:31:08","guid":{"rendered":"http:\/\/arikuncoro.xyz\/blog\/?p=599"},"modified":"2020-12-24T04:04:31","modified_gmt":"2020-12-23T21:04:31","slug":"map-latitude-longitude-to-shapefile","status":"publish","type":"post","link":"https:\/\/arikuncoro.xyz\/blog\/data-science\/r-python-sql-linux\/map-latitude-longitude-to-shapefile\/","title":{"rendered":"Mapping the geopoint (Latitude &#038; Longitude) to Shapefile"},"content":{"rendered":"\n<p class=\"has-text-color has-drop-cap has-very-dark-gray-color\">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.<\/p>\n\n\n\n<p>This is part of the analysis you may need when you handle GeoSpatial Data.<\/p>\n\n\n\n<p>Thank someone who gave me the example from <a href=\"https:\/\/stackoverflow.com\/questions\/45950770\/map-lat-lon-points-to-a-shape-file-in-r\">this link<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">library(rgdal)\nlibrary(sp)\n\n#load shapefile\ndata.shape <-readOGR(dsn=\"\/nama\/direktori\/shapefile\/anda\",\nlayer=\"nama_shapefile\")\ndata.shape <- spTransform(data.shape, CRS(\"+proj=longlat +datum=WGS84\"))\n\n#create csv file that want to be mapped into shapefile\ncsvfile <- data.frame(LONGITUDE = c(106.6882639, 106.7705755),\nLATITUDE = c(-6.1342941, -6.1642941))\n\n# convert data frame to SpatialPoints class\ncoordinates(csvfile) <- ~LONGITUDE+LATITUDE\n\n# make sure the two files share the same CRS\ncsvfile@proj4string <- data.shape@proj4string\n\n# visual check\nplot(data.shape, border = \"grey\")\npoints(csvfile, col = \"red\", cex = 5)\naxis(1) # showing the axes helps to check whether the coordinates are what you expected\naxis(2)\n\n#mapping\npoints_in_shape <- over(csvfile, data.shape)\n\n#output\npoints_in_shape\n\ufeff<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you want to know what Kelurahan (Village), Kecamatan (District), Kabupaten (Region), and Province are from latitude and longitude. I &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85],"tags":[149,150,151,102,148,152],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/arikuncoro.xyz\/blog\/wp-json\/wp\/v2\/posts\/599"}],"collection":[{"href":"https:\/\/arikuncoro.xyz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arikuncoro.xyz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arikuncoro.xyz\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/arikuncoro.xyz\/blog\/wp-json\/wp\/v2\/comments?post=599"}],"version-history":[{"count":7,"href":"https:\/\/arikuncoro.xyz\/blog\/wp-json\/wp\/v2\/posts\/599\/revisions"}],"predecessor-version":[{"id":957,"href":"https:\/\/arikuncoro.xyz\/blog\/wp-json\/wp\/v2\/posts\/599\/revisions\/957"}],"wp:attachment":[{"href":"https:\/\/arikuncoro.xyz\/blog\/wp-json\/wp\/v2\/media?parent=599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arikuncoro.xyz\/blog\/wp-json\/wp\/v2\/categories?post=599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arikuncoro.xyz\/blog\/wp-json\/wp\/v2\/tags?post=599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}