Friday 31 May 2019

coordinate system - Choosing the correct value for proj4string for shapefile reading in R?



I am having a shapefile of polygons and another CSV file which contains a list of points as (Lat, Lng) pairs..


I want to check for each (lat, lng) pair from the CSV file which polygon does it fall inside..


The shapefile is projected and the proj file reads like this:


PROJCS["Transverse_Mercator",GEOGCS["GCS_OSGB 1936",
DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],UNIT["Meter",1]]

My plan is as follows:



  1. Read the shapefile using the readShapePoly function in the R MapTools package.

  2. Read the points coordinates from the CSV file into a dataframe and convert it to SpatialPointsDataFrame


  3. Use over function to determine which polygon it falls inside.


In order to do so, I need to specify the proj4string while loading the shapefile in step 1 and also transform the coordinates from the CSV file into the same projection system using spTransform function before applying the over function in step 3 as it requires that the points and polygons must be under the same projection system.


Any idea about what should the correct value for the proj file content shown above ?



Answer



The proj4string is a valid PROJ4 crs string.


see How can I get the proj4 string or EPSG code from a shapefile .prj file? and Shapefile PRJ to PostGIS SRID lookup table?


in short:



  • You can use gdalinfo as in the first reference or the GDAL Python bindings as in the second reference.



Or



  • go to Prj2EPSG (a simple service for converting well-known text projection information from .prj files into standard EPSG codes)

  • Enter the content of your prj file


enter image description here




  • the result is EPSG:27700 so a first version of the PROJ4 string is



    "+init=epsg:27700"




`Or



enter image description here




  • click on Proj4 and the complete PROJ4 string is:


    "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs"





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...