How can I add shape file (.shp) in php and use that shape file data in php file?

10,294

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.


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.


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.

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

Share:
10,294
Arpi Patel
Author by

Arpi Patel

Updated on June 25, 2022

Comments

  • Arpi Patel
    Arpi Patel almost 2 years

    I have to develop one project in php and in that I have to include shape file and that shape file needs to be converted in to kml file.

    I know how to convert shape file into kml file but I don't know how to take/import shape file into php project.
    and I also have the supporting files with the shape file which contain more information.some of them are .dbf, .shx etc. And this all file's information should also be stored with the shape file information.

    Is there any tool to import shape file or any other help so that I can add shape file into my project in php site? or is it possible to store all the shape file(.shp), .dbf, . shx data into database and then use that data for the kml structuring.

    I also want to know that,all shape files follow any structure or formatting?Is there any standard for the shape file such as the xml file have?

    xml file should have the starting tag mandatory.
    They should follow the structure otherwise the viewer is unable to see the xml file.