Announcement

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

  • world (ocean) map with spherical coordinates (or transform them into decimal degrees?)

    Hi,

    My goal is to plot specific locations (most of them located in internatinoal waters) on a world map, using "spherical coordinates" stored in two variables (Latitude & Longitude) as shown bellow. I'd appreciate to know if there's an easier way than the one I propose below (or command that I'm not aware of) to a) either transform spherical coordinates to decimal degrees or use a specific command to plot spherical coordinates on a world map.

    My spherical coordinates are stored as follows:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str13 Latitude str14 Longitude
    "15° 21.70' N" "52° 34.10' E" 
    "30° 06.60' N" "47° 55.73' E" 
    "13° 32.70' N" "49° 32.80' E" 
    "30° 06.74' N" "47° 55.90' E" 
    "4° 54.00' N"  "49° 21.00' E" 
    "22° 10.86' N" "91° 47.06' E" 
    "2° 53.00' S"  "107° 18.40' E"
    "2° 58.00' S"  "107° 18.50' E"
    "2° 52.20' S"  "107° 17.50' E"
    "6° 01.30' N"  "3° 17.40' E"  
    "2° 55.00' S"  "107° 18.00' E"
    "3° 04.30' S"  "107° 17.20' E"
    "3° 13.00' N"  "108° 45.00' E"
    "9° 13.00' N"  "14° 06.20' W" 
    "1° 23.50' N"  "104° 27.00' E"
    "17° 52.90' N" "76° 46.60' W" 
    "12° 55.20' N" "49° 36.60' E" 
    "6° 01.00' S"  "106° 52.00' E"
    "19° 04.00' N" "17° 09.00' W" 
    "1° 13.80' N"  "103° 34.80' E"
    "17° 52.70' N" "76° 46.60' W" 
    "9° 16.70' N"  "14° 42.50' W" 
    "1° 57.00' N"  "45° 31.00' E" 
    "3° 10.20' S"  "106° 20.20' E"
    "5° 52.20' S"  "106° 04.50' E"
    "25° 40.00' N" "57° 04.00' E" 
    "5° 53.28' S"  "106° 05.29' E"
    "5° 28.70' S"  "105° 17.60' E"
    "3° 18.50' N"  "112° 55.30' E"
    "4° 55.42' N"  "98° 00.63' E" 
    "4° 38.40' N"  "98° 12.80' E" 
    "5° 17.00' N"  "98° 01.50' E" 
    "10° 15.84' N" "64° 34.60' W" 
    "10° 12.00' S" "112° 15.00' E"
    "5° 16.00' S"  "106° 07.80' E"
    "8° 45.90' S"  "13° 16.60' E" 
    "5° 33.80' S"  "104° 37.00' E"
    "24° 59.40' N" "59° 16.10' E" 
    "24° 08.30' S" "46° 17.20' W" 
    "9° 25.25' N"  "13° 44.30' W" 
    "5° 36.50' N"  "0° 01.10' E"  
    "6° 01.68' S"  "106° 53.84' E"
    "22° 12.68' N" "91° 43.10' E" 
    "6° 19.50' N"  "3° 25.00' E"  
    "8° 29.80' N"  "13° 12.50' W" 
    "22° 16.94' N" "91° 43.08' E" 
    "1° 39.76' N"  "101° 38.30' E"
    "24° 05.10' S" "46° 21.50' W" 
    "24° 07.70' S" "46° 21.00' W" 
    "24° 07.70' S" "46° 18.20' W" 
    end
    http://www.haghish.com/statistics/st.../nearstat.html proposes a formula to achieve the latter:
    "
    Spherical coordinates must be measured in decimal degrees. If your
    coordinates are in a degrees, minutes, and seconds format, you can
    convert them into decimal degrees using the following formula:


    Decimal value = Degrees + (Minutes/60) + (Seconds/3600)


    For instance, a latitude of 122 degrees 45 minutes 45 seconds north
    is equal to 122.7625 degrees north.
    "
    Similarly, https://www.stata.com/manuals/spspdistance.pdf informs about a similar task, however, doesn't solve my task:

    Click image for larger version

Name:	spspdistance.PNG
Views:	1
Size:	206.8 KB
ID:	1569426

    In order to implement the above mentioned formula, I thought
    Code:
    split Latitude
    split Latitude1, p(°) destring
    split Latitude2, p(.) destring
    gen minutes = (Latitude21/60)
    format minutes %5.2g
    split Latitude22, p(') destring
    gen seconds = (Latitude221/3600)
    which yields
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str13 Latitude str14 Longitude str4 Latitude1 str6 Latitude2 str1 Latitude3 byte(Latitude11 Latitude21) str3 Latitude22 float minutes byte Latitude221 float seconds
    "15° 21.70' N" "52° 34.10' E"  "15°" "21.70'" "N" 15 21 "70'"        .35 70 .019444445
    "30° 06.60' N" "47° 55.73' E"  "30°" "06.60'" "N" 30  6 "60'"         .1 60 .016666668
    "13° 32.70' N" "49° 32.80' E"  "13°" "32.70'" "N" 13 32 "70'"  .53333336 70 .019444445
    "30° 06.74' N" "47° 55.90' E"  "30°" "06.74'" "N" 30  6 "74'"         .1 74 .020555556
    "4° 54.00' N"  "49° 21.00' E"  "4°"  "54.00'" "N"  4 54 "00'"         .9  0          0
    "22° 10.86' N" "91° 47.06' E"  "22°" "10.86'" "N" 22 10 "86'"  .16666667 86  .02388889
    "2° 53.00' S"  "107° 18.40' E" "2°"  "53.00'" "S"  2 53 "00'"   .8833333  0          0
    "2° 58.00' S"  "107° 18.50' E" "2°"  "58.00'" "S"  2 58 "00'"   .9666666  0          0
    "2° 52.20' S"  "107° 17.50' E" "2°"  "52.20'" "S"  2 52 "20'"   .8666667 20 .005555556
    "6° 01.30' N"  "3° 17.40' E"   "6°"  "01.30'" "N"  6  1 "30'" .016666668 30 .008333334
    "2° 55.00' S"  "107° 18.00' E" "2°"  "55.00'" "S"  2 55 "00'"   .9166667  0          0
    "3° 04.30' S"  "107° 17.20' E" "3°"  "04.30'" "S"  3  4 "30'"  .06666667 30 .008333334
    "3° 13.00' N"  "108° 45.00' E" "3°"  "13.00'" "N"  3 13 "00'"  .21666667  0          0
    "9° 13.00' N"  "14° 06.20' W"  "9°"  "13.00'" "N"  9 13 "00'"  .21666667  0          0
    "1° 23.50' N"  "104° 27.00' E" "1°"  "23.50'" "N"  1 23 "50'"   .3833333 50  .01388889
    "17° 52.90' N" "76° 46.60' W"  "17°" "52.90'" "N" 17 52 "90'"   .8666667 90       .025
    "12° 55.20' N" "49° 36.60' E"  "12°" "55.20'" "N" 12 55 "20'"   .9166667 20 .005555556
    "6° 01.00' S"  "106° 52.00' E" "6°"  "01.00'" "S"  6  1 "00'" .016666668  0          0
    "19° 04.00' N" "17° 09.00' W"  "19°" "04.00'" "N" 19  4 "00'"  .06666667  0          0
    "1° 13.80' N"  "103° 34.80' E" "1°"  "13.80'" "N"  1 13 "80'"  .21666667 80  .02222222
    "17° 52.70' N" "76° 46.60' W"  "17°" "52.70'" "N" 17 52 "70'"   .8666667 70 .019444445
    "9° 16.70' N"  "14° 42.50' W"  "9°"  "16.70'" "N"  9 16 "70'"  .26666668 70 .019444445
    "1° 57.00' N"  "45° 31.00' E"  "1°"  "57.00'" "N"  1 57 "00'"        .95  0          0
    "3° 10.20' S"  "106° 20.20' E" "3°"  "10.20'" "S"  3 10 "20'"  .16666667 20 .005555556
    "5° 52.20' S"  "106° 04.50' E" "5°"  "52.20'" "S"  5 52 "20'"   .8666667 20 .005555556
    "25° 40.00' N" "57° 04.00' E"  "25°" "40.00'" "N" 25 40 "00'"   .6666667  0          0
    "5° 53.28' S"  "106° 05.29' E" "5°"  "53.28'" "S"  5 53 "28'"   .8833333 28 .007777778
    "5° 28.70' S"  "105° 17.60' E" "5°"  "28.70'" "S"  5 28 "70'"   .4666667 70 .019444445
    "3° 18.50' N"  "112° 55.30' E" "3°"  "18.50'" "N"  3 18 "50'"         .3 50  .01388889
    "4° 55.42' N"  "98° 00.63' E"  "4°"  "55.42'" "N"  4 55 "42'"   .9166667 42 .011666667
    "4° 38.40' N"  "98° 12.80' E"  "4°"  "38.40'" "N"  4 38 "40'"   .6333333 40  .01111111
    "5° 17.00' N"  "98° 01.50' E"  "5°"  "17.00'" "N"  5 17 "00'"  .28333333  0          0
    "10° 15.84' N" "64° 34.60' W"  "10°" "15.84'" "N" 10 15 "84'"        .25 84 .023333333
    "10° 12.00' S" "112° 15.00' E" "10°" "12.00'" "S" 10 12 "00'"         .2  0          0
    "5° 16.00' S"  "106° 07.80' E" "5°"  "16.00'" "S"  5 16 "00'"  .26666668  0          0
    "8° 45.90' S"  "13° 16.60' E"  "8°"  "45.90'" "S"  8 45 "90'"        .75 90       .025
    "5° 33.80' S"  "104° 37.00' E" "5°"  "33.80'" "S"  5 33 "80'"        .55 80  .02222222
    "24° 59.40' N" "59° 16.10' E"  "24°" "59.40'" "N" 24 59 "40'"   .9833333 40  .01111111
    "24° 08.30' S" "46° 17.20' W"  "24°" "08.30'" "S" 24  8 "30'"  .13333334 30 .008333334
    "9° 25.25' N"  "13° 44.30' W"  "9°"  "25.25'" "N"  9 25 "25'"   .4166667 25 .006944444
    "5° 36.50' N"  "0° 01.10' E"   "5°"  "36.50'" "N"  5 36 "50'"         .6 50  .01388889
    "6° 01.68' S"  "106° 53.84' E" "6°"  "01.68'" "S"  6  1 "68'" .016666668 68  .01888889
    "22° 12.68' N" "91° 43.10' E"  "22°" "12.68'" "N" 22 12 "68'"         .2 68  .01888889
    "6° 19.50' N"  "3° 25.00' E"   "6°"  "19.50'" "N"  6 19 "50'"   .3166667 50  .01388889
    "8° 29.80' N"  "13° 12.50' W"  "8°"  "29.80'" "N"  8 29 "80'"   .4833333 80  .02222222
    "22° 16.94' N" "91° 43.08' E"  "22°" "16.94'" "N" 22 16 "94'"  .26666668 94  .02611111
    "1° 39.76' N"  "101° 38.30' E" "1°"  "39.76'" "N"  1 39 "76'"        .65 76  .02111111
    "24° 05.10' S" "46° 21.50' W"  "24°" "05.10'" "S" 24  5 "10'"  .08333334 10 .002777778
    "24° 07.70' S" "46° 21.00' W"  "24°" "07.70'" "S" 24  7 "70'"  .11666667 70 .019444445
    "24° 07.70' S" "46° 18.20' W"  "24°" "07.70'" "S" 24  7 "70'"  .11666667 70 .019444445
    end
    The next step, which I have not done so far (and that might be suceptible to errors) would be to format vars. minutes & seconds as having two decimals only, join them together with var. Latitude 11 into one new variable and check whether Stata can plot that generated variable on a world map. I'm afraid these latter steps (and my whole appoach) might (best case scenario) plot wrong points, though.

    I'd appreciate any comment on the matter.

    Victor
    Victor Cruz

  • #2
    Maybe this thread will be helpful: https://www.statalist.org/forums/for...de-to-decimals
    Best regards,

    Marcos

    Comment


    • #3
      Originally posted by Marcos Almeida View Post
      Thanks. Unfortunately, the online tool is designed to transform UK coordinates only (it warns about it in advance
      Latitude hemisphere is omitted as irrelevant within GB.
      ) Still, I gave it a try as follows:

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str13 Latitude str14 Longitude
      "15° 21.70' N" "52° 34.10' E" 
      "30° 06.60' N" "47° 55.73' E" 
      "13° 32.70' N" "49° 32.80' E" 
      "30° 06.74' N" "47° 55.90' E" 
      "4° 54.00' N"  "49° 21.00' E" 
      "22° 10.86' N" "91° 47.06' E" 
      "2° 53.00' S"  "107° 18.40' E"
      "2° 58.00' S"  "107° 18.50' E"
      "2° 52.20' S"  "107° 17.50' E"
      "6° 01.30' N"  "3° 17.40' E"  
      "2° 55.00' S"  "107° 18.00' E"
      "3° 04.30' S"  "107° 17.20' E"
      "3° 13.00' N"  "108° 45.00' E"
      "9° 13.00' N"  "14° 06.20' W" 
      "1° 23.50' N"  "104° 27.00' E"
      "17° 52.90' N" "76° 46.60' W" 
      "12° 55.20' N" "49° 36.60' E" 
      "6° 01.00' S"  "106° 52.00' E"
      "19° 04.00' N" "17° 09.00' W" 
      "1° 13.80' N"  "103° 34.80' E"
      "17° 52.70' N" "76° 46.60' W" 
      "9° 16.70' N"  "14° 42.50' W" 
      "1° 57.00' N"  "45° 31.00' E" 
      "3° 10.20' S"  "106° 20.20' E"
      "5° 52.20' S"  "106° 04.50' E"
      "25° 40.00' N" "57° 04.00' E" 
      "5° 53.28' S"  "106° 05.29' E"
      "5° 28.70' S"  "105° 17.60' E"
      "3° 18.50' N"  "112° 55.30' E"
      "4° 55.42' N"  "98° 00.63' E" 
      "4° 38.40' N"  "98° 12.80' E" 
      "5° 17.00' N"  "98° 01.50' E" 
      "10° 15.84' N" "64° 34.60' W" 
      "10° 12.00' S" "112° 15.00' E"
      "5° 16.00' S"  "106° 07.80' E"
      "8° 45.90' S"  "13° 16.60' E" 
      "5° 33.80' S"  "104° 37.00' E"
      "24° 59.40' N" "59° 16.10' E" 
      "24° 08.30' S" "46° 17.20' W" 
      "9° 25.25' N"  "13° 44.30' W" 
      "5° 36.50' N"  "0° 01.10' E"  
      "6° 01.68' S"  "106° 53.84' E"
      "22° 12.68' N" "91° 43.10' E" 
      "6° 19.50' N"  "3° 25.00' E"  
      "8° 29.80' N"  "13° 12.50' W" 
      "22° 16.94' N" "91° 43.08' E" 
      "1° 39.76' N"  "101° 38.30' E"
      "24° 05.10' S" "46° 21.50' W" 
      "24° 07.70' S" "46° 21.00' W" 
      "24° 07.70' S" "46° 18.20' W" 
      end
      In order to end up with a .csv according to what the website requires:
      ETRS89 Geodetic ( Degrees, Minutes, Seconds )

      ETRS89 Coordinates in a Degrees Minutes Seconds notation. Latitude hemisphere is omitted as irrelevant within GB. NOTATION:

      [Degrees Latitude], [Minutes Latitude], [Seconds Latitude], [Longitude Hemisphere], [Degrees Longitude], [Minutes Longitude], [Seconds Longitude] (, [optional ETRS89 ellipsoidal height]) EXAMPLE:

      50, 54, 26.42, W, 1, 49, 50.49, 0
      I executed
      Code:
      split Latitude
      split Latitude1, p(°) destring
      split Latitude2, p(.) destring
      gen minutes = (Latitude21/60)
      split Latitude22, p(') destring
      gen seconds = (Latitude221/3600)
      rename Latitude11 degrees
      rename Latitude3 hemisphere
      br Latitude degrees minutes seconds hemisphere
      tostring Latitude degrees minutes seconds hemisphere, replace force
      replace minutes=substr(minutes,1,3)
      replace seconds=substr(seconds,1,3)
      
      split Longitude
      split Longitude1, p(°) destring
      split Longitude2, p(.) destring
      gen minutesL = (Longitude21/60)
      split Longitude22, p(') destring
      gen secondsL = (Longitude221/3600)
      rename Longitude11 degreesL
      rename Longitude3 hemisphereL
      tostring Longitude degreesL minutesL secondsL hemisphereL, replace force
      replace minutesL=substr(minutesL,1,3)
      replace secondsL=substr(secondsL,1,3)
      br Latitude degrees minutes seconds hemisphere Longitude degreesL minutesL secondsL hemisphereL
      replace minutes= subinstr(minutes,".",",",.)
      foreach j in seconds minutesL secondsL {
      replace `j'= subinstr(`j',".",",",.)
      }
      gen latitude=degrees+minutes+seconds+","+hemisphere 
      gen longitude=degreesL+minutesL+secondsL+","+hemisphereL 
      gen spheric=latitude+","+longitude
      keep spheric
      dataex
      save spheric, replace
      export delimited using spheric, replace
      and ended up with

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str21 spheric
      "15,34,01,N,52,56,00,E"
      "30,10,01,N,47,91,02,E"
      "13,53,01,N,49,53,02,E"
      "30,10,02,N,47,91,02,E"
      "4,890,N,49,340,E"     
      "22,16,02,N,91,78,00,E"
      "2,880,S,107,30,01,E"  
      "2,960,S,107,30,01,E"  
      "2,86,00,S,107,28,01,E"
      "6,01,00,N,3,28,01,E"  
      "2,910,S,107,300,E"    
      "3,06,00,S,107,28,00,E"
      "3,210,N,108,750,E"    
      "9,210,N,14,10,00,W"   
      "1,38,01,N,104,440,E"  
      "17,86,02,N,76,76,01,W"
      "12,91,00,N,49,60,01,E"
      "6,010,S,106,860,E"    
      "19,060,N,17,150,W"    
      "1,21,02,N,103,56,02,E"
      "17,86,01,N,76,76,01,W"
      "9,26,01,N,14,69,01,W" 
      "1,940,N,45,510,E"     
      "3,16,00,S,106,33,00,E"
      "5,86,00,S,106,06,01,E"
      "25,660,N,57,060,E"    
      "5,88,00,S,106,08,00,E"
      "5,46,01,S,105,28,01,E"
      "3,30,01,N,112,91,00,E"
      "4,91,01,N,980,01,E"   
      "4,63,01,N,98,20,02,E" 
      "5,280,N,98,01,01,E"   
      "10,25,02,N,64,56,01,W"
      "10,200,S,112,250,E"   
      "5,260,S,106,11,02,E"  
      "8,75,02,S,13,26,01,E" 
      "5,55,02,S,104,610,E"  
      "24,98,01,N,59,26,00,E"
      "24,13,00,S,46,28,00,W"
      "9,41,00,N,13,73,00,W" 
      "5,60,01,N,0,01,00,E"  
      "6,01,01,S,106,88,02,E"
      "22,20,01,N,91,71,00,E"
      "6,31,01,N,3,410,E"    
      "8,48,02,N,13,20,01,W" 
      "22,26,02,N,91,71,00,E"
      "1,64,02,N,101,63,00,E"
      "24,08,00,S,46,34,01,W"
      "24,11,01,S,46,340,W"  
      "24,11,01,S,46,30,00,W"
      end
      which I uploaded to the recommended website, and yielded:
      0 coordinates were detected of which 3867 could not be converted.
      I'd appreciate further comments.
      Victor Cruz

      Comment


      • #4
        I've just realized that the data that I provided above is in "ETRS89 Geodetic ( Degrees, Decimal Minutes )". The website above recommended should also be able to transform that kind of data i.e.,
        ETRS89 Coordinates in a Degrees Decimal Minutes notation. Latitude hemisphere is omitted as irrelevant within GB.NOTATION:
        [Degrees Latitude], [Decimal Minutes Latitude], [Longitude Hemisphere], [Degrees Longitude], [Decimal Minutes Longitude](, [optional ETRS89 ellipsoidal height])
        EXAMPLE:
        50, 26.42, W, 1, 50.49, 0
        and if I instead execute the following lines in order to export one variable according to the last quote, the website still is not able to transform (recognize) my coordinates, presumably because it only works with UK coordinates.

        Code:
        split Latitude
        split Latitude1, p(°) 
        split Latitude2, p(') 
        gen latitude=Latitude11+","+Latitude21+","+Latitude3
        split Longitude
        split Longitude1, p(°) 
        split Longitude2, p(') 
        gen longitude=Longitude11+","+Longitude21+","+Longitude3
        keep Latitude Longitude latitude longitude
        gen spheric=latitude+","+longitude
        keep spheric
        save spheric, replace
        export delimited using "sphericcsv", replace
        I'd appreciate your support
        Victor Cruz

        Comment

        Working...
        X