Reputation: 9
I'm using the lib, gasparesganga/php-shapefile, to read a 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;
}
In this case I'm just unzipping a folder with shp, shx, dbf, qmd, prj, cpg files.
and when I read the file, the following error occurs:
#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"
Passing the flag [Shapefile::OPTION_IGNORE_FILE_DBF => true], The data is now missing, but without any errors. Is there anything in the documentation that I might not have found about BDF options to fix this?
Upvotes: 0
Views: 85
Reputation: 9
Only need pass options to false, when DBF is not UFT-8 charset
[
Shapefile::OPTION_DBF_CONVERT_TO_UTF8_DEFAULT => false,
Shapefile::OPTION_DBF_CONVERT_TO_UTF8 => false
]
Upvotes: 0