@@ -22,13 +22,14 @@ public function it_stores_geometry_collection(): void
22
22
'geometry_collection ' => new GeometryCollection ([
23
23
new Polygon ([
24
24
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 ),
29
30
]),
30
31
]),
31
- new Point (23.1 , 55.5 ),
32
+ new Point (0 , 0 ),
32
33
]),
33
34
])->fresh ();
34
35
@@ -40,20 +41,22 @@ public function it_stores_geometry_collection(): void
40
41
$ lineStrings = $ polygon ->getGeometries ();
41
42
$ points = $ lineStrings [0 ]->getGeometries ();
42
43
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 );
51
54
52
55
/** @var Point $point */
53
56
$ point = $ geometries [1 ];
54
57
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 );
57
60
58
61
$ this ->assertDatabaseCount ($ testPlace ->getTable (), 1 );
59
62
}
@@ -63,7 +66,7 @@ public function it_stores_geometry_collection_from_geo_json(): void
63
66
{
64
67
/** @var TestPlace $testPlace */
65
68
$ 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 ]}]} ' ),
67
70
])->fresh ();
68
71
69
72
$ this ->assertTrue ($ testPlace ->geometry_collection instanceof GeometryCollection);
@@ -74,20 +77,22 @@ public function it_stores_geometry_collection_from_geo_json(): void
74
77
$ lineStrings = $ polygon ->getGeometries ();
75
78
$ points = $ lineStrings [0 ]->getGeometries ();
76
79
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 );
85
90
86
91
/** @var Point $point */
87
92
$ point = $ geometries [1 ];
88
93
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 );
91
96
92
97
$ this ->assertDatabaseCount ($ testPlace ->getTable (), 1 );
93
98
}
@@ -97,7 +102,7 @@ public function it_stores_geometry_collection_from_feature_collection_geo_json()
97
102
{
98
103
/** @var TestPlace $testPlace */
99
104
$ 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 ]}}]} ' ),
101
106
])->fresh ();
102
107
103
108
$ this ->assertTrue ($ testPlace ->geometry_collection instanceof GeometryCollection);
@@ -108,39 +113,67 @@ public function it_stores_geometry_collection_from_feature_collection_geo_json()
108
113
$ lineStrings = $ polygon ->getGeometries ();
109
114
$ points = $ lineStrings [0 ]->getGeometries ();
110
115
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 );
119
126
120
127
/** @var Point $point */
121
128
$ point = $ geometries [1 ];
122
129
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 );
125
132
126
133
$ this ->assertDatabaseCount ($ testPlace ->getTable (), 1 );
127
134
}
128
135
129
136
/** @test */
130
- public function it_generates_multi_polygon_geo_json (): void
137
+ public function it_generates_geometry_collection_geo_json (): void
131
138
{
132
139
$ geometryCollection = new GeometryCollection ([
133
140
new Polygon ([
134
141
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 ),
139
147
]),
140
148
]),
141
- new Point (23.1 , 55.5 ),
149
+ new Point (0 , 0 ),
142
150
]);
143
151
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
+ );
145
178
}
146
179
}
0 commit comments