Пример #1
0
 public function test_polygon_ewkt()
 {
     $ring1_coords = array(array(0, 0, 0), array(0, 5, 1), array(5, 5, 2), array(5, 0, 1), array(0, 0, 0));
     $ring2_coords = array(array(1, 1, 0), array(1, 4, 1), array(4, 4, 2), array(4, 1, 1), array(1, 1, 0));
     $poly = Polygon::from_array(array($ring1_coords, $ring2_coords), 444, true);
     $this->assertEquals('SRID=444;POLYGON((0 0 0,0 5 1,5 5 2,5 0 1,0 0 0),(1 1 0,1 4 1,4 4 2,4 1 1,1 1 0))', $poly->to_ewkt());
     $this->assertEquals('POLYGON((0 0,0 5,5 5,5 0,0 0),(1 1,1 4,4 4,4 1,1 1))', $poly->to_wkt());
 }
Пример #2
0
 public function test_extent()
 {
     $ring1_coords = array(array(0, 1, 0), array(0, 6, 1), array(5, 6, 2), array(5, 1, 1), array(0, 1, 0));
     $ring2_coords = array(array(1, 2, 0), array(1, 4, 1), array(4, 4, 2), array(4, 2, 1), array(1, 2, 0));
     $ring1 = LinearRing::from_array($ring1_coords, 444, true);
     $ring2 = LinearRing::from_array($ring2_coords, 444, true);
     $poly = Polygon::from_linear_rings(array($ring1, $ring2), 444, true);
     $e = $poly->extent();
     $this->assertTrue($e->ll instanceof Point);
     $this->assertTrue($e->ur instanceof Point);
     $this->assertEquals(0, $e->ll->x);
     $this->assertEquals(1, $e->ll->y);
     $this->assertEquals(0, $e->ll->z);
     $this->assertEquals(5, $e->ur->x);
     $this->assertEquals(6, $e->ur->y);
     $this->assertEquals(2, $e->ur->z);
 }
Пример #3
0
 public function test_multipolygon_create()
 {
     $ring1_coords = array(array(0, 0, 0), array(0, 5, 1), array(5, 5, 2), array(5, 0, 1), array(0, 0, 0));
     $ring2_coords = array(array(1, 1, 0), array(1, 4, 1), array(4, 4, 2), array(4, 1, 1), array(1, 1, 0));
     $ring3_coords = array(array(6, 6, 0), array(6, 10, 1), array(10, 10, 2), array(10, 6, 1), array(6, 6, 0));
     $poly1 = Polygon::from_array(array($ring1_coords, $ring2_coords), 444, true);
     $poly2 = Polygon::from_array(array($ring3_coords), 444, true);
     $mp = MultiPolygon::from_polygons(array($poly1, $poly2), 444, true);
     $this->assertTrue($mp instanceof MultiPolygon);
     $this->assertEquals(2, count($mp->polygons));
     $this->assertEquals(2, count($mp->polygons[0]->rings));
     $this->assertEquals(1, count($mp->polygons[1]->rings));
     $this->assertEquals(10, $mp->polygons[1]->rings[0]->points[2]->x);
     $this->assertEquals(10, $mp->polygons[1]->rings[0]->points[2]->y);
     $this->assertEquals(2, $mp->polygons[1]->rings[0]->points[2]->z);
     $mp = MultiPolygon::from_array(array(array($ring1_coords, $ring2_coords), array($ring3_coords)), 444, true);
     $this->assertTrue($mp instanceof MultiPolygon);
     $this->assertEquals(2, count($mp->polygons));
 }
Пример #4
0
 private function parse_polygon()
 {
     if ($this->tokenizer->get_next_token() != '(') {
         throw new EWKTFormatError('Invalid POLYGON');
     }
     $token = '';
     $rings = array();
     while ($token != ')') {
         $rings[] = $this->parse_linear_ring();
         $token = $this->tokenizer->get_next_token();
         // comma
         if ($token === null) {
             throw new EWKTFormatError('Incorrect termination of EWKT string');
         }
     }
     return Polygon::from_linear_rings($rings, $this->srid, $this->with_z, $this->with_m);
 }
Пример #5
0
 private function parse_polygon()
 {
     $num_rings = $this->unpacker->read_uint();
     $rings = array();
     for ($i = 0; $i < $num_rings; $i++) {
         $rings[] = $this->parse_linear_ring();
     }
     return Polygon::from_linear_rings($rings, $this->srid, $this->with_z, $this->with_m);
 }