1

I am a newbie to R and I want to divide a country map into grids so that I can come to a decision according to the latitude and longitude values which grid am I residing.

I am looking for an example (R code) how to this.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
joker
  • 227
  • 2
  • 5
  • 14
  • See the raster package. Create a raster() with the offset and resolution you want, and use cellFromXY(ras, xy). If you want to tile the polygon map (you don't really say) see https://cran.rstudio.com/web/packages/geoaxe/ for one way. – mdsumner Sep 07 '16 at 06:42

3 Answers3

2

If you want to draw gridlines on a map, have a look at https://edzer.github.io/sp/, and especially at the sp::gridlines function.

Jannes
  • 672
  • 3
  • 8
0

You can create a polygon fishnet offline using GIS tools and plot the data along with fishnet.Alternatively a complete R-base solution is provided in SE link here Overlay a spatial polygon with a grid and check in which grid element specific coordinates are located

addcolor
  • 1,282
  • 9
  • 19
  • Thank you for the answer @Durga .But the link is for a shape file where my file is a google map.Could you please help me? – joker Sep 07 '16 at 06:36
  • 1
    You should add this detail about requirements to your original question. – hrbrmstr Sep 08 '16 at 10:36
0

The most easy way to make that is using the map.grid() function. Pls visit the page https://www.rdocumentation.org/packages/mapproj/versions/1.2-5/topics/map.grid. The documentation is very simple and obvious. Let me know if you have issues still/

J.Pan
  • 1