Пример #1
0
 private function parse_point()
 {
     $x = $this->unpacker->read_double();
     $y = $this->unpacker->read_double();
     if (!$this->with_z && !$this->with_m) {
         return Point::from_xy($x, $y, $this->srid);
     } elseif ($this->with_z && $this->with_m) {
         $z = $this->unpacker->read_double();
         $m = $this->unpacker->read_double();
         return Point::from_xyzm($x, $y, $z, $m, $this->srid);
     } elseif ($this->with_z) {
         $z = $this->unpacker->read_double();
         return Point::from_xyz($x, $y, $z, $this->srid);
     } else {
         // with_m
         $m = $this->unpacker->read_double();
         return Point::from_xym($x, $y, $m, $this->srid);
     }
 }
Пример #2
0
 private function parse_coords()
 {
     $x = $this->tokenizer->get_next_token();
     $y = $this->tokenizer->get_next_token();
     if ($x === null || $y === null) {
         throw new EWKTFormatError('Bad POINT format');
     }
     if ($this->is_3dm) {
         $m = $this->tokenizer->get_next_token();
         if ($m === null || $m == ',' || $m == ')') {
             throw new EWKTFormatError('m component expected but not found');
         } else {
             $point = Point::from_xym(floatval($x), floatval($y), floatval($m), $this->srid);
             $next = $this->tokenizer->get_next_token();
         }
     } else {
         $z = $this->tokenizer->get_next_token();
         if ($z === null) {
             throw new EWKTFormatError('Incorrect termination of EWKT string');
         }
         if ($z == ',' || $z == ')') {
             // No Z value
             $point = Point::from_xy(floatval($x), floatval($y), $this->srid);
             $next = $z;
         } else {
             $m = $this->tokenizer->get_next_token();
             if ($m === null) {
                 throw new EWKTFormatError('Incorrect termination of EWKT string');
             }
             $this->with_z = true;
             if ($m == ',' || $m == ')') {
                 // 3dz
                 $point = Point::from_xyz(floatval($x), floatval($y), floatval($z), $this->srid);
                 $next = $m;
             } else {
                 // 4d
                 $this->with_m = true;
                 $point = Point::from_xyzm(floatval($x), floatval($y), floatval($z), floatval($m), $this->srid);
                 $next = $this->tokenizer->get_next_token();
             }
         }
     }
     return array($next, $point);
 }
Пример #3
0
 public function test_point_extent()
 {
     $p = Point::from_xy(1.1, 2.2, 444);
     $env = $p->extent();
     $this->assertEquals($env->ll, $env->ur);
     $this->assertEquals($p->x, $env->ll->x);
     $this->assertEquals($p->y, $env->ll->y);
     $this->assertEquals(false, $env->with_z);
     $p = Point::from_xyz(1.1, 2.2, 3.3, 444);
     $env = $p->extent();
     $this->assertEquals($env->ll, $env->ur);
     $this->assertEquals($p->x, $env->ll->x);
     $this->assertEquals($p->y, $env->ll->y);
     $this->assertEquals($p->z, $env->ll->z);
     $this->assertEquals(true, $env->with_z);
     $this->assertEquals($p->x, $env->left);
     $this->assertEquals($p->x, $env->right);
     $this->assertEquals($p->y, $env->top);
     $this->assertEquals($p->y, $env->bottom);
 }