0

各道路の shape_leng 列と座標 (multilinestring) 列を使用して各道路のテーブルを形成する必要があります。道路には任意の数の行があり、それらを 1 行に保存する必要があります。

Xml ファイルの形式は次のとおりです。いくつかの道路は複数行の文字列であり、その他のいくつかは 1 行のみです。

そして、私はそれを解析しようとしました

( shape_lengは道路では 1 つですが、道路では座標線が 1 つまたは複数になることに注意してください。)

そのため、 shape_leng座標のような特定の順序でそれらを追加することはできません。

4

1 に答える 1

1

すべての座標を単一のデータベース行に挿入したい場合は、XPath を作成してループを少し変える必要があると思います。道路をループし、XPath を使用してその道路に属するすべての座標を取得します。例えば:

// get all the roads and loop through them
$roads = $xml->xpath("//e:featureMember/b:AA_ROAD");
$i=0;

while(isset($roads[$i]))
{
    // get the coordinates for the current road
    $coordinates = $roads[i]->xpath("/b:the_geom/e:MultiLineString/e:lineStringMember/e:LineString/e:coordinates");
    $shapel = $roads[i]->xpath("/b:SHAPE_Leng");

    // add a second loop to concatinate all the $coordinates
    $j=0;
    while (isset($coordinates[$j])) {
        // TODO concatinate coordinates
    }

   // insert the row
   $b=mysql_query("INSERT IGNORE INTO `new`.`road1` (`coordstr`, `shapeleng`) values (GEOMFROMTEXT(concat('MULTILINESTRING ($a )')), '$shapel[$i]') ");


    $i++;
    echo "<br />";
    echo $i;    
}
于 2012-06-02T21:53:00.127 に答える