teamzac / laravel-shapefiles
gasparesganga/php-shapefile 的包装器,具有类似 Laravel 集合的 API
0.4.2
2021-06-23 22:05 UTC
Requires
- php: ^7.1|^8.0
- gasparesganga/php-shapefile: ^3.4
- illuminate/support: ^7.0|^8.0
- proj4php/proj4php: ^2.0
Requires (Dev)
- orchestra/testbench: ^5.0|^6.0
- phpunit/phpunit: ^8.0|^9.0
README
gasparesganga/php-shapefile 包对于直接处理 Shapefile 非常方便,但我们主要在 Laravel 中工作,并喜欢使用集合风格的 API。此包简单地将原始 ShapefileReader 类包装在 LazyCollection 中,使其迭代更熟悉。
安装
您可以通过 composer 安装此包
composer require teamzac/laravel-shapefiles
用法
$reader = new TeamZac\LaravelShapefiles\Reader('file_or_directory_path_here'); $reader->count(); // total number of records $reader->each(function($geometry) { // do something });
在实例化 Reader 时,您可以传递 .shp 文件的引用,或包含 .shp 文件的目录。
在原始包中迭代时,您将收到 Shapefile\Geometry\Geometry
的一个实例。我们还在此类中添加了几个附加方法
... $reader->each(function($geometry) { $geometry->asGeoJson(); // passes through to the getGeoJSON() method with the "as" verbiage commonly used in Laravel $geometry->asJson(); // a convenience method that runs the GeoJSON through json_decode first $geometry->getData('ID'); // allows retreival of a specific key in the data array $geometry->ID; // you can also access the data array as properties on the Geometry class $geometry->getDataArray(); // methods are passed through to the underlying Shapefile\Geometry\Geometry class $geometry->getRaw(); // you can retrieve the underlying Shapefile\Geometry\Geometry class with the getRaw() method }); ...
待办事项
由于我们没有使用它,我们没有实现 ShapefileWriter 类的包装器。将来如果我们需要它,可能会添加。
测试
composer test
该包包含一个包含两个多边形的 Shapefile。注意,我们只测试了多边形,但没有理由它不能与其他类型的特征一起工作。
更改日志
有关最近更改的更多信息,请参阅 CHANGELOG。
贡献
有关详细信息,请参阅 CONTRIBUTING。
安全
如果您发现任何安全相关的问题,请通过电子邮件 chad@zactax.com 而不是使用问题跟踪器。
鸣谢
- Gaspare Sganga - 底层包的作者
- Chad Janicek
- Laravel 包模板
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。