22
33namespace Javaabu \Geospatial ;
44
5- use Geometry as geoPHPGeometry ;
6- use geoPHP ;
5+ use Brick \ Geo \ Geometry as BrickGeometry ;
6+ use Brick \ Geo \ MultiPoint ;
77use InvalidArgumentException ;
88use Javaabu \Geospatial \Objects \Point ;
99use Javaabu \Geospatial \Objects \Polygon ;
1010use MatanYadaev \EloquentSpatial \Objects \Geometry ;
11- use Point as geoPHPPoint ;
12- use Polygon as geoPHPPolygon ;
1311
1412class Factory extends \MatanYadaev \EloquentSpatial \Factory
1513{
1614 public static function parse (string $ value ): Geometry
1715 {
18- try {
19- /** @var geoPHPGeometry|false $geoPHPGeometry */
20- $ geoPHPGeometry = geoPHP::load ($ value );
21- } finally {
22- if (! isset ($ geoPHPGeometry ) || ! $ geoPHPGeometry ) {
23- throw new InvalidArgumentException ('Invalid spatial value ' );
24- }
25- }
26-
27- return self ::createFromGeometry ($ geoPHPGeometry );
16+ return parent ::parse ($ value );
2817 }
29- protected static function createFromGeometry (geoPHPGeometry $ geometry ): Geometry
18+
19+ protected static function createFromGeometry (BrickGeometry $ geometry , bool $ isRoot = true ): Geometry
3020 {
3121 $ srid = is_int ($ geometry ->getSRID ()) ? $ geometry ->getSRID () : 0 ;
3222
33- if ($ geometry instanceof geoPHPPoint ) {
23+ if ($ geometry instanceof Point ) {
3424 if ($ geometry ->coords [0 ] === null || $ geometry ->coords [1 ] === null ) {
3525 throw new InvalidArgumentException ('Invalid spatial value ' );
3626 }
@@ -39,16 +29,14 @@ protected static function createFromGeometry(geoPHPGeometry $geometry): Geometry
3929 }
4030
4131 $ components = collect ($ geometry ->components )
42- ->map (static function (geoPHPGeometry $ geometryComponent ): Geometry {
32+ ->map (static function (MultiPoint $ geometryComponent ): Geometry {
4333 return self ::createFromGeometry ($ geometryComponent );
4434 });
4535
46- if ($ geometry ::class === geoPHPPolygon ::class) {
36+ if ($ geometry ::class === Polygon ::class) {
4737 return new Polygon ($ components , $ srid );
4838 }
4939
50- return parent ::createFromGeometry ($ geometry );
40+ return parent ::createFromGeometry ($ geometry, $ isRoot );
5141 }
52-
53-
5442}
0 commit comments