vincjo / spatialite
PHP + Spatialite
0.0.7
2020-03-06 08:40 UTC
Requires
- php: >=7.3
- symfony/process: >=4.3
Requires (Dev)
- phpunit/phpunit: >=8
README
请注意,您必须首先安装 sqlite3 / mod_spatialite 和 spatialite 才能运行此库。
composer require vincjo/spatialite
测试
./vendor/bin/phpunit tests
基本用法
创建一个新的空数据库
use Spatialite\SPL; $db = new SPL( SPL::CreateNewEmptyDB('test.sqlite') ); // Or connect an existing Spatialite DB : $db = new SPL( 'path/to/mydb.sqlite' );
加载shapfile
$db->loadShapefile('path/to/shapefile/commune', 'commune', [ 'srid' => 2154, 'charset' => 'UTF-8' ]);
查询
$result = $db->query(" SELECT numero, nom_acc, statut, AsText( ST_Centroid(geom) ) AS centroid FROM commune LIMIT 3 ")->fetchAll(SPL::FETCH_OBJ); // output : Array ( [0] => stdClass Object ( [numero] => 71176 [nom_acc] => Digoin [statut] => Chef-lieu de canton [centroid] => POINT(778668.545898 6599300.563594) ) [1] => stdClass Object ( [numero] => 71590 [nom_acc] => Volesvres [statut] => Commune simple [centroid] => POINT(789596.3737 6597690.519251) ) [2] => stdClass Object ( [numero] => 71325 [nom_acc] => La Motte-Saint-Jean [statut] => Commune simple [centroid] => POINT(773591.803208 6602067.726544) ) )
转储shapefile
$db->dumpShapefile('./shapefile', 'commune', [ 'charset' => 'UTF-8', 'geomcolumn' => 'geom' ]);
关于Spatialite
SpatiaLite 实现了遵循开放地理空间联盟(OGC)规范的地理空间扩展。
在最基本层面上,支持空间数据的数据库管理系统提供了一个扩展了几何类型的SQL环境,因此可以被某些GIS应用程序等有用地应用。
具有几何值的SQL列实现为具有几何类型的列。OGC规范描述了一套SQL几何类型,以及在这些类型上的函数来创建和分析几何值。
SpatiaLite 4.2.0 - SQL函数参考列表