Tuesday, 3 October 2017

r - Checking if Lng and Lat fall inside polygons from ESRI Shapefile


I have two input files.


First: CSV file with a list of points each defined with Lng, Lat, Name


Second: ESRI Shapefile defining a number of polygons


I would like to determine for each point I have (from the CSV file) which polygon does it fall inside (if any)?



I will be using R.


I know that this might be a straightforward task but I am totally a newbie to GIS.


I have done some searching, and I have found that I can use "MapTools" package in R to load the ESRI shapefile, but I don't know how to move after that.


I managed to read the shapefile using readShapePoly function in the MapTools package and now I can plot the polygons and iterate through them in R. I also loaded the points from the CSV file into a data frame with two columns (lng, lat). Now I need to check for each point which polygon does it fall inside (if any)...


I managed to do this using the function over from package sp in the way explained here, however I am getting NA result for all points which is unexpected. I think it is due to different projections for the points and polygons.. Examining the polygons loaded from the shapefile using summary function gives me Is projected: NA, proj4string : [NA]


Any tips ?


Any advice, good tutorial or code sample showing how to do that would be highly appreciated.




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...