Пример #1
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);
 }
Пример #2
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);
     }
 }
Пример #3
0
 public function test_point_ewkt()
 {
     $p = Point::from_xy(1.1, 2.2, 444);
     $this->assertEquals('SRID=444;POINT(1.1 2.2)', $p->to_ewkt());
     $p = Point::from_xyz(1.1, 2.2, 3.3, 444);
     $this->assertEquals('SRID=444;POINT(1.1 2.2 3.3)', $p->to_ewkt());
     $this->assertEquals('POINT(1.1 2.2 3.3)', $p->to_ewkt(false));
     $this->assertEquals('POINT(1.1 2.2)', $p->to_wkt());
     $p = Point::from_xym(1.1, 2.2, 3.3, 444);
     $this->assertEquals('SRID=444;POINTM(1.1 2.2 3.3)', $p->to_ewkt(true, false));
     $p = Point::from_xyzm(1.1, 2.2, 3.3, 4.4, 444);
     $this->assertEquals('SRID=444;POINT(1.1 2.2 3.3 4.4)', $p->to_ewkt());
 }