且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在php中添加形状文件(.shp)并在php文件中使用该形状文件数据?

更新时间:2023-01-21 10:52:10

更新2:
对于 v3.0.0 版本,该库已被完全重写使用面向对象的方法:现在,它公开了一些方便的 ShapefileReader ShapefileWriter 和各种 Geometry 对象( Point MultiPoint 线串 MultiLinestring 多边形 MultiPolygon ).
已添加了对自定义字符集( CPG 文件),备注字段( DBT 文件)的支持,最重要的是,它现在能够编写shapefile
目前,它旨在成为最完善的免费开放源代码PHP库,以在那里读取和写入shapefile,并且在最近几年中它已被许多用户广泛使用,但应该如果发现有任何错误,请报告并/或打开一个问题,该问题将立即得到解决.

UPDATE 2:
For v3.0.0 release, the library has been completely rewritten with an object-oriented approach: it now exposes some convenient ShapefileReader, ShapefileWriter and different kinds of Geometry objects (Point, MultiPoint, Linestring, MultiLinestring, Polygon and MultiPolygon).
It has been added support for custom charsets (CPG files), memo fields (DBT files) and, most importantly, it is now able to write shapefiles too!
At this point, it aims to be the most complete free and open source PHP library to read and write shapefiles out there and it's been used widely by many users in the last few years, but should you find any bug with it, please report it and/or open an issue and it will be promptly fixed.

更新1:
从v2.0.0版本开始,PHP Shapefile能够读取Z和M形状文件,本机访问DBF,与PHP 7兼容等等.我正在积极开发此功能,因此可以提供功能请求.

UPDATE 1:
Since v2.0.0, PHP Shapefile is capable of reading Z and M shapefiles, natively access DBF, is PHP 7 compatible and much more. I am actively developing this, so feature requests are available.

我不想在一个老问题上破坏关于我自己的图书馆的任何规则发布,但是在Google上搜索php shapefile时,该页面会在第一个结果中弹出,因此我认为这可能对那些正在寻找像我以前那样的图书馆.

I don't want to break any rule posting about my own library in an old question, but this page pops up in the firsts result when searching for php shapefile on Google, so I thought it might be useful for someone who is looking for such a library as I used to.

我一直在寻找一个不错的库来亲自在PHP中导入ESRI Shapefile,而最终我自己构建了一个库.它可以读取所有 2D shapefile 类型的shapefile和DBF数据,并且应该100%无错误.
到目前为止,它已经在生产中使用了几个月,所以我公开发布了任何想要使用它的人:

I've been looking for a decent library to import ESRI Shapefiles in PHP myself, and I ended up building my own. It can read all 2D shapefiles kinds of shapefiles and DBF data and it should be 100% bug free.
It's been used in production for a few months by now, so I made public release for anybody who would like to use it:

https://github.com/gasparesganga/php-shapefile