upgrade bootstrap and js

This commit is contained in:
Walter Hupfeld
2024-03-13 12:03:56 +01:00
parent 2ac9d01257
commit 0df358251a
93 changed files with 17858 additions and 33259 deletions

View File

@@ -5,7 +5,7 @@
*
* @package Shapefile
* @author Gaspare Sganga
* @version 3.3.0
* @version 4.0.0dev
* @license MIT
* @link https://gasparesganga.com/labs/php-shapefile/
*/
@@ -67,7 +67,7 @@ class ShapefileWriter extends Shapefile
/**
* Constructor.
*
* @param string|array $files Path to SHP file / Array of paths / Array of handles of individual files.
* @param string|array $files Path to SHP file / Array of paths / Array of resource handles / Array of FileInterface instances.
* @param array $options Optional associative array of options.
*/
public function __construct($files, $options = [])
@@ -95,12 +95,7 @@ class ShapefileWriter extends Shapefile
// Mode overwrite
if ($this->getOption(Shapefile::OPTION_EXISTING_FILES_MODE) === Shapefile::MODE_OVERWRITE) {
foreach (array_keys($this->getFiles()) as $file_type) {
if ($this->getFileSize($file_type) > 0) {
$this->fileTruncate($file_type);
$this->setFilePointer($file_type, 0);
}
}
$this->truncateFiles();
}
// Mode append
@@ -133,23 +128,25 @@ class ShapefileWriter extends Shapefile
// Close Shapefile in reading mode
$ShapefileReader = null;
// Mark Shapefile as initialized if there are any records
if ($this->getTotRecords() > 0) {
// Mark Shapefile as initialized
$this->setFlagInitialized(true);
}
// Flag init headers
$this->flag_init_headers = true;
// SHP current offset (in 16-bit words)
$this->shp_current_offset = $this->getFileSize(Shapefile::FILE_SHP) / 2;
// Remove DBF EOF marker
$dbf_size_without_eof = $this->getFileSize(Shapefile::FILE_DBF) - 1;
$this->setFilePointer(Shapefile::FILE_DBF, $dbf_size_without_eof);
if ($this->readData(Shapefile::FILE_DBF, 1) === $this->packChar(Shapefile::DBF_EOF_MARKER)) {
$this->fileTruncate(Shapefile::FILE_DBF, $dbf_size_without_eof);
}
// Reset pointers
foreach (array_keys($this->getFiles()) as $file_type) {
$this->resetFilePointer($file_type);
// Set flag init headers
$this->flag_init_headers = true;
// SHP current offset (in 16-bit words)
$this->shp_current_offset = $this->getFileSize(Shapefile::FILE_SHP) / 2;
// Remove DBF EOF marker
$dbf_size_without_eof = $this->getFileSize(Shapefile::FILE_DBF) - 1;
$this->setFilePointer(Shapefile::FILE_DBF, $dbf_size_without_eof);
if ($this->readData(Shapefile::FILE_DBF, 1) === $this->packChar(Shapefile::DBF_EOF_MARKER)) {
$this->fileTruncate(Shapefile::FILE_DBF, $dbf_size_without_eof);
}
// Reset pointers
foreach (array_keys($this->getFiles()) as $file_type) {
$this->resetFilePointer($file_type);
}
} else {
$this->truncateFiles();
}
}
}
@@ -158,14 +155,12 @@ class ShapefileWriter extends Shapefile
* Destructor.
*
* Finalizes open files.
* If files were NOT passed as stream resources, empty useless files will be removed.
* Empty useless files will be removed if they were NOT passed as stream resources or FileInterface instances.
*/
public function __destruct()
{
// Flush buffers
$this->writeBuffers();
// Write DBF EOF marker to buffer
$this->writeData(Shapefile::FILE_DBF, $this->packChar(Shapefile::DBF_EOF_MARKER));
// Try setting Shapefile as NULL SHAPE if it hasn't been initialized yet (no records written)
if (!$this->isInitialized()) {
@@ -194,6 +189,9 @@ class ShapefileWriter extends Shapefile
$this->resetFilePointer($file_type);
}
// Write DBF EOF marker
$this->writeData(Shapefile::FILE_DBF, $this->packChar(Shapefile::DBF_EOF_MARKER));
// Write PRJ file
if ($this->isFileOpen(Shapefile::FILE_PRJ)) {
$this->fileTruncate(Shapefile::FILE_PRJ);
@@ -403,6 +401,20 @@ class ShapefileWriter extends Shapefile
/////////////////////////////// PRIVATE ///////////////////////////////
/**
* Truncates open files.
*/
private function truncateFiles()
{
foreach (array_keys($this->getFiles()) as $file_type) {
if ($this->getFileSize($file_type) > 0) {
$this->fileTruncate($file_type);
$this->setFilePointer($file_type, 0);
}
}
}
/**
* Stores binary string packed data into a buffer.
*
@@ -638,11 +650,10 @@ class ShapefileWriter extends Shapefile
*/
private function packPoint(Geometry\Geometry $Geometry)
{
$array = $Geometry->getArray();
$bounding_box = $Geometry->getBoundingBox();
$is_m = $this->isM();
$is_z = $this->isZ();
$shape_type = $is_z ? Shapefile::SHAPE_TYPE_POINTZ : ($is_m ? Shapefile::SHAPE_TYPE_POINTM : Shapefile::SHAPE_TYPE_POINT);
$array = $Geometry->getArray();
$is_m = $this->isM();
$is_z = $this->isZ();
$shape_type = $is_z ? Shapefile::SHAPE_TYPE_POINTZ : ($is_m ? Shapefile::SHAPE_TYPE_POINTM : Shapefile::SHAPE_TYPE_POINT);
// Shape type
$ret = $this->packInt32L($shape_type);
@@ -651,12 +662,12 @@ class ShapefileWriter extends Shapefile
if ($is_z) {
// Z Coordinate
$ret .= $this->packZ($coordinates);
$ret .= $this->packZ($array);
}
if ($is_m) {
// M Coordinate
$ret .= $this->packM($coordinates);
$ret .= $this->packM($array);
}
return $ret;
@@ -840,7 +851,7 @@ class ShapefileWriter extends Shapefile
}
/**
* Packs DBF and DBT data from a Geometry object into binary strings and returns an array with SHP, DBT and "dbt_next_available_block" members.
* Packs DBF and DBT data from a Geometry object into binary strings and returns an array with DBF, DBT and "dbt_next_available_block" members.
*
* @param \Shapefile\Geometry\Geometry $Geometry Input Geometry.
*
@@ -949,12 +960,12 @@ class ShapefileWriter extends Shapefile
// Try YYYY-MM-DD format
$DateTime = \DateTime::createFromFormat('Y-m-d', $value);
$errors = \DateTime::getLastErrors();
if ($errors['warning_count'] || $errors['error_count']) {
if (is_array($errors) && ($errors['warning_count'] || $errors['error_count'])) {
// Try YYYYMMDD format
$DateTime = \DateTime::createFromFormat('Ymd', $value);
$errors = \DateTime::getLastErrors();
}
if ($errors['warning_count'] || $errors['error_count']) {
if (is_array($errors) && ($errors['warning_count'] || $errors['error_count'])) {
$value = $this->getOption(Shapefile::OPTION_DBF_NULLIFY_INVALID_DATES) ? null : $this->truncateOrPadString($this->sanitizeNumber($value), $size);
} else {
$value = $DateTime->format('Ymd');
@@ -963,12 +974,19 @@ class ShapefileWriter extends Shapefile
break;
case Shapefile::DBF_TYPE_LOGICAL:
if ($value === null) {
$value = Shapefile::DBF_VALUE_NULL;
} elseif ($value === true || strpos(Shapefile::DBF_VALUE_MASK_TRUE, substr(trim($value), 0, 1)) !== false) {
$value = Shapefile::DBF_VALUE_TRUE;
if (is_string($value)) {
$value = substr(trim($value), 0, 1);
if (strpos(Shapefile::DBF_VALUE_MASK_TRUE, $value) !== false) {
$value = Shapefile::DBF_VALUE_TRUE;
} elseif (strpos(Shapefile::DBF_VALUE_MASK_FALSE, $value) !== false) {
$value = Shapefile::DBF_VALUE_FALSE;
} else {
$value = Shapefile::DBF_VALUE_NULL;
}
} elseif (is_bool($value) || is_int($value) || is_float($value)) {
$value = $value ? Shapefile::DBF_VALUE_TRUE : Shapefile::DBF_VALUE_FALSE;
} else {
$value = Shapefile::DBF_VALUE_FALSE;
$value = Shapefile::DBF_VALUE_NULL;
}
break;
@@ -1054,8 +1072,17 @@ class ShapefileWriter extends Shapefile
// Shape Type
$ret .= $this->packInt32L($this->getShapeType(Shapefile::FORMAT_INT));
//Bounding Box
$bounding_box = $this->getBoundingBox();
//Bounding Box (Defaults to all zeros for empty Shapefile)
$bounding_box = $this->getBoundingBox() ?: [
'xmin' => -Shapefile::SHP_NO_DATA_VALUE,
'ymin' => -Shapefile::SHP_NO_DATA_VALUE,
'xmax' => Shapefile::SHP_NO_DATA_VALUE,
'ymax' => Shapefile::SHP_NO_DATA_VALUE,
'zmin' => -Shapefile::SHP_NO_DATA_VALUE,
'zmax' => Shapefile::SHP_NO_DATA_VALUE,
'mmin' => -Shapefile::SHP_NO_DATA_VALUE,
'mmax' => Shapefile::SHP_NO_DATA_VALUE,
];
$ret .= $this->packXYBoundingBox($bounding_box);
$ret .= $this->packZRange($this->isZ() ? $bounding_box : ['zmin' => 0, 'zmax' => 0]);
$ret .= $this->packMRange($this->isM() ? $bounding_box : ['mmin' => 0, 'mmax' => 0]);