1 | <?php |
||
8 | class Utils |
||
9 | { |
||
10 | const POLYGON_GEOJSON_NAME = "Polygon"; |
||
11 | const POINT_WKT_NAME = "POINT"; |
||
12 | const FEATURE_COLLECTION_GEOJSON_NAME = "FeatureCollection"; |
||
13 | const FEATURE_GEOJSON_NAME = "Feature"; |
||
14 | const WKT_EXTENSION = "wkt"; |
||
15 | const GEOJSON_EXTENSION = "json"; |
||
16 | const NOT_FOUND_IN_FEATURES = "notFoundInFeatures"; |
||
17 | |||
18 | /** |
||
19 | * Convert array of coordinates to polygon structured json array |
||
20 | * @param $polygonPoints |
||
21 | * @return array |
||
22 | */ |
||
23 | 7 | public function createPolygonJsonFromPoints($polygonPoints) |
|
30 | |||
31 | /** |
||
32 | * Structure polygon coordinates as geoPHP needs |
||
33 | * @param $polygonPoints |
||
34 | * @return array |
||
35 | */ |
||
36 | 7 | protected function structurePolygonCoordinates($polygonPoints) |
|
37 | { |
||
38 | 7 | $structuredCoordinates = array(); |
|
39 | 7 | foreach ($polygonPoints as $points) { |
|
40 | 7 | if (count($points) == 2) { |
|
41 | 7 | $structuredCoordinates[] = $polygonPoints; |
|
42 | 7 | break; |
|
43 | } |
||
44 | 1 | $structuredCoordinates[] = $points; |
|
45 | } |
||
46 | 7 | return $structuredCoordinates; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * Create polygon geometry object from polygon points array |
||
51 | * @param $polygonPoints |
||
52 | * @return bool|geoPHP::GeometryCollection|mixed |
||
|
|||
53 | */ |
||
54 | protected function createPolygonFromPoints($polygonPoints) |
||
59 | |||
60 | /** |
||
61 | * Create polygon geometry object from structured polygon data (as json) |
||
62 | * @param $polygonJson |
||
63 | * @return bool|geoPHP::GeometryCollection|mixed |
||
64 | */ |
||
65 | 7 | public function createPolygonFromJson($polygonJson) |
|
75 | |||
76 | /** |
||
77 | * Adapt quadrant bounds to polygon array format |
||
78 | * @param $quadrantBounds |
||
79 | * @return array |
||
80 | */ |
||
81 | public function adaptQuadrantBoundsToPolygon($quadrantBounds) |
||
93 | |||
94 | /** |
||
95 | * Create polygon object from quadrant bounds |
||
96 | * @param $quadrantBounds |
||
97 | * @return mixed |
||
98 | */ |
||
99 | public function getQuadrantPolygon($quadrantBounds) |
||
104 | |||
105 | /** |
||
106 | * Structure features data |
||
107 | * @param $features |
||
108 | * @return array |
||
109 | */ |
||
110 | protected function structureFeatures($features) |
||
118 | |||
119 | /** |
||
120 | * Structure an isolated feature |
||
121 | * @param $feature |
||
122 | * @return array |
||
123 | */ |
||
124 | protected function structureOneFeature($feature) |
||
136 | |||
137 | /** |
||
138 | * Create feature collection array from features list |
||
139 | * @param $features |
||
140 | * @return array |
||
141 | */ |
||
142 | public function getFeatureCollection($features) |
||
150 | |||
151 | /** |
||
152 | * Get intersection data json from two different geometry features |
||
153 | * @param $geoFeaturesJsonA |
||
154 | * @param $geoFeaturesJsonB |
||
155 | * @return mixed |
||
156 | */ |
||
157 | public function intersection($geoFeaturesJsonA, $geoFeaturesJsonB) |
||
164 | |||
165 | /** |
||
166 | * Check if a particular object point is IN the indicated polygon (source: https://github.com/sookoll/geoPHP.git) |
||
167 | * and if it is not contained inside, it checks the boundaries |
||
168 | * @param $point |
||
169 | * @param $polygon |
||
170 | * @return mixed |
||
171 | */ |
||
172 | 7 | protected function isInPolygon($point, $polygon) |
|
189 | |||
190 | /** |
||
191 | * Check if point is ON the boundaries of the polygon |
||
192 | * @param $point |
||
193 | * @param $polygon |
||
194 | * @return mixed |
||
195 | */ |
||
196 | 3 | protected function isOnPolygonBoundaries($point, $polygon) |
|
200 | |||
201 | /** |
||
202 | * Check if the polygonA intersects with polygonB |
||
203 | * @param $polygonJsonA |
||
204 | * @param $polygonBoundsB |
||
205 | * @return mixed |
||
206 | * @internal param $polygonA |
||
207 | * @internal param $polygonB |
||
208 | */ |
||
209 | public function intersectsPolygons($polygonJsonA, $polygonBoundsB) |
||
215 | |||
216 | /** |
||
217 | * Check if the polygonA is within polygonB |
||
218 | * @param $polygonBoundsOrigin |
||
219 | * @param $polygonJsonDest |
||
220 | * @return mixed |
||
221 | * @internal param $polygonA |
||
222 | * @internal param $polygonB |
||
223 | */ |
||
224 | public function withinPolygon($polygonBoundsOrigin, $polygonJsonDest) |
||
230 | |||
231 | /** |
||
232 | * Create a point geometry object from coordinates (latitude, longitude) |
||
233 | * @param $latitude |
||
234 | * @param $longitude |
||
235 | * @return bool|geoPHP::GeometryCollection|mixed |
||
236 | */ |
||
237 | 7 | protected function createPoint($latitude, $longitude) |
|
248 | |||
249 | /** |
||
250 | * Check if point (latitude, longitude) is IN a particular features polygon |
||
251 | * @param $features |
||
252 | * @param $latitude |
||
253 | * @param $longitude |
||
254 | * @return null|string |
||
255 | */ |
||
256 | 7 | public function isPointInQuadrantFeatures($features, $latitude, $longitude) |
|
278 | |||
279 | /** |
||
280 | * Check if the point is between two points from the polygon |
||
281 | * @param $point |
||
282 | * @param $currentPolygonPoint |
||
283 | * @param $backPolygonPoint |
||
284 | * @return bool |
||
285 | */ |
||
286 | 7 | protected function isInside($point, $currentPolygonPoint, $backPolygonPoint) |
|
295 | } |
||
296 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.