Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • XYZ coordinates of the 'globe'

    Dear Statalisters,

    My question is not Stata related as such, but because there are packages like geocircles or geo2XY (from SSC by Robert Picard) that deal with geo-mapping, possibly someone can answer my question.

    I am looking for XYZ coordinates of positions on earth, i.e. our globe.
    For example, of capitals, or (sketchy) the coastline of the continents.

    So, it concerns the '3D Cartesian coordinates', Earth centered, Earth fixed (ECEF) coordinates in relation to latitude and longitude (from Wikipedia):
    Click image for larger version

Name:	Cartesian XYZs.jpg
Views:	1
Size:	1.29 MB
ID:	1546831



    I have searched at many sites and asked around by several organisations but so far without any result.

    So, should you know where to go for such data, your help is much appreciated.
    Last edited by ericmelse; 14 Apr 2020, 11:24. Reason: Added link to the source of the snapshot.
    http://publicationslist.org/eric.melse

  • #2

    Taken from here: https://stackoverflow.com/questions/...an-coordinates


    Code:
    python:
    # Converting lat/long to cartesian
    import numpy as np
    from sfi import Data
    def get_cartesian(lat=None,lon=None):
        lat, lon = np.deg2rad(lat), np.deg2rad(lon)
        R = 6371 # radius of the earth
        x = R * np.cos(lat) * np.cos(lon)
        y = R * np.cos(lat) * np.sin(lon)
        z = R *np.sin(lat)
        return x,y,z
    
    get_cartesian(lat = 51.5074 , lon = 0.2178)
    end
    
    //or in Stata
    local latitude = 51.5074
    local longitude = 0.2178
    
    scalar r_lat = `latitude'*_pi/180
    scalar r_long = `longitude'*_pi/180
    
    scalar x =  6371 * cos(r_lat) * cos(r_long)
    scalar y =  6371 * cos(r_lat) * sin(r_long)
    scalar z = 6371*sin(r_lat)
    disp x,y,z
    If you have your data points in terms of latitude and longitude you can convert them. For example here a data set of latitude and longitude of world capitals.

    Comment


    • #3
      Dear Scott,

      Excellent advise, I have got it all working!

      Many thanks.
      http://publicationslist.org/eric.melse

      Comment

      Working...
      X