0

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.

  • 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 cran.rstudio.com/web/packages/geoaxe for one way. – mdsumner Sep 7 '16 at 6:42
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.

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

  • 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? – joker21 Sep 7 '16 at 6:36
  • 1
    You should add this detail about requirements to your original question. – hrbrmstr Sep 8 '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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.