當前位置: 首頁>>代碼示例>>PHP>>正文


PHP geoPHP::geosToGeometry方法代碼示例

本文整理匯總了PHP中geoPHP::geosToGeometry方法的典型用法代碼示例。如果您正苦於以下問題:PHP geoPHP::geosToGeometry方法的具體用法?PHP geoPHP::geosToGeometry怎麽用?PHP geoPHP::geosToGeometry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在geoPHP的用法示例。


在下文中一共展示了geoPHP::geosToGeometry方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: centroid

 public function centroid()
 {
     if ($this->isEmpty()) {
         return NULL;
     }
     if ($this->geos()) {
         return geoPHP::geosToGeometry($this->geos()->centroid());
     }
     $exterior_ring = $this->components[0];
     $pts = $exterior_ring->getComponents();
     $c = count($pts);
     if ((int) $c == '0') {
         return NULL;
     }
     $cn = array('x' => '0', 'y' => '0');
     $a = $this->area(TRUE, TRUE);
     // If this is a polygon with no area. Just return the first point.
     if ($a == 0) {
         return $this->exteriorRing()->pointN(1);
     }
     foreach ($pts as $k => $p) {
         $j = ($k + 1) % $c;
         $P = $p->getX() * $pts[$j]->getY() - $p->getY() * $pts[$j]->getX();
         $cn['x'] = $cn['x'] + ($p->getX() + $pts[$j]->getX()) * $P;
         $cn['y'] = $cn['y'] + ($p->getY() + $pts[$j]->getY()) * $P;
     }
     $cn['x'] = $cn['x'] / (6 * $a);
     $cn['y'] = $cn['y'] / (6 * $a);
     $centroid = new Point($cn['x'], $cn['y']);
     return $centroid;
 }
開發者ID:drupdateio,項目名稱:gvj,代碼行數:31,代碼來源:Polygon.class.php

示例2: getBBox

 public function getBBox()
 {
     if ($this->isEmpty()) {
         return NULL;
     }
     if ($this->geos()) {
         $envelope = $this->geos()->envelope();
         if ($envelope->typeName() == 'Point') {
             return geoPHP::geosToGeometry($envelope)->getBBOX();
         }
         $geos_ring = $envelope->exteriorRing();
         return array('maxy' => $geos_ring->pointN(3)->getY(), 'miny' => $geos_ring->pointN(1)->getY(), 'maxx' => $geos_ring->pointN(1)->getX(), 'minx' => $geos_ring->pointN(3)->getX());
     }
     // Go through each component and get the max and min x and y
     $i = 0;
     foreach ($this->components as $component) {
         $component_bbox = $component->getBBox();
         // On the first run through, set the bbox to the component bbox
         if ($i == 0) {
             $maxx = $component_bbox['maxx'];
             $maxy = $component_bbox['maxy'];
             $minx = $component_bbox['minx'];
             $miny = $component_bbox['miny'];
         }
         // Do a check and replace on each boundary, slowly growing the bbox
         $maxx = $component_bbox['maxx'] > $maxx ? $component_bbox['maxx'] : $maxx;
         $maxy = $component_bbox['maxy'] > $maxy ? $component_bbox['maxy'] : $maxy;
         $minx = $component_bbox['minx'] < $minx ? $component_bbox['minx'] : $minx;
         $miny = $component_bbox['miny'] < $miny ? $component_bbox['miny'] : $miny;
         $i++;
     }
     return array('maxy' => $maxy, 'miny' => $miny, 'maxx' => $maxx, 'minx' => $minx);
 }
開發者ID:tijdmedia,項目名稱:geophp,代碼行數:33,代碼來源:Collection.php

示例3: read

 /**
  * Read WKT string into geometry objects
  *
  * @param string $WKT A WKT string
  *
  * @return Geometry|GeometryCollection
  */
 public function read($wkt)
 {
     $wkt = strval($wkt);
     // If geos is installed, then we take a shortcut and let it parse the WKT
     if (geoPHP::geosInstalled()) {
         $reader = new GEOSWKTReader();
         return geoPHP::geosToGeometry($reader->read($wkt));
     }
     $matches = array();
     if (!preg_match($this->regExes['typeStr'], $wkt, $matches)) {
         return null;
     }
     return $this->parse(strtolower($matches[1]), $matches[2]);
 }
開發者ID:happy-code-com,項目名稱:PHP5-Shape-File-Parser,代碼行數:21,代碼來源:WKT.class.php

示例4: read

 /**
  * Read WKT string into geometry objects
  *
  * @param string $WKT A WKT string
  *
  * @return Geometry
  */
 public function read($wkt)
 {
     $wkt = trim($wkt);
     // If it contains a ';', then it contains additional SRID data
     if (strpos($wkt, ';')) {
         $parts = explode(';', $wkt);
         $wkt = $parts[1];
         $eparts = explode('=', $parts[0]);
         $srid = $eparts[1];
     } else {
         $srid = NULL;
     }
     // If geos is installed, then we take a shortcut and let it parse the WKT
     if (geoPHP::geosInstalled()) {
         $reader = new GEOSWKTReader();
         if ($srid) {
             $geom = geoPHP::geosToGeometry($reader->read($wkt));
             $geom->setSRID($srid);
             return $geom;
         } else {
             return geoPHP::geosToGeometry($reader->read($wkt));
         }
     }
     $wkt = str_replace(', ', ',', $wkt);
     // For each geometry type, check to see if we have a match at the
     // beggining of the string. If we do, then parse using that type
     foreach (geoPHP::geometryList() as $geom_type) {
         $wkt_geom = strtoupper($geom_type);
         if (strtoupper(substr($wkt, 0, strlen($wkt_geom))) == $wkt_geom) {
             $data_string = $this->getDataString($wkt, $wkt_geom);
             $method = 'parse' . $geom_type;
             if ($srid) {
                 $geom = $this->{$method}($data_string);
                 $geom->setSRID($srid);
                 return $geom;
             } else {
                 return $this->{$method}($data_string);
             }
         }
     }
 }
開發者ID:drupdateio,項目名稱:gvj,代碼行數:48,代碼來源:WKT.class.php

示例5: simplify

 public function simplify($tolerance, $preserveTopology = FALSE)
 {
     if ($this->geos()) {
         return geoPHP::geosToGeometry($this->geos()->simplify($tolerance, $preserveTopology));
     }
 }
開發者ID:tijdmedia,項目名稱:geophp,代碼行數:6,代碼來源:Geometry.php


注:本文中的geoPHP::geosToGeometry方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。