Grasshopper

algorithmic modeling for Rhino

Best way to translate latitude / longitude data into xyz points?

Hi All,

I have a list of latitude / longitude coordinates, formatted as columns in an excel doc. I'd like to be able to bring these in to GH and use to construct xyz points. For now, they don't actually have to be referenced to anything other than each other. I've taken a quick look at previous posts, which all seem to point to Elk, but Elk seems to be tied specifically to OSM data, which is not what I'm working with. Any suggestions on how best to approach this task? Does anyone know of a formula for translating latitude / longitude values into xyz coordinates (forgive my lackluster geography knowledge here...)?

Excel doc with sample values attached...

Thanks!

Views: 6774

Attachments:

Replies to This Discussion

Lunchbox  converts to datatree or you can write your own script (always the best option for custom needs). Just be caseful with numbers x.xxxxxxxxxxxxxxxxxx, as those strings will be rounded  to doubles that are able to store in memory

Hi Petras,

Thanks for your reply - and I apologize, I realize that I was not at all clear in my initial question! I know how to bring the data in - and would be doing pretty much exactly what you've outlined nicely in your suggestion. My issue is that I believe there needs to be some kind of formula in order to get from lat / long coords to xyz space. When I try plotting as the lat / long coords directly, the geometry looks really off, so I feel like I'm probably missing something? Any geographers out there able to weigh in?

just google this stuff how to convert latitude longitude to cartesian coordinates:

https://stackoverflow.com/questions/1185408/converting-from-longitude-latitude-to-cartesian-coordinates

Because your coordinates are on sphere, while you are mapping to 2D space.

and then smb can say that 

 You are assuming the earth is a sphere, while WGS-84 assumes an ellipsoid

Copy paste:

Just to make the definition complete, in the Cartesian coordinate system:

  • the x-axis goes through long,lat (0,0), so longitude 0 meets the equator;
  • the y-axis goes through (0,90);
  • and the z-axis goes through the poles.

The conversion is:

x = R * cos(lat) * cos(lon)  y = R * cos(lat) * sin(lon)  z = R *sin(lat) 

Where R is the approximate radius of earth (e.g. 6371KM).

If your trigonometric functions expect radians (which they probably do), you will need to convert your longitude and latitude to radians first. You obviously need a decimal representation, not degrees\minutes\seconds (see e.g. here about conversion).

The formula for back conversion:

   lat = asin(z / R)    lon = atan2(y, x) 

asin is of course arc sine. read about atan2 in wikipedia. Don’t forget to convert back from radians to degrees.

So it boils down to:

var earthRadius = 6367; //radius in km
public Point3d
convertSphericalToCartesian(latlong)
{
    var lat = DegtoRad (latlong.Latitude);
    var lon = DegtoRad (latlong.Longitude);
    var x = earthRadius * Math.cos(lat)*Math.cos(lon);
    var y = earthRadius * Math.cos(lat)*Math.sin(lon);
    var z = earthRadius * Math.sin(lat);
    return new Point3d(x,y,z);
}

Hi Petras,

This is great! Thanks so much for all the info - I really didn't know where to start, but this gives me a lot to work with. I'll dig into it and see how it goes...

The last reply is literally math functions achievable though grasshopper component, just read line by line and recreate.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service