-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclasses.php
More file actions
78 lines (65 loc) · 1.33 KB
/
Copy pathclasses.php
File metadata and controls
78 lines (65 loc) · 1.33 KB
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
<?php
class GeoJSONPoint
{
public $p;
function __construct( $lon, $lat )
{
$this->p = array( (float) $lon, (float) $lat );
}
function getGeoJSON()
{
return array( 'type' => 'Point', 'coordinates' => $this->p );
}
static function fromGeoJson( $json )
{
$geo = new GeoJSONPoint( $json['coordinates'][0], $json['coordinates'][1] );
return $geo;
}
}
class GeoJSONLineString
{
public $ls;
function __construct( $ls )
{
$this->ls = $ls;
}
function getGeoJSON()
{
return array( 'type' => 'LineString', 'coordinates' => $this->ls );
}
}
class GeoJSONPolygon
{
public $pg;
function __construct( $pg )
{
$this->pg = $pg;
}
function getGeoJSON()
{
return array( 'type' => 'Polygon', 'coordinates' => $this->pg );
}
static function fromGeoJson( $json )
{
$geo = new GeoJSONPolygon( $json['coordinates'] );
return $geo;
}
static function createFromBounds( $n, $e, $s, $w, $segments = 1 )
{
$coordinates = [];
/* West to East, North side */
for ($j = 0; $j <= $segments; $j++ )
{
$coordinates[] = [ $w + (($e-$w)/$segments*$j), $n ];
}
/* East to West, South side */
for ($j = $segments; $j >= 0; $j-- )
{
$coordinates[] = [ $w + (($e-$w)/$segments*$j), $s ];
}
/* North West corner to tie it up */
$coordinates[] = [ $w, $n ];
return new GeoJSONPolygon( [ $coordinates ] );
}
}
?>