[R-sig-Geo] WKT coordinate system string (PRJ) to PROJ.4

boB Rudis bob at rudis.net
Tue Jan 5 12:20:11 CET 2016


It's too early I guess as it didn't occur to me that if writing it out
locally was naff using an external service is more so. The
SpatialReference "importFromESRI()" function doesn't seem to be mapped
in rgdal. That would be the function needed to avoid a
write-out/external call.

On Tue, Jan 5, 2016 at 5:57 AM, boB Rudis <bob at rudis.net> wrote:
> This may not be optimal as it uses an external service:
>
>   prj_to_epsg <- function(prj) {
>
>     require(sp)
>     require(httr)
>     require(jsonlite)
>
>     res <- GET("http://prj2epsg.org/search.json",
>                query=list(exact=TRUE,
>                           error=TRUE,
>                           mode="wkt",
>                           terms=prj))
>
>     # one shld prbly do more error checking than this
>     stop_for_status(res)
>
>     dat <- fromJSON(content(res, as="text", flatten=TRUE))
>
>     # NOTE: there could be more in dat$codes if prj was ambiguous
>     CRS(paste0("+init=epsg:", dat$codes[1, "code"]))
>
>   }
>
>   prj <- paste0(readLines("110m_admin_1_states_provinces_shp.prj"))
>   prj_to_epsg(prj)
>   ## CRS arguments:
>   ##  +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84
>   ## +towgs84=0,0,0
>
>   prj_1 <- '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]]'
>   prj_to_epsg(prj_1)
>   ## CRS arguments:
>   ##  +init=epsg:27700 +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717
>   ## +x_0=400000 +y_0=-100000 +datum=OSGB36 +units=m +no_defs +ellps=airy
>   ## +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894
>
> On Tue, Jan 5, 2016 at 5:09 AM, Michael Sumner <mdsumner at gmail.com> wrote:
>> Hello, is there any R-level way to convert a WKT/PRJ *coordinate system*
>> string to PROJ.4 used by sp/rgdal?
>>
>> (Previously I've written out to SHP/PRJ, and read back in with rgdal, but
>> that's obviously a bit naff.)
>>
>> (I know you can rgeos::readWKT and wkb::readWKB for *geometry*).
>>
>> Cheers, Mike.
>>
>>
>>
>>
>> --
>> Dr. Michael Sumner
>> Software and Database Engineer
>> Australian Antarctic Division
>> 203 Channel Highway
>> Kingston Tasmania 7050 Australia
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list