我正在使用 lib Gasparesganga/php-shapefile 来读取 shapefile。
public static function getShapefile(string $url): ?ShapefileReader
{
$shapefile = null;
$tmp = Utils::tempdir(prefix: 'icmbio_');
$fileName = ZIP::getFrom($url, $tmp);
ZIP::extractTo($fileName, $tmp);
$content = Utils::readDir($tmp);
if (!empty($content)) {
$basename = pathinfo(reset($content), PATHINFO_FILENAME);
$path = "$tmp/$basename";
$shapefile = new ShapefileReader($path);
}
Utils::closeDir($tmp);
return $shapefile;
}
在本例中,我只是解压一个包含 shp、shx、dbf、qmd、prj、cpg 文件的文件夹。
当我读取文件时,出现以下错误:
#message: "Error during conversion from provided DBF input charset to UTF-8"
#code: 0
#file: "/var/www/vendor/gasparesganga/php-shapefile/src/Shapefile/ShapefileReader.php"
#line: 335
-error_type: "ERR_DBF_CHARSET_CONVERSION"
传递标志 [Shapefile::OPTION_IGNORE_FILE_DBF => true], 数据现在丢失,但没有任何错误。 文档中是否有我可能没有找到的有关 BDF 选项的内容来解决此问题?
尝试以不同方式将图表集更改为 UFT-8,但问题出在库本身。
在 \Shapefile\ShapefileReader::decodeFieldValue
$value = $this->decodeFieldValue($f['name'], $type, $this>readString(Shapefile::FILE_DBF, $f['size'], false));
它的第三个参数接收带有固定
TRUE
的readString()函数,其中OPTION_DBF_CONVERT_TO_UTF8
标志应该是,根据文档,当它是TRUE
时,它将转换为UTF。