gasparesganga/php-shapefile
PHP library to read and write ESRI Shapefiles, compatible with WKT and GeoJSON
v3.4.1
1.8M downloads/mo
#4429 most downloaded on Packagist
gasparesganga/php-shapefile
What this package is like to depend on
Last release 3 years ago
no release in 18 months
Ships unpredictably
gaps range from 1 weeks to 2.6 years
Nearly every release is documented
notes for 23 of 23 stable releases
Nothing withdrawn
no release was ever pulled
10 years old
23 releases · first in 2016
0 releases in the last 12 months
see the full history below
Release timeline
23 releases · Nov 2016 to Aug 2023Releases
latest 23-
v3.4.129 Aug 2023Release notes
Open source →Important notice
v3 branch will not receive any new features updates anymore. Only eventual bugfixes will be released for this branch. Legacy PHP users can safely keep using it, while PHP 8+ users should switch to v4 once it is released.
Fixed
ShapefileReader::rewind()pointer reset (thank you to Adrian Geissel for finding it)- Compatibility fixes for PHP 8+
See release notes
Release notes
Open source →Fixed
ShapefileReader::rewind()pointer reset- Compatibility fixes for PHP 8+
-
v3.4.023 Jan 2021Release notes
Open source →Added
- Full GeoJSON Feature support with properties data
- Capability to ignore DBF and SHX files to recover corrupted Shapefiles
- ShapefileReader constructor options constants:
Shapefile::OPTION_IGNORE_FILE_DBFShapefile::OPTION_IGNORE_FILE_SHX
ShapefileReader::getTotRecords()output constant:Shapefile::UNKNOWN
- Error types constants:
Shapefile::ERR_INPUT_RANDOM_ACCESS_UNAVAILABLE
Changed
- Improved handling of Logical fields in DBF files
- Increased tolerance coefficient to deal with extremely small areas when determining ring orientation
Fixed
- Handling of unspecified bounding box in SHP and SHX file headers for empty Shapefiles
- Behaviour with DBF files for empty Shapefiles
See release notes
Release notes
Open source →Added
- Full GeoJSON Feature support with properties data
- Capability to ignore DBF and SHX files to recover corrupted Shapefiles
- ShapefileReader constructor options constants:
Shapefile::OPTION_IGNORE_FILE_DBFShapefile::OPTION_IGNORE_FILE_SHX
ShapefileReader::getTotRecords()output constant:Shapefile::UNKNOWN
- Error types constants:
Shapefile::ERR_INPUT_RANDOM_ACCESS_UNAVAILABLE
Changed
- Improved handling of Logical fields in DBF files
- Increased tolerance coefficient to deal with extremely small areas when determining ring orientation
Fixed
- Handling of unspecified bounding box in SHP and SHX file headers for empty Shapefiles
- Behaviour with DBF files for empty Shapefiles
-
v3.3.317 Sep 2020Release notes
Open source →Release notes
Open source →Fixed
- Bug in
ShapefileWriter::packPoint()method affecting Z and M geometries
- Bug in
-
v3.3.217 Aug 2020Release notes
Open source → -
v3.3.113 Aug 2020Release notes
Open source →Fixed
- Prevented a PHP warning when encoding a boolean
falsevalue for aShapefile::DBF_TYPE_LOGICALfield
See release notes
Release notes
Open source →Fixed
- Prevented a PHP warning when encoding a boolean
falsevalue for aShapefile::DBF_TYPE_LOGICALfield
- Prevented a PHP warning when encoding a boolean
-
v3.3.023 May 2020Release notes
Open source →Added
Shapefile\Geometry\Linestringpublic methods:Shapefile\Geometry\Linestring::isClockwise()Shapefile\Geometry\Linestring::forceClockwise()Shapefile\Geometry\Linestring::forceCounterClockwise()Shapefile\Geometry\Linestring::forceClosedRing()
Shapefile\Geometry\Polygonpublic methods:Shapefile\Geometry\Polygon::isClockwise()Shapefile\Geometry\Polygon::isCounterClockwise()Shapefile\Geometry\Polygon::forceClockwise()Shapefile\Geometry\Polygon::forceCounterClockwise()Shapefile\Geometry\Polygon::forceClosedRings()
Shapefile\Geometry\MultiPolygonpublic methods:Shapefile\Geometry\MultiPolygon::isClockwise()Shapefile\Geometry\MultiPolygon::isCounterClockwise()Shapefile\Geometry\MultiPolygon::forceClockwise()Shapefile\Geometry\MultiPolygon::forceCounterClockwise()Shapefile\Geometry\MultiPolygon::forceClosedRings()
Shapefile\Geometry\GeometryCollection::reverseGeometries()protected method.Shapefile\Geometry\PolygonandShapefile\Geometry\MultiPolygonoptional constructor parameter$force_orientation.Shapefile\ShapefileReaderconstructor options:Shapefile::OPTION_POLYGON_CLOSED_RINGS_ACTIONShapefile::OPTION_POLYGON_ORIENTATION_READING_AUTOSENSEShapefile::OPTION_POLYGON_OUTPUT_ORIENTATION
- Action constants:
Shapefile::ACTION_IGNOREShapefile::ACTION_CHECKShapefile::ACTION_FORCE
- Polygon orientation constants:
Shapefile::ORIENTATION_CLOCKWISEShapefile::ORIENTATION_COUNTERCLOCKWISEShapefile::ORIENTATION_UNCHANGED
- Error types constants:
Shapefile::ERR_GEOM_RING_AREA_TOO_SMALLShapefile::ERR_GEOM_RING_NOT_ENOUGH_VERTICES
- Other constants:
Shapefile::UNDEFINED
- Library implements a fluent interface that allows method chaining.
Changed
Shapefile\Geometry\PolygonandShapefile\Geometry\MultiPolygonconstructor parameter$flag_enforce_closed_ringsis now$closed_ringsand acceptsShapefile::ACTION_IGNORE,Shapefile::ACTION_CHECKandShapefile::ACTION_FORCEvalues.- Code is now PSR-12 compliant
Deprecated
Shapefile\ShapefileReaderconstructor options that will disappear in the next releases:Shapefile::OPTION_ENFORCE_POLYGON_CLOSED_RINGS. UseShapefile::OPTION_POLYGON_CLOSED_RINGS_ACTIONinstead.Shapefile::OPTION_INVERT_POLYGONS_ORIENTATION. UseShapefile::OPTION_POLYGON_OUTPUT_ORIENTATIONinstead.
- Constants:
Shapefile::ERR_GEOM_POLYGON_AREA_TOO_SMALL. UseShapefile::ERR_GEOM_RING_AREA_TOO_SMALLinstead.Shapefile::ERR_GEOM_POLYGON_NOT_VALID. UseShapefile::ERR_GEOM_POLYGON_WRONG_ORIENTATIONinstead.
See release notes
Release notes
Open source →Added
Shapefile\Geometry\Linestringpublic methods:Shapefile\Geometry\Linestring::isClockwise()Shapefile\Geometry\Linestring::forceClockwise()Shapefile\Geometry\Linestring::forceCounterClockwise()Shapefile\Geometry\Linestring::forceClosedRing()
Shapefile\Geometry\Polygonpublic methods:Shapefile\Geometry\Polygon::isClockwise()Shapefile\Geometry\Polygon::isCounterClockwise()Shapefile\Geometry\Polygon::forceClockwise()Shapefile\Geometry\Polygon::forceCounterClockwise()Shapefile\Geometry\Polygon::forceClosedRings()
Shapefile\Geometry\MultiPolygonpublic methods:Shapefile\Geometry\MultiPolygon::isClockwise()Shapefile\Geometry\MultiPolygon::isCounterClockwise()Shapefile\Geometry\MultiPolygon::forceClockwise()Shapefile\Geometry\MultiPolygon::forceCounterClockwise()Shapefile\Geometry\MultiPolygon::forceClosedRings()
Shapefile\Geometry\GeometryCollection::reverseGeometries()protected method.Shapefile\Geometry\PolygonandShapefile\Geometry\MultiPolygonoptional constructor parameter$force_orientation.Shapefile\ShapefileReaderconstructor options:Shapefile::OPTION_POLYGON_CLOSED_RINGS_ACTIONShapefile::OPTION_POLYGON_ORIENTATION_READING_AUTOSENSEShapefile::OPTION_POLYGON_OUTPUT_ORIENTATION
- Action constants:
Shapefile::ACTION_IGNOREShapefile::ACTION_CHECKShapefile::ACTION_FORCE
- Polygon orientation constants:
Shapefile::ORIENTATION_CLOCKWISEShapefile::ORIENTATION_COUNTERCLOCKWISEShapefile::ORIENTATION_UNCHANGED
- Error types constants:
Shapefile::ERR_GEOM_RING_AREA_TOO_SMALLShapefile::ERR_GEOM_RING_NOT_ENOUGH_VERTICES
- Other constants:
Shapefile::UNDEFINED
- Library implements a fluent interface that allows method chaining.
Changed
Shapefile\Geometry\PolygonandShapefile\Geometry\MultiPolygonconstructor parameter$flag_enforce_closed_ringsis now$closed_ringsand acceptsShapefile::ACTION_IGNORE,Shapefile::ACTION_CHECKandShapefile::ACTION_FORCEvalues.- Code is now PSR-12 compliant
Deprecated
Shapefile\ShapefileReaderconstructor options that will disappear in the next releases:Shapefile::OPTION_ENFORCE_POLYGON_CLOSED_RINGS. UseShapefile::OPTION_POLYGON_CLOSED_RINGS_ACTIONinstead.Shapefile::OPTION_INVERT_POLYGONS_ORIENTATION. UseShapefile::OPTION_POLYGON_OUTPUT_ORIENTATIONinstead.
- Constants:
Shapefile::ERR_GEOM_POLYGON_AREA_TOO_SMALL. UseShapefile::ERR_GEOM_RING_AREA_TOO_SMALLinstead.Shapefile::ERR_GEOM_POLYGON_NOT_VALID. UseShapefile::ERR_GEOM_POLYGON_WRONG_ORIENTATIONinstead.
-
v3.2.009 Apr 2020Release notes
Open source →Added
Shapefile::OPTION_DBF_ALLOW_FIELD_SIZE_255constructor option for bothShapefileReaderandShapefileWriterclasses
See release notes
Release notes
Open source →Added
Shapefile::OPTION_DBF_ALLOW_FIELD_SIZE_255constructor option for bothShapefileReaderandShapefileWriterclasses
-
v3.1.302 Feb 2020Release notes
Open source →Fixed
- Changed
GEOJSON_BASETYPEconstants forShapefile\Geometry\LinestringandShapefile\Geometry\MultiLinestringrespectively to'LineString'and'MultiLineString'(with a capital S)
See release notes
Release notes
Open source →Fixed
- Changed
GEOJSON_BASETYPEconstants forShapefile\Geometry\LinestringandShapefile\Geometry\MultiLinestringrespectively to'LineString'and'MultiLineString'
- Changed
-
v3.1.215 Jan 2020Release notes
Open source →Fixed
- Do not apply
Shapefile::OPTION_FORCE_MULTIPART_GEOMETRIESto Point Shapefiles
See release notes
Release notes
Open source →Fixed
- Do not apply
Shapefile::OPTION_FORCE_MULTIPART_GEOMETRIESto Point Shapefiles
- Do not apply
-
v3.1.110 Nov 2019Release notes
Open source →Fixed
- Truncate PRJ and CPG files before writing them to prevent content to be appended when
Shapefile::OPTION_EXISTING_FILES_MODEis set toShapefile::MODE_APPEND - Increased maximum number of fields in DBF files to 255
See release notes
Release notes
Open source →Fixed
- Truncate PRJ and CPG files before writing them to prevent content to be appended when
Shapefile::OPTION_EXISTING_FILES_MODEis set toShapefile::MODE_APPEND - Increased maximum number of fields in DBF files to 255
- Truncate PRJ and CPG files before writing them to prevent content to be appended when
-
v3.1.030 Oct 2019Release notes
Open source →Added
- Writing buffer in
ShapefileWriter. It allows up to a 50% reduction in writing time ShapefileWriter::flushBuffer()methodShapefile::OPTION_BUFFERED_RECORDSconstructor option forShapefileWriterclass- Capability to append records to existing Shapefiles
Shapefile::OPTION_EXISTING_FILES_MODEconstructor option forShapefileWriterclassShapefile::MODE_PRESERVE,Shapefile::MODE_APPEND,Shapefile::MODE_OVERWRITEconstantsisZ(),isM()andgetFieldsNames()methods for bothShapefileReaderandShapefileWriterclassesShapefileWriterexposesgetShapeType(),getBoundingBox(),getPRJ(),getCharset(),setCharset(),getFieldsNames(),getField(),getFieldType(),getFieldSize(),getFieldDecimals(),getFields()andgetTotRecords()public methods likeShapefileReader- Sanitize and accept conflicting and duplicated field names
- Other minor code and performance improvements across the library
Changed
- Improved
GeometryCollection::getBoundingBox()method for better performance - Improved
ShapefileWriter::encodeFieldValue()method for better performance, relying on PHPnumber_format()for non-textual numeric input - Field name sanitization is always carried out in all
ShapefileWriterfield-adding methods Shapefile::ERR_DBF_FIELD_NAME_NOT_VALIDerror type is now defined as"Too many field names conflicting"- Default
c+bfile access mode forShapefileWriterclass
Fixed
- Convert field names to uppercase for
Geometrydata whenShapefile::OPTION_DBF_FORCE_ALL_CAPSis enabled - Decoupling field names sanitization and
Shapefile::OPTION_DBF_FORCE_ALL_CAPSoption Shapefile::ERR_GEOM_MISSING_FIELDexception was erroneously raised when a field had an explicitnullvalue andShapefile::OPTION_ENFORCE_GEOMETRY_DATA_STRUCTUREwas enabled- Suppress PHP warnings in
fread()andfwrite()calls: aShapefileExceptionis thrown anyways - Bug causing a corrupted DBF file when a
Shapefile::ERR_GEOM_MISSING_FIELDis raised - Bug causing wrong record number to be written in SHP record headers (count starts from
1, not from0) - Corner case bug affecting
ShapefileWriterdestructor when no record has been written yet
Removed
$flag_sanitize_nameparameter from all field-adding methodsShapefile::OPTION_OVERWRITE_EXISTING_FILESconstructor option forShapefileWriterclassShapefile::ERR_DBF_FIELD_NAME_NOT_UNIQUEerror type
- Writing buffer in
-
v3.0.223 Sep 2019Release notes
Open source →Fixed
- A Declaration of X must be compatible with Y PHP7 Warning thrown for
PolygonandMultiPolygonaddGeometryprotected methods
- A Declaration of X must be compatible with Y PHP7 Warning thrown for
-
v3.0.131 Aug 2019Release notes
Open source →Fixed
- A typo in a variable name introduced with a late code clean-up before final release that was causing a PHP Notice when reading Shapefiles with Memo fields
- Year in the release date of v3 in CHANGELOG file.
-
v3.0.030 Aug 2019Release notes
Open source →Added
- Complete OOP style refactoring
- Shapefile writing capabilities
- PHPDoc style comments
Shapefile\Geometrynamespace withPoint,MultiPoint,Linestring,MultiLinestring,PolygonandMultiPolygonclassesShapefileReaderandShapefileWriterclassesShapefile,GeometryandGeometryCollectionabstract classes- Custom DBF charset support
- Support for emulated
nullvalues in DBF files - Reading and writing optional DBT files (support for
MEMOfields) - Reading and writing optional CPG files
ShapefileException::getDetails()method- Constructor options constants:
Shapefile::OPTION_CPG_ENABLE_FOR_DEFAULT_CHARSETShapefile::OPTION_DBF_CONVERT_TO_UTF8Shapefile::OPTION_DBF_FORCE_ALL_CAPSShapefile::OPTION_DBF_IGNORED_FIELDSShapefile::OPTION_DBF_NULL_PADDING_CHARShapefile::OPTION_DBF_NULLIFY_INVALID_DATESShapefile::OPTION_DBF_RETURN_DATES_AS_OBJECTSShapefile::OPTION_DELETE_EMPTY_FILESShapefile::OPTION_ENFORCE_GEOMETRY_DATA_STRUCTUREShapefile::OPTION_ENFORCE_POLYGON_CLOSED_RINGSShapefile::OPTION_FORCE_MULTIPART_GEOMETRIESShapefile::OPTION_IGNORE_GEOMETRIES_BBOXESShapefile::OPTION_IGNORE_SHAPEFILE_BBOXShapefile::OPTION_INVERT_POLYGONS_ORIENTATIONShapefile::OPTION_OVERWRITE_EXISTING_FILESShapefile::OPTION_SUPPRESS_MShapefile::OPTION_SUPPRESS_Z
- File types constants:
Shapefile::FILE_SHPShapefile::FILE_SHXShapefile::FILE_DBFShapefile::FILE_DBTShapefile::FILE_PRJShapefile::FILE_CPG
- Shape types constants:
Shapefile::SHAPE_TYPE_NULLShapefile::SHAPE_TYPE_POINTShapefile::SHAPE_TYPE_POLYLINEShapefile::SHAPE_TYPE_POLYGONShapefile::SHAPE_TYPE_MULTIPOINTShapefile::SHAPE_TYPE_POINTZShapefile::SHAPE_TYPE_POLYLINEZShapefile::SHAPE_TYPE_POLYGONZShapefile::SHAPE_TYPE_MULTIPOINTZShapefile::SHAPE_TYPE_POINTMShapefile::SHAPE_TYPE_POLYLINEMShapefile::SHAPE_TYPE_POLYGONMShapefile::SHAPE_TYPE_MULTIPOINTM
- DBF fields types constants:
Shapefile::DBF_TYPE_CHARShapefile::DBF_TYPE_DATEShapefile::DBF_TYPE_LOGICALShapefile::DBF_TYPE_MEMOShapefile::DBF_TYPE_NUMERICShapefile::DBF_TYPE_FLOAT
- Error types constants:
Shapefile::ERR_UNDEFINEDShapefile::ERR_FILE_MISSINGShapefile::ERR_FILE_EXISTSShapefile::ERR_FILE_INVALID_RESOURCEShapefile::ERR_FILE_OPENShapefile::ERR_FILE_READINGShapefile::ERR_FILE_WRITINGShapefile::ERR_SHP_TYPE_NOT_SUPPORTEDShapefile::ERR_SHP_TYPE_NOT_SETShapefile::ERR_SHP_TYPE_ALREADY_SETShapefile::ERR_SHP_GEOMETRY_TYPE_NOT_COMPATIBLEShapefile::ERR_SHP_MISMATCHED_BBOXShapefile::ERR_SHP_FILE_ALREADY_INITIALIZEDShapefile::ERR_SHP_WRONG_RECORD_TYPEShapefile::ERR_DBF_FILE_NOT_VALIDShapefile::ERR_DBF_MISMATCHED_FILEShapefile::ERR_DBF_EOF_REACHEDShapefile::ERR_DBF_MAX_FIELD_COUNT_REACHEDShapefile::ERR_DBF_FIELD_NAME_NOT_UNIQUEShapefile::ERR_DBF_FIELD_NAME_NOT_VALIDShapefile::ERR_DBF_FIELD_TYPE_NOT_VALIDShapefile::ERR_DBF_FIELD_SIZE_NOT_VALIDShapefile::ERR_DBF_FIELD_DECIMALS_NOT_VALIDShapefile::ERR_DBF_CHARSET_CONVERSIONShapefile::ERR_DBT_EOF_REACHEDShapefile::ERR_GEOM_NOT_EMPTYShapefile::ERR_GEOM_COORD_VALUE_NOT_VALIDShapefile::ERR_GEOM_MISMATCHED_DIMENSIONSShapefile::ERR_GEOM_MISMATCHED_BBOXShapefile::ERR_GEOM_MISSING_FIELDShapefile::ERR_GEOM_POINT_NOT_VALIDShapefile::ERR_GEOM_POLYGON_OPEN_RINGShapefile::ERR_GEOM_POLYGON_AREA_TOO_SMALLShapefile::ERR_GEOM_POLYGON_NOT_VALIDShapefile::ERR_INPUT_RECORD_NOT_FOUNDShapefile::ERR_INPUT_FIELD_NOT_FOUNDShapefile::ERR_INPUT_GEOMETRY_TYPE_NOT_VALIDShapefile::ERR_INPUT_GEOMETRY_INDEX_NOT_VALIDShapefile::ERR_INPUT_ARRAY_NOT_VALIDShapefile::ERR_INPUT_WKT_NOT_VALIDShapefile::ERR_INPUT_GEOJSON_NOT_VALIDShapefile::ERR_INPUT_NUMERIC_VALUE_OVERFLOW
Changed
- Folder structure under
src/reflects namespaces hierarchy - Namespace and class names case normalized
- Bitwise constructor flags replaced by associative array
- Default output polygons orientation is now opposite to ESRI Shapefile specs and compliant to OGC Simple Features
- Use of
iconv()instead ofutf8_encode()for charset conversion ShapefileException::getErrorType()method returns one ofShapefile::ERR_*constant valuesShapefileReader::fetchRecord()method replacesShapefileReader::getRecord()and returns an object- Order of bounding boxes associative arrays elements
Fixed
- Stricter invalid date format detection
- Logical (
bool) not initialized values (null) detection in DBF files
Removed
ShapefileReaderpublic methods:setDefaultGeometryFormat()readRecord()
ShapefileReaderprotected methodinit()Shapefileconstants:Shapefile::FLAG_SUPPRESS_ZShapefile::FLAG_SUPPRESS_MShapefile::GEOMETRY_ARRAYShapefile::GEOMETRY_WKTShapefile::GEOMETRY_GEOJSON_GEOMETRYShapefile::GEOMETRY_GEOJSON_FEATUREShapefile::GEOMETRY_BOTH
Shapefilenumeric error codes
-
v2.4.307 Apr 2018Release notes
Open source →Fixed
- Bug in binary reading function causing issues with DBF fields size
-
v2.4.206 Dec 2017Release notes
Open source →Fixed
- Reversed the orientation of inner and outer rings in GeoJSON output of Polygons and MultiPolygons, complying to section 3.1.6 of RFC 7946
-
v2.4.129 Nov 2017Release notes
Open source →Fixed
- Fixed composer.json file. Since version 2.4.0 the library requires PHP 5.4+
-
v2.4.020 Nov 2017Release notes
Open source →Added
- Public method
setDefaultGeometryFormat(). It sets the default format for future calls togetRecord()and use with the Iterator interface (foreach loop) GEOMETRY_GEOJSON_GEOMETRYandGEOMETRY_GEOJSON_FEATUREformats forgetRecord()method
Changed
- Geometry return format types for
getRecord()can be combined using bitwise Or operator| - Default geometry return format for
getRecord()method changed toShapeFile::GEOMETRY_ARRAY
Deprecated
GEOMETRY_BOTHgeometry return format forgetRecord()method - Please update your code still relying on it
- Public method
-
v2.3.014 Sep 2017Release notes
Open source →Added
- Protected method
init()allows the mainShapeFileclass to be easily extended using a custom constructor
Fixed
- Some minor code embellishments to better comply to PSR-2
- Protected method
-
v2.2.023 Nov 2016Release notes
Open source →Added
- Capability to randomly access the shapefile records
- Implements the PHP Iterator interface
- Public method
getTotRecords(). It provides the number of records in the shapefile - Public method
setCurrentRecord(). It sets the current record pointer - Public method
getCurrentRecord(). It gets the current record pointer - Error code 91: RECORD_INDEX_NOT_VALID
Changed
- Class constructor: SHX file is now required
Fixed
- Handles eventual useless random bytes between records in the SHP file (using the SHX file for the correct offsets)
-
v2.1.017 Nov 2016Release notes
Open source →Added
- Public method
getDBFFields(). It provides the fields definition in the DBF file
- Public method
-
v2.0.110 Nov 2016 -
v2.0.001 Nov 2016Release notes
Open source →Added
- Support for Z and M shapes
- Native DBF reading capabilities (no dbase functions or external libraries required anymore)
FLAG_SUPPRESS_ZandFLAG_SUPPRESS_Mflags for ShapeFile constructorGEOMETRY_BOTHformat forgetRecord()methodShapeFilenamespace andShapeFileAutoloaderclass- DBF error codes
41and42 - CHANGELOG file
Changed
- Code is now php-fig PSR-1, PSR-2 and PSR-4 compliant
- PHP 7 compatible
- All strings read from DBF are returned already encoded in utf-8
Removed
- PHP XBase library dependency as dbase fallback
Fixed
- It works on big-endian machines