定制 deadbyback/php-cyrillic-shapefile 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

deadbyback/php-cyrillic-shapefile

Composer 安装命令:

composer require deadbyback/php-cyrillic-shapefile

包简介

Modern PHP 8.3+ library to read and write ESRI Shapefiles with Cyrillic charset support, compatible with WKT and GeoJSON

README 文档

README

PHP library to read and write ESRI Shapefiles with full Cyrillic charset support, compatible with WKT and GeoJSON.

This is a modernized fork of gasparesganga/php-shapefile with enhanced Cyrillic text handling and PHP 8.3+ compatibility.

Features

  • Full PHP 8.3+ support with typed properties, constants, and return types
  • Cyrillic charset support - automatic detection and repair of broken encodings (Windows-1251, ISO-8859-1)
  • ✅ Read and write ESRI Shapefiles (.shp, .shx, .dbf, .dbt, .prj, .cpg)
  • ✅ Support for all standard shape types (Point, Polyline, Polygon, MultiPoint, Z/M variants)
  • ✅ WKT (Well-Known Text) and GeoJSON conversion
  • ✅ DBF field types: CHAR, DATE, LOGICAL, MEMO, NUMERIC, FLOAT
  • ✅ Fluent interface for method chaining
  • ✅ PSR-12 code style compliant
  • ✅ No external dependencies

Requirements

Installation

composer require deadbyback/php-cyrillic-shapefile

Quick Start

Reading a Shapefile

use CyrillicShapefile\ShapefileReader;

$shapefile = new ShapefileReader('path/to/file.shp');

foreach ($shapefile as $record) {
    // $record is a Geometry object (Point, Linestring, Polygon, etc.)
    $data = $record->getDataArray();
    $coords = $record->getArray();

    echo "Record: " . json_encode($data) . "\n";
}

Writing a Shapefile

use CyrillicShapefile\ShapefileWriter;
use CyrillicShapefile\Shapefile;
use CyrillicShapefile\Geometry\Point;

$shapefile = new ShapefileWriter('path/to/output.shp');

// Define structure
$shapefile->setShapeType(Shapefile::SHAPE_TYPE_POINT);
$shapefile->addCharField('NAME', 50);
$shapefile->addNumericField('POPULATION', 10, 0);

// Add records
$point = new Point(30.5164, 50.4536);
$point->setData('NAME', 'Київ');
$point->setData('POPULATION', 4700000);
$shapefile->writeRecord($point);

// Shapefile is automatically finalized and closed

Cyrillic Support

The library automatically detects and handles Cyrillic text in multiple encodings:

use CyrillicShapefile\ShapefileHelper;

// Automatic charset detection and repair
$fixed = ShapefileHelper::tryRepairStringCharset($brokenString);

// Supported charsets: Windows-1251, ISO-8859-1, UTF-8

What's New in v4.0.0

This major version brings full PHP 8.3 compatibility with breaking changes:

  • Typed constants: All class constants now have explicit types
  • Full type safety: Parameter types and return types on all methods
  • Modern PHP: Union types, nullable types, static return types
  • Bug fixes: Fixed Iterator compatibility, undefined variables, namespace issues

See CHANGELOG.md for complete details.

Documentation

For detailed documentation and examples, visit the original project:

Differences from Original

This fork extends the original gasparesganga/php-shapefile with:

  1. PHP 8.3+ compatibility - uses modern PHP features (typed constants, properties, etc.)
  2. Cyrillic charset handling - enhanced support for Cyrillic text in DBF files
  3. Namespace change - from Shapefile to CyrillicShapefile
  4. Bug fixes - fixed several issues with undefined variables and type compatibility

License

MIT License - Same as the original project

Credits

  • Original library: Gaspare Sganga
  • Cyrillic support and PHP 8.3 upgrade: deadbyback

Contributing

Issues and pull requests are welcome!

统计信息

  • 总下载量: 169
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固