-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
116 lines (100 loc) · 3.15 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
require __DIR__ . '/../vendor/autoload.php';
/**
*
*/
use \Ballen\Distical\Entities\LatLong;
use Ballen\Cartographer\LineString;
/**
* Test a LineString type.
*/
$testCoords = [
new LatLong(51.51259, -0.12514),
new LatLong(51.51537, -0.01614),
new LatLong(51.48758, -0.06111),
new LatLong(51.48267, -0.35328),
];
$linestring = new \Ballen\Cartographer\LineString($testCoords);
echo $linestring->generate();
/**
* Test adding a single Point.
*/
$point = new \Ballen\Cartographer\Point(new LatLong(51.882034, 0.230355));
echo $point->generate();
/**
* Test a multipoint type.
*/
$multipoint = new \Ballen\Cartographer\MultiPoint($testCoords);
echo $multipoint->generate();
/**
* Test a multipointstring type.
*/
$roadCoords = [
new LatLong(52.005700, 1.045057),
new LatLong(52.005651, 1.045329),
new LatLong(52.005521, 1.045709),
new LatLong(52.005348, 1.046035),
new LatLong(52.005262, 1.046356),
new LatLong(52.005181, 1.046561),
new LatLong(52.005074, 1.046860),
new LatLong(52.005038, 1.047102),
new LatLong(52.005029, 1.047338),
new LatLong(52.005042, 1.047543),
new LatLong(52.005103, 1.047982),
new LatLong(52.005257, 1.048789),
];
$multilinestring = new \Ballen\Cartographer\MultiLineString([
new LineString($testCoords),
new LineString($roadCoords)]
);
echo $multilinestring->generate();
/**
* Test a polygon type.
*/
// Load a complex polygon schema from a test file...
$polygon_example = json_decode(file_get_contents(__DIR__ . '/polygon.json'), true);
// Create a LinearRing object to contain the polygon data.
$linearRing = new \Ballen\Cartographer\Core\LinearRing();
foreach ($polygon_example['coordinates'] as $poly) {
$linearRing->addRing($poly);
}
$polygon = new \Ballen\Cartographer\Polygon($linearRing);
echo $polygon->generate();
/**
* Test a MultiPolygon type.
*/
$polygon_example2 = json_decode(file_get_contents(__DIR__ . '/polygon2.json'), true);
// Create a LinearRing object to contain the polygon data.
$linearRing2 = new \Ballen\Cartographer\Core\LinearRing();
foreach ($polygon_example2['coordinates'] as $poly2) {
$linearRing2->addRing($poly2);
}
$polygon2 = new \Ballen\Cartographer\Polygon($linearRing2);
$multipolygon_example = (new Ballen\Cartographer\MultiPolygon())
->addPolygon($polygon)
->addPolygon($polygon2);
echo $multipolygon_example->generate();
/**
* Test a GeometryCollection type
*/
$geometryCollection_example = new Ballen\Cartographer\GeometryCollection([$linestring, $point]);
echo $geometryCollection_example->generate();
/**
* Test a Feature type
*/
$feature_example = new \Ballen\Cartographer\Feature($point, [
'name' => 'Example point',
'link' => 'http://example.com/point',
]);
echo $feature_example->generate();
/**
* Test a FeatureCollection tpye
*/
$featureCollection_example = new Ballen\Cartographer\FeatureCollection();
$featureCollection_example->addFeature($feature_example);
$feature_example2 = new \Ballen\Cartographer\Feature($polygon, [
'name' => 'A polygon example',
'link' => 'http://example.com/polygon'
]);
$featureCollection_example->addFeature($feature_example2);
echo $featureCollection_example->generate();