7

I think that by using readOGR to import a shapefile renders worthless to put proj4string to the script since if any coords are available in the shapefile, it will be transported through the readOGR.

Therefore, proj4string is expedient only if we use another import function for example readShapeSpatial (for polygons, lines or points) or by using readOGR, but in the case that the shapefile does not contain the coordinates/projection:

When checking if the shapefile has projection information and if it has not, should I add proj4string although I have put readOGR?

5
  • 1
    Is there a question here? Yes, readOGR imports the projection information whereas shapefile import functions in maptools do not. Same goes for export. Apr 22, 2015 at 15:25
  • The question is should i skip proj4string if i use readOGR? or should i check if the shapefile has projection information and if it has not i shall add proj4string although i have put readOGR?
    – gsa
    Apr 22, 2015 at 15:29
  • 2
    Can you please edit your post to make this clear? You do not always get data that has a defined projection to begin with. You can check if your data has a defined projection using proj4string. If it is NA, then you would likely want to define the projection. Apr 22, 2015 at 15:35
  • @JeffreyEvans Sould i use readOGR always when in need to import a shapefile even if it is points or lines?
    – gsa
    Apr 23, 2015 at 5:38
  • 1
    I would say always use readOGR. However, occasionally you get a byte error in the shx file that can be repaired using repair=TRUE in the maptools import functions that is not available in readOGR. Apr 23, 2015 at 13:40

1 Answer 1

10

As JeffreyEvans states, readOGR from the rgdal library imports a CRS if there is one embedded in the shapefile. You can check by (example using a shp I've been playing with):

proj4string(india)  # from the sp package
# [1] "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"

If this returns NA you can specify a CRS with:

proj4string(india) <- CRS("+init=epsg:24383")

You can obtain the EPSG CRS strings from http://spatialreference.org/

To answer your specific question, yes, you should define a projection if one is not specified.


If one is not certain which CRS to assign/define, refer to the following post:

And if one wants to reproject a spatial object in R, i.e., change its projection, then refer to:

3
  • How can i choose a country and provide me its epsg from that site? Please clarify cause i cant found it
    – gsa
    Apr 27, 2015 at 17:00
  • Just search for a country, and the projection(s) most commonly used for that territory will be displayed. For example, here in the UK we use the British National Grid: spatialreference.org/ref/epsg/27700
    – Phil
    Apr 27, 2015 at 20:47
  • okay can you please answer this gis.stackexchange.com/questions/144194/…
    – gsa
    Apr 27, 2015 at 21:29

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.