Tom Roche
2012-Dec-31 02:49 UTC
[R] code to convert 3D geographical coordinates to Cartesian?
Is there packaged code to convert geographical coordinates (e.g., longitude, latitude, elevation) to Cartesian coordinates in 3-space? I can see how to do this using 1. a spherical-to-Cartesian conversion like pracma::sph2cart(tpr) http://cran.r-project.org/web/packages/pracma/ 2. a geographical-to-spherical conversion. This seems to involve (in roughly increasing order of difficulty or error-prone-ness) * converting longitude (units=?) to an azimuthal angle (units=rad) * converting latitude (units=?) to a polar angle (aka inclination) (units=rad) * converting elevation (usually, distance above mean sea level) to radial distance (i.e., distance from earth center). Ideally this should be done using a user-chosen coordinate reference system and ellipsoid/geoid (i.e., PROJ.4-style), hence my hope that some package (of which I'm currently unaware) has already coded this The Right Way. For now, for the atmospheric model with which I need to work, I believe I can just assume a spherical earth with r=6370 km, and just add that to the elevation. 3. composition of the two (e.g., sph2cart(geo2sph(lat.lon.elev))), noting that package=pracma uses the mathematics convention that azimuth=? and polar angle=? (vs the reverse physics convention). Net: the task seems straightforward enough, but there's certainly scope for error, so I'd prefer to use tested, well-used code if available. Am I missing something? TIA, Tom Roche <Tom_Roche at pobox.com>
Bert Gunter
2012-Dec-31 03:37 UTC
[R] code to convert 3D geographical coordinates to Cartesian?
Have you checked the spatial stats task view on CRAN? http://cran.r-project.org/web/views/Spatial.html -- Bert On Sun, Dec 30, 2012 at 6:49 PM, Tom Roche <Tom_Roche@pobox.com> wrote:> > Is there packaged code to convert geographical coordinates (e.g., > longitude, latitude, elevation) to Cartesian coordinates in 3-space? > I can see how to do this using > > 1. a spherical-to-Cartesian conversion like pracma::sph2cart(tpr) > > http://cran.r-project.org/web/packages/pracma/ > > 2. a geographical-to-spherical conversion. This seems to involve (in > roughly increasing order of difficulty or error-prone-ness) > > * converting longitude (units=°) to an azimuthal angle (units=rad) > > * converting latitude (units=°) to a polar angle (aka inclination) > (units=rad) > > * converting elevation (usually, distance above mean sea level) to > radial distance (i.e., distance from earth center). Ideally this > should be done using a user-chosen coordinate reference system and > ellipsoid/geoid (i.e., PROJ.4-style), hence my hope that some package > (of which I'm currently unaware) has already coded this The Right Way. > For now, for the atmospheric model with which I need to work, I > believe I can just assume a spherical earth with r=6370 km, and just > add that to the elevation. > > 3. composition of the two (e.g., sph2cart(geo2sph(lat.lon.elev))), > noting that package=pracma uses the mathematics convention that > azimuth=Θ and polar angle=φ (vs the reverse physics convention). > > Net: the task seems straightforward enough, but there's certainly scope > for error, so I'd prefer to use tested, well-used code if available. > Am I missing something? > > TIA, Tom Roche <Tom_Roche@pobox.com> > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[alternative HTML version deleted]]
Tom Roche
2012-Dec-31 04:14 UTC
[R] code to convert 3D geographical coordinates to Cartesian?
https://stat.ethz.ch/pipermail/r-help/2012-December/332658.html>> Is there packaged code to convert geographical coordinates (e.g., >> longitude, latitude, elevation) to Cartesian coordinates in 3-space?...>> Net: the task seems straightforward enough, but there's certainly >> scope for error, so I'd prefer to use tested, well-used code if >> available.https://stat.ethz.ch/pipermail/r-help/2012-December/332666.html> Have you checked the spatial stats task view on CRAN?> http://cran.r-project.org/web/views/Spatial.htmlI have, and can't believe that functionality this fundamental is not API. But I have looked at several packages and am not seeing it. I suspect that either it's so low-level that it's just not exposed as API, or just that there is API but I'm not seeing it in the package docs ("hidden in plain sight"). Hence I ask>> Am I missing something?TIA, Tom Roche <Tom_Roche at pobox.com>