【问题标题】:Converting ISO 6709 Formatted GPS Coordinates to Decimal Degrees in R将 ISO 6709 格式的 GPS 坐标转换为 R 中的十进制度
【发布时间】:2017-01-05 04:11:01
【问题描述】:

我们有一台设备将其 GPS 坐标输出为数值,以 ISO 6709 lat/lon 格式 Lat = ±DDMM.MMMM & Lon = ±DDDMM.MMMM

在 R 中是否有任何带有函数(或自定义函数)的包可以将其转换为十进制度数格式? (即:±DD.DDDDDD & ±DDD.DDDDDD)

例如,lat & lon (2433.056, -8148.443) 将被转换为 (24.55094, -81.80739)。

【问题讨论】:

  • 对您的问题没有直接的兴趣,但 R 中有一个完整的系统可以从纬度/经度转换为各种投影。
  • 感谢您的评论。我查看了“MapProj”和“MapTools”包,但没有看到它们在哪里能够完成上述任务。如果可以,请告诉。
  • 我相信 proj4 包也有一些功能。我已经有一段时间没有做这件事了,但我记得有一种财富的尴尬。

标签: r gps iso


【解决方案1】:

您可以使用read.csvread.delim 之类的方式从文件中读取值。

然后,要从 DDMM.MMMM 和 DDDMM.MMMM 转换,您可以使用类似这样的东西(当然根据需要修改输入/输出的形式):

convertISO6709 <- function( lat, lon ) {
    # will just do lat and lon together, as the process is the same for both
    # It's simpler to do the arithmetic on positive numbers, we'll add the signs
    #  back in at the end.
    latlon <- c(lat,lon)
    sgns   <- sign(latlon)
    latlon <- abs(latlon)

    # grab the MM.MMMM bit, which is always <100. '%%' is modular arithmetic.
    mm <- latlon %% 100

    # grab the DD bit. Divide by 100 because of the MM.MMMM bit.
    dd <- (latlon - mm)/100

    # convert to decimal degrees, don't forget to add the signs back!
    out_latlon <- (dd+mm/60) * sgns
    return(out_latlon)
}

【讨论】:

  • 干得好 - 不知道“sign”函数,试图用 if 语句和
【解决方案2】:

这可能不是最优雅的 PHP 代码,但它确实有效:

function convertISO6709($coord)
{
    $abs_coord = abs($coord);
    $sign = ($abs_coord == $coord) ? 1 : -1;
    $m = 2;
    $dlen = 2;
    $s = 0;
    $seconds = 0;
    switch (strlen($abs_coord)) {
        case 4 :
            break;
        case 5 :
            $dlen = 3;
            $m = 3;
            break;
        case 6 :
            $s = 4;
            break;
    }
    $degrees = substr($abs_coord, 0, $dlen);
    $minutes = substr($abs_coord, $m, 2);
    if ($s != 0) {
        $seconds = substr($abs_coord, $s, 2);
    }
    return ($degrees + ($minutes / 60)  + ($seconds / 3600)) * $sign;
}

【讨论】:

    【解决方案3】:

    我在从 FedEx WS 获取坐标时遇到了类似的问题。我使用此函数从 +19.467945-99.14357/ 之类的字符串中获取值:

    function convertCoordISO6709($coord)
    {
      //$coord example
      //$coord = +19.467945-99.14357/
    
      $returnArray[0] = 1;//result non 0 means error
      $returnArray[1] = 0;//Lat
      $returnArray[2] = 0;//long
    
      $coord = trim($coord,"/"); //Strip / sign
      //look for + - sign
      $lat_sign = substr($coord,0,1);  //strip and save the first sign (latitude value)
    
      $sub_coord = substr($coord,1,strlen($coord));
    
      if(count(explode("+",$sub_coord)) == 2) //Second value is + for the longitude
      {
        $coords=explode("+",$sub_coord);
        $returnArray[0] = 0;
        $returnArray[1] =  $lat_sign.$coords[0];
        $returnArray[2] =  "+".$coords[1];    
      }
      else //Second value is - for the longitude
      {
        $coords=explode("-",$sub_coord);
        $returnArray[0] = 0;    
        $returnArray[1] =  $lat_sign.$coords[0];
        $returnArray[2] =  "-".$coords[1];      
      }
    
    
      return $returnArray;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-01-11
      • 2021-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-23
      • 1970-01-01
      • 1970-01-01
      • 2013-04-14
      相关资源
      最近更新 更多