Skip to content

Commit 7f62564

Browse files
authored
Merge pull request grimzy#128 from grimzy/issue-58-fix-retrieving-empty-geometry-collection
Fix issue where the WKB of empty GeometryCollections was not getting parsed
2 parents e5e4c89 + 8818d7a commit 7f62564

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/Eloquent/SpatialTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function setRawAttributes(array $attributes, $sync = false)
104104
$spatial_fields = $this->getSpatialFields();
105105

106106
foreach ($attributes as $attribute => &$value) {
107-
if (in_array($attribute, $spatial_fields) && is_string($value) && strlen($value) >= 15) {
107+
if (in_array($attribute, $spatial_fields) && is_string($value) && strlen($value) >= 13) {
108108
$value = Geometry::fromWKB($value);
109109
}
110110
}

tests/Integration/Models/GeometryModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ class GeometryModel extends Model
99

1010
protected $table = 'geometry';
1111

12-
protected $spatialFields = ['location', 'line'];
12+
protected $spatialFields = ['location', 'line', 'multi_geometries'];
1313
}

tests/Integration/SpatialTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ public function testInsertEmptyGeometryCollection()
251251
$geo->multi_geometries = new GeometryCollection([]);
252252
$geo->save();
253253
$this->assertDatabaseHas('geometry', ['id' => $geo->id]);
254+
255+
$geo2 = GeometryModel::find($geo->id);
256+
$this->assertInstanceOf(GeometryCollection::class, $geo2->multi_geometries);
257+
$this->assertEquals(0, count($geo2->multi_geometries));
254258
}
255259

256260
public function testUpdate()

0 commit comments

Comments
 (0)