Skip to content

Commit

Permalink
Use constant to store header magic
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Nov 21, 2016
1 parent 023fba7 commit 1a29e8b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/ShapeFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* @package ShapeFile
*/
class ShapeFile {
const MAGIC = 0x270a;

public $FileName;

private $SHPFile = null;
Expand Down Expand Up @@ -276,7 +278,7 @@ private function _deleteRecordFromDBF($index) {
}

private function _loadHeaders() {
if (Util::loadData('N', $this->readSHP(4)) != 0x270a) {
if (Util::loadData('N', $this->readSHP(4)) != ShapeFile::MAGIC) {
$this->setError('Not a SHP file (file code mismatch)');
return false;
}
Expand Down Expand Up @@ -325,13 +327,13 @@ private function _saveBBox($file) {
}

private function _saveHeaders() {
fwrite($this->SHPFile, pack('NNNNNN', 9994, 0, 0, 0, 0, 0));
fwrite($this->SHPFile, pack('NNNNNN', ShapeFile::MAGIC, 0, 0, 0, 0, 0));
fwrite($this->SHPFile, pack('N', $this->fileLength));
fwrite($this->SHPFile, pack('V', 1000));
fwrite($this->SHPFile, pack('V', $this->shapeType));
$this->_saveBBox($this->SHPFile);

fwrite($this->SHXFile, pack('NNNNNN', 9994, 0, 0, 0, 0, 0));
fwrite($this->SHXFile, pack('NNNNNN', ShapeFile::MAGIC, 0, 0, 0, 0, 0));
fwrite($this->SHXFile, pack('N', 50 + 4 * count($this->records)));
fwrite($this->SHXFile, pack('V', 1000));
fwrite($this->SHXFile, pack('V', $this->shapeType));
Expand Down

0 comments on commit 1a29e8b

Please sign in to comment.