0

我编写了一个从一些 KML 文件中提取坐标的 perl 脚本。像这样:

if ($start ne 6) 
  {
  $sheet = substr($line,$start,$end-$start);
  }
  $start =  index($line,"<coordinates>") + 13;
  $end = index($line,"</coordinates>");
  $coords = substr($line,$start,$end-$start); 
if ($start ne 12) 
  {
  @values = split (' ',$coords);
  foreach (@values) {}
  my (@lat, @long);
( $lat[@lat], $long[@long] )
    = split /,/ for @values;

这将从该行中提取坐标: <Polygon><outerBoundaryIs><LinearRing><coordinates>-4.799999989183125,54.479999998144478 -5.399999989687073,54.479999998084068 -5.409999989614521,54.739999998345262 -4.809999989103597,54.749999998414239 -4.799999989183125,54.479999998144478</coordinates></LinearRing></outerBoundaryIs></Polygon>

<LinearRing><coordinates>但是当我有多个环形多边形在一行中多次重复标签时,它只会检索第一组坐标(如您所料)。

所以我的问题是:有没有一种方法可以修改我已经必须适应多重多边形,或者我必须使用不同的解析技术?

谢谢。

4

1 回答 1

0

我通过用反向索引替换索引来修复它,然后删除 < 和 > 之间的任何内容:

while ( <INPUT> ) {
  chomp();
    $line = $_;
  $start =  index($line,"SHEET") + 7;
  $end = index($line,"</SimpleData>");
if ($start ne 6) 
  {
  $sheet = substr($line,$start,$end-$start);
  }
  $start =  index($line,"<coordinates>") + 13;
  $end = rindex($line,"</coordinates>");
  $coords = substr($line,$start,$end-$start);
  $coords =~ s/<.*>//; 
if ($start ne 12) 
  {

  @values = split (' ',$coords);
于 2013-07-02T13:05:00.510 回答