@@ -22,13 +22,14 @@ public function it_stores_geometry_collection(): void
2222 'geometry_collection ' => new GeometryCollection ([
2323 new Polygon ([
2424 new LineString ([
25- new Point (23.1 , 55.5 ),
26- new Point (23.2 , 55.6 ),
27- new Point (23.3 , 55.7 ),
28- new Point (23.1 , 55.5 ),
25+ new Point (0 , 0 ),
26+ new Point (1 , 1 ),
27+ new Point (2 , 2 ),
28+ new Point (3 , 3 ),
29+ new Point (0 , 0 ),
2930 ]),
3031 ]),
31- new Point (23.1 , 55.5 ),
32+ new Point (0 , 0 ),
3233 ]),
3334 ])->fresh ();
3435
@@ -40,20 +41,22 @@ public function it_stores_geometry_collection(): void
4041 $ lineStrings = $ polygon ->getGeometries ();
4142 $ points = $ lineStrings [0 ]->getGeometries ();
4243
43- $ this ->assertEquals (23.1 , $ points [0 ]->latitude );
44- $ this ->assertEquals (55.5 , $ points [0 ]->longitude );
45- $ this ->assertEquals (23.2 , $ points [1 ]->latitude );
46- $ this ->assertEquals (55.6 , $ points [1 ]->longitude );
47- $ this ->assertEquals (23.3 , $ points [2 ]->latitude );
48- $ this ->assertEquals (55.7 , $ points [2 ]->longitude );
49- $ this ->assertEquals (23.1 , $ points [3 ]->latitude );
50- $ this ->assertEquals (55.5 , $ points [3 ]->longitude );
44+ $ this ->assertEquals (0 , $ points [0 ]->latitude );
45+ $ this ->assertEquals (0 , $ points [0 ]->longitude );
46+ $ this ->assertEquals (1 , $ points [1 ]->latitude );
47+ $ this ->assertEquals (1 , $ points [1 ]->longitude );
48+ $ this ->assertEquals (2 , $ points [2 ]->latitude );
49+ $ this ->assertEquals (2 , $ points [2 ]->longitude );
50+ $ this ->assertEquals (3 , $ points [3 ]->latitude );
51+ $ this ->assertEquals (3 , $ points [3 ]->longitude );
52+ $ this ->assertEquals (0 , $ points [4 ]->latitude );
53+ $ this ->assertEquals (0 , $ points [4 ]->longitude );
5154
5255 /** @var Point $point */
5356 $ point = $ geometries [1 ];
5457
55- $ this ->assertEquals (23.1 , $ point ->latitude );
56- $ this ->assertEquals (55.5 , $ point ->longitude );
58+ $ this ->assertEquals (0 , $ point ->latitude );
59+ $ this ->assertEquals (0 , $ point ->longitude );
5760
5861 $ this ->assertDatabaseCount ($ testPlace ->getTable (), 1 );
5962 }
@@ -63,7 +66,7 @@ public function it_stores_geometry_collection_from_geo_json(): void
6366 {
6467 /** @var TestPlace $testPlace */
6568 $ testPlace = TestPlace::factory ()->create ([
66- 'geometry_collection ' => GeometryCollection::fromJson ('{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[55.5,23.1 ],[55.6,23. 2],[55.7,23. 3],[55.5,23.1 ]]]},{"type":"Point","coordinates":[55.5,23.1 ]}]} ' ),
69+ 'geometry_collection ' => GeometryCollection::fromJson ('{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[0,0],[1,1 ],[2, 2],[3, 3],[0,0 ]]]},{"type":"Point","coordinates":[0,0 ]}]} ' ),
6770 ])->fresh ();
6871
6972 $ this ->assertTrue ($ testPlace ->geometry_collection instanceof GeometryCollection);
@@ -74,20 +77,22 @@ public function it_stores_geometry_collection_from_geo_json(): void
7477 $ lineStrings = $ polygon ->getGeometries ();
7578 $ points = $ lineStrings [0 ]->getGeometries ();
7679
77- $ this ->assertEquals (23.1 , $ points [0 ]->latitude );
78- $ this ->assertEquals (55.5 , $ points [0 ]->longitude );
79- $ this ->assertEquals (23.2 , $ points [1 ]->latitude );
80- $ this ->assertEquals (55.6 , $ points [1 ]->longitude );
81- $ this ->assertEquals (23.3 , $ points [2 ]->latitude );
82- $ this ->assertEquals (55.7 , $ points [2 ]->longitude );
83- $ this ->assertEquals (23.1 , $ points [3 ]->latitude );
84- $ this ->assertEquals (55.5 , $ points [3 ]->longitude );
80+ $ this ->assertEquals (0 , $ points [0 ]->latitude );
81+ $ this ->assertEquals (0 , $ points [0 ]->longitude );
82+ $ this ->assertEquals (1 , $ points [1 ]->latitude );
83+ $ this ->assertEquals (1 , $ points [1 ]->longitude );
84+ $ this ->assertEquals (2 , $ points [2 ]->latitude );
85+ $ this ->assertEquals (2 , $ points [2 ]->longitude );
86+ $ this ->assertEquals (3 , $ points [3 ]->latitude );
87+ $ this ->assertEquals (3 , $ points [3 ]->longitude );
88+ $ this ->assertEquals (0 , $ points [4 ]->latitude );
89+ $ this ->assertEquals (0 , $ points [4 ]->longitude );
8590
8691 /** @var Point $point */
8792 $ point = $ geometries [1 ];
8893
89- $ this ->assertEquals (23.1 , $ point ->latitude );
90- $ this ->assertEquals (55.5 , $ point ->longitude );
94+ $ this ->assertEquals (0 , $ point ->latitude );
95+ $ this ->assertEquals (0 , $ point ->longitude );
9196
9297 $ this ->assertDatabaseCount ($ testPlace ->getTable (), 1 );
9398 }
@@ -97,7 +102,7 @@ public function it_stores_geometry_collection_from_feature_collection_geo_json()
97102 {
98103 /** @var TestPlace $testPlace */
99104 $ testPlace = TestPlace::factory ()->create ([
100- 'geometry_collection ' => GeometryCollection::fromJson ('{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[55.5,23.1 ],[55.6,23. 2],[55.7,23. 3],[55.5,23.1 ]]]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[55.5,23.1 ]}}]} ' ),
105+ 'geometry_collection ' => GeometryCollection::fromJson ('{"type":"FeatureCollection","features":[{"type":"Feature","properties":[]," geometry":{"type":"Polygon","coordinates":[[[0,0],[1,1 ],[2, 2],[3, 3],[0,0 ]]]}},{"type":"Feature","properties":[]," geometry":{"type":"Point","coordinates":[0,0 ]}}]} ' ),
101106 ])->fresh ();
102107
103108 $ this ->assertTrue ($ testPlace ->geometry_collection instanceof GeometryCollection);
@@ -108,39 +113,67 @@ public function it_stores_geometry_collection_from_feature_collection_geo_json()
108113 $ lineStrings = $ polygon ->getGeometries ();
109114 $ points = $ lineStrings [0 ]->getGeometries ();
110115
111- $ this ->assertEquals (23.1 , $ points [0 ]->latitude );
112- $ this ->assertEquals (55.5 , $ points [0 ]->longitude );
113- $ this ->assertEquals (23.2 , $ points [1 ]->latitude );
114- $ this ->assertEquals (55.6 , $ points [1 ]->longitude );
115- $ this ->assertEquals (23.3 , $ points [2 ]->latitude );
116- $ this ->assertEquals (55.7 , $ points [2 ]->longitude );
117- $ this ->assertEquals (23.1 , $ points [3 ]->latitude );
118- $ this ->assertEquals (55.5 , $ points [3 ]->longitude );
116+ $ this ->assertEquals (0 , $ points [0 ]->latitude );
117+ $ this ->assertEquals (0 , $ points [0 ]->longitude );
118+ $ this ->assertEquals (1 , $ points [1 ]->latitude );
119+ $ this ->assertEquals (1 , $ points [1 ]->longitude );
120+ $ this ->assertEquals (2 , $ points [2 ]->latitude );
121+ $ this ->assertEquals (2 , $ points [2 ]->longitude );
122+ $ this ->assertEquals (3 , $ points [3 ]->latitude );
123+ $ this ->assertEquals (3 , $ points [3 ]->longitude );
124+ $ this ->assertEquals (0 , $ points [4 ]->latitude );
125+ $ this ->assertEquals (0 , $ points [4 ]->longitude );
119126
120127 /** @var Point $point */
121128 $ point = $ geometries [1 ];
122129
123- $ this ->assertEquals (23.1 , $ point ->latitude );
124- $ this ->assertEquals (55.5 , $ point ->longitude );
130+ $ this ->assertEquals (0 , $ point ->latitude );
131+ $ this ->assertEquals (0 , $ point ->longitude );
125132
126133 $ this ->assertDatabaseCount ($ testPlace ->getTable (), 1 );
127134 }
128135
129136 /** @test */
130- public function it_generates_multi_polygon_geo_json (): void
137+ public function it_generates_geometry_collection_geo_json (): void
131138 {
132139 $ geometryCollection = new GeometryCollection ([
133140 new Polygon ([
134141 new LineString ([
135- new Point (23.1 , 55.5 ),
136- new Point (23.2 , 55.6 ),
137- new Point (23.3 , 55.7 ),
138- new Point (23.1 , 55.5 ),
142+ new Point (0 , 0 ),
143+ new Point (1 , 1 ),
144+ new Point (2 , 2 ),
145+ new Point (3 , 3 ),
146+ new Point (0 , 0 ),
139147 ]),
140148 ]),
141- new Point (23.1 , 55.5 ),
149+ new Point (0 , 0 ),
142150 ]);
143151
144- $ this ->assertEquals ('{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[55.5,23.1],[55.6,23.2],[55.7,23.3],[55.5,23.1]]]},{"type":"Point","coordinates":[55.5,23.1]}]} ' , $ geometryCollection ->toJson ());
152+ $ this ->assertEquals (
153+ '{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[0,0],[1,1],[2,2],[3,3],[0,0]]]},{"type":"Point","coordinates":[0,0]}]} ' ,
154+ $ geometryCollection ->toJson ()
155+ );
156+ }
157+
158+ /** @test */
159+ public function it_generates_geometry_collection_feature_collection_json (): void
160+ {
161+ $ geometryCollection = new GeometryCollection ([
162+ new Polygon ([
163+ new LineString ([
164+ new Point (0 , 0 ),
165+ new Point (1 , 1 ),
166+ new Point (2 , 2 ),
167+ new Point (3 , 3 ),
168+ new Point (0 , 0 ),
169+ ]),
170+ ]),
171+ new Point (0 , 0 ),
172+ ]);
173+
174+ $ this ->assertEquals (
175+ '{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"Polygon","coordinates":[[[0,0],[1,1],[2,2],[3,3],[0,0]]]}},{"type":"Feature","properties":[],"geometry":{"type":"Point","coordinates":[0,0]}}]} ' ,
176+ $ geometryCollection ->toFeatureCollectionJson ()
177+ );
145178 }
146179}
0 commit comments