Reading and projecting lat/long point coordinates using R?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Reading and projecting lat/long point coordinates using R?

Rick Reeves


Hello:

I've searched the literature, havent found an answer, so here goes?

We have a set of polygon features defined as a series of unprojected
vertices represented by lat/long pairs, in an ASCII-format file.

We need to display (on a map-like plot) and then calculate the areas
of the polygons, and would like to do this entirely within R if
possible.
Is there a map projection package for R? Or, has anyone solved this
or a related problem using R? I could do this with the MATLAB mapping
toolbox, but prefer to use R if possible....


Thanks,

Rick Reeves

Scientific Programmer / Quantitative Analyst
National Center for Ecological Analysis and Synthesis
University of California, Santa Barbara
805 892 2534
reeves at nceas.ucsb.edu



Reply | Threaded
Open this post in threaded view
|

Reading and projecting lat/long point coordinates using R?

Sander Oom
Hi Rick,

Map projections can be done with the package proj4R developed by Roger
Bivand (http://spatial.nhh.no/R/Devel/). Roger send me a development
version to use with R2.0.1.

This is the code I use to project to Albers equal area and UTM in South
Africa (the projection settings listed in the comments come from GRASS):

   ## Project data with proj4R
   datSable.XY <- cbind(datSable$Longitude, datSable$Latitude)
   ## Albers Equal Area projection for SA
   ## elipse or datum    WGS84
   ## false eastings     0
   ## false northing     0
   ## central meridian   24
   ## stand parr_1       -18
   ## stand parr_2       -32
   ## lat of origin      0
   ## output of project is a matrix!
   datSable.XYaea <- project(datSable.XY, "+proj=aea +ellps=WGS84
+lon_0=24 +lat_0=0 +lat_1=18s +lat_2=32s +x_0=0 +y_0=0 ")
   nrow(datSable.XYaea)
   tmp <- data.frame(datSable.XYaea)
   datSable <- data.frame(datSable, Xaea=tmp$X1, Yaea=tmp$X2)
# name: UTM
# datum: WGS84
# towgs84: 0.000,0.000,0.000
# proj: utm
# ellps: wgs84
# a: 6378137.0000000000
# es: 0.0066943800
# f: 298.2572235630
# zone: 36
# south: defined
   datSable.XYutm <- project(datSable.XY, "+proj=utm +ellps=WGS84
+zone=36S +south +units=m ")

This should work on polygon coordinates to!

The packages maps and maptools might provide a solution to the area of
the polygons.

Let me know what you manage to do. I am trying similar things: see
earlier posts on the r-geo list.

Cheers,

Sander.

Rick Reeves wrote:

>
> Hello:
>
> I've searched the literature, havent found an answer, so here goes?
>
> We have a set of polygon features defined as a series of unprojected
> vertices represented by lat/long pairs, in an ASCII-format file.
>
> We need to display (on a map-like plot) and then calculate the areas
> of the polygons, and would like to do this entirely within R if
> possible.
> Is there a map projection package for R? Or, has anyone solved this
> or a related problem using R? I could do this with the MATLAB mapping
> toolbox, but prefer to use R if possible....
>
>
> Thanks,
>
> Rick Reeves
>
> Scientific Programmer / Quantitative Analyst
> National Center for Ecological Analysis and Synthesis
> University of California, Santa Barbara
> 805 892 2534
> reeves at nceas.ucsb.edu
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

--
--------------------------------------------
Dr. Sander P. Oom
Animal, Plant and Environmental Sciences,
University of the Witwatersrand
Private Bag 3, Wits 2050, South Africa
Tel (work)      +27 (0)11 717 64 04
Tel (home)      +27 (0)18 297 44 51
Fax             +27 (0)18 299 24 64
Email   sander at oomvanlieshout.net
Web     www.oomvanlieshout.net/sander



Reply | Threaded
Open this post in threaded view
|

Re: Reading and projecting lat/long point coordinates using R?

Anthony Westerling-3
If you want a base map to add your polygons to, you can use the Maps
package in R, or plot a map from a shapefile or arcinfo coverage using
Rmap or maptools libraries (for shapefile format) or RArcInfo (for e00
or avc formats) in R.  To add your polygons to the figure just use
polygon().  If you need to reproject the coordinates in your polygons
you can use mapproject() in the mapproj library or project() in Rmap().
  I prefer project() (it can convert from a projection to geographic
coordinates (ie, lat/lon), while I think mapproject() just takes
geographic coordinates) but mapproject() has more documentation.  Both
use proj4 library (libproj), so you will need to install that.  To use
shapefiles you need libshp.

I think Rmap is still not distributed via CRAN.  You can find it at
http://www.maths.lancs.ac.uk/Software/Rmap/

I've linked the documentation for the proj4 library to Barry
Rowlingson's Rmap documentation, which can be useful when you are
re-projecting coordinates.  If you want it,  the zipped html files are
~9 MB.  The original sources are on the web of course.

areapl() in the splancs library can calculate the area of a polygon.

Anthony L. Westerling
Climate Research Division
Scripps Institution of Oceanography
University of California, San Diego
858 822 4057
leroy at ucsd.edu

> Date: Wed, 30 Mar 2005 11:42:17 -0800
> From: "Rick Reeves" <reeves at nceas.ucsb.edu>
> Subject: [R-sig-Geo] Reading and projecting lat/long point coordinates
> using R?
> To: <r-sig-geo at stat.math.ethz.ch>
> Message-ID: <000001c53560$9484c970$8bdc6f80 at BURAN>
> Content-Type: text/plain; charset="us-ascii"
>
>
>
> Hello:
>
> I've searched the literature, havent found an answer, so here goes?
>
> We have a set of polygon features defined as a series of unprojected
> vertices represented by lat/long pairs, in an ASCII-format file.
>
> We need to display (on a map-like plot) and then calculate the areas
> of the polygons, and would like to do this entirely within R if
> possible.
> Is there a map projection package for R? Or, has anyone solved this
> or a related problem using R? I could do this with the MATLAB mapping
> toolbox, but prefer to use R if possible....
>
>
> Thanks,
>
> Rick Reeves
>
> Scientific Programmer / Quantitative Analyst
> National Center for Ecological Analysis and Synthesis
> University of California, Santa Barbara
> 805 892 2534
> reeves at nceas.ucsb.edu
>
>
>
> ------------------------------
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
> End of R-sig-Geo Digest, Vol 19, Issue 15
> *****************************************
>