私は、ogr2ogrツールを使用してポイントシェイプファイルから得た1つのテーブル( 'pk')のmysql空間データベース( 'mydb1')を持っています。私は、出力には、このテーブルのにGeoJSONファイルが必要mysql空間表からgeoJSONファイルを出力する方法は?
OGR_FID SHAPE CODIF Position_X Position_Y Nom Status
1 [GEOMETRY-25o] PAC182854 398235.38 414569.24 G-31 Vert
:この「PK」テーブルの1行は、のようなものです。私はgeoPHPライブラリをダウンロードし、以下のように、私は私の設定に適応にGeoJSONスクリプトにMySQLを使用:
<?php
/**
* Title: MySQL to GeoJSON (Requires https://github.com/phayes/geoPHP)
* Notes: Query a MySQL table or view and return the results in GeoJSON format, suitable for use in OpenLayers, Leaflet, etc.
* Author: Bryan R. McBride, GISP
* Contact: bryanmcbride.com
* GitHub: https://github.com/bmcbride/PHP-Database-GeoJSON
*/
# Include required geoPHP library and define wkb_to_json function
include_once('geoPHP/geoPHP.inc');
function wkb_to_json($wkb) {
$geom = geoPHP::load($wkb,'wkb');
return $geom->out('json');
}
# Connect to MySQL database
$conn = new PDO('mysql:host=localhost;dbname=mydb1','root','admin');
# Build SQL SELECT statement and return the geometry as a WKB element
$sql = 'SELECT *, AsWKB(SHAPE) AS wkb FROM pk';
# Try query or error
$rs = $conn->query($sql);
if (!$rs) {
echo 'An SQL error occured.\n';
exit;
}
# Build GeoJSON feature collection array
$geojson = array(
'type' => 'FeatureCollection',
'features' => array()
);
# Loop through rows to build feature arrays
while ($row = $rs->fetch(PDO::FETCH_ASSOC)) {
$properties = $row;
# Remove wkb and geometry fields from properties
unset($properties['wkb']);
unset($properties['SHAPE']);
$feature = array(
'type' => 'Feature',
'geometry' => json_decode(wkb_to_json($row['wkb'])),
'properties' => $properties
);
# Add feature arrays to feature collection array
array_push($geojson['features'], $feature);
}
header('Content-type: application/json');
echo json_encode($geojson, JSON_NUMERIC_CHECK);
$conn = NULL;
?>
しかし、私は、ブラウザ上でコードを実行するとき、私は完全に空白のページを取得します。私のgeoJSONファイルplzを出力するために修正しなければならないのは何ですか?
を使用することでしょう$のにGeoJSONオブジェクトを検査していない場合MySQLのクエリや配列などの生の出力を表示するPHPのエラー処理を有効にします。これらは、物事が南に行くかもしれないアイデアをあなたに与えるでしょう。 – Shadow
@Shadow申し訳ありませんが、私はあなたが言ったことを理解していませんでした。説明してもらえますか? – drissrais
あなたはPHPプログラミングの背景を持っていますか、PHPの知識なしにあなたのニーズにあらかじめ書かれたスクリプトを調整しようとしていますか? – Shadow