PHP code example of aeris / spatial
1. Go to this page and download the library: Download aeris/spatial library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aeris / spatial example snippets
use Aeris\Spatial\GeometryConverter;
$geoJson = json_encode([
'type' => 'Polygon',
'coordinates' => [
[
[100, 0],
[101, 0],
[101, 1],
[100, 1],
[100, 0],
]
]
]);
$wkt = GeometryConverter::geoJsonToWkt($geoJson);
$this->assertEquals(
'POLYGON((100 0,101 0,101 1,100 1,100 0))',
$wkt
);
$geoJson = [
'type' => 'FeatureCollection',
'features' => [
[
'type' => 'Feature',
'geometry' => [
'type' => 'Polygon',
'coordinates' => [
[
[100, 0],
[100, 100],
[0, 100],
[0, 0],
[100, 0],
]
]
],
],
[
'type' => 'Feature',
'geometry' => [
'type' => 'Polygon',
'coordinates' => [
[
[200, 0],
[200, 200],
[0, 200],
[0, 0],
[200, 0]
]
]
]
]
],
];
$mPoly = MultiPolygon::FromFeatureCollection($geoJson);
$this->assertEquals([
Polygon::FromArray([
[
[100, 0],
[100, 100],
[0, 100],
[0, 0],
[100, 0]
]
]),
Polygon::FromArray([
[
[200, 0],
[200, 200],
[0, 200],
[0, 0],
[200, 0]
]
])
], $mPoly->getPolygons());
$myQuery = 'SELECT * FROM `places` ' .
'WHERE ST_CONTAINS(GeomFromText(' . $mPoly->toWKT() . '), `places`.`point`)'
$minneapolis = new Coordinate(-93.251953125, 44.9336963896947);
$chicago = new Coordinate(-87.71484375, 41.80407814427237);
Util\bearing($minneapolis, $chicago); // 125.93766052151
Util\bearing($chicago, $minneapolis); // 309.74293632484
$minneapolis = new Coordinate(-93.251953125, 44.9336963896947);
$edenPrarie = new Coordinate(-93.4768295288086, 44.85148787683413);
Util\compassDirection($minneapolis, $edenPrarie); // 'SW'
Util\compassDirection($edenPrarie, $minneapolis); // 'NE'