0

我正在尝试导入大量已解析的 JSON 文件(4 gb)。我想将它插入到 QGis 的 mysql 数据库中。起初我以为我可以直接使用 mongodb 和 RazorSQL 导入所有内容,但那是不可能的。我发现没有比制作脚本单独处理所有内容更快的方法了:

  "pandgeometrie": {
            "type": "Polygon",
            "coordinates": [
                [
                    [199801.469, 483101.581],
                    [199787.101, 483102.676],
                    [199786.139, 483090.053],
                    [199800.507, 483088.957],
                    [199801.469, 483101.581]
                ]
            ]
        }
"geometry": {
        "type": "Point",
        "coordinates": [199793.932, 483095.516]
    }

我想使用 PHP 导入这些数据我想如果将多边形组合成一行多边形信息,就可以将其查询到 MYSQL。我是这样做的:

    $constants = get_defined_constants(true);
    $json_errors = array();
    foreach ($json  as $name->features => $value) {
            foreach ($value as  $var){
                $id = $var->id; 
                $coordinates =  $var->properties->pandgeometrie->coordinates;
                $long = $var->geometry->coordinates[0];
                $lat = $var->geometry->coordinates[1];
                $point = "POINT(". $long . " ". $lat. ")";
                var_dump($point);
                        foreach ($coordinates as  $var){


                                echo "<div>";
                                $arrPoly= array()  ;
                                        foreach ($var as  $var2){


                                                $V0 = strval($var2[0])  ;
                                                $V1 = strval($var2[1]);
                                                $Comb = $V0 ." ". $V1;
                                                array_push($arrPoly, $Comb);

                            }
                                $polyImplode = implode($arrPoly, ",");
                                $polygon = "POLYGON((".$polyImplode."))";
                                var_dump($polygon);


$query = "INSERT INTO  geometry VALUES(PolygonFromText('$polygon'),'$id',PointFromText('$point'))"; 

检查值时,我只得到 NULL 值。

4

0 回答 0