示例#1
0
 public function __construct($projString)
 {
     $this->specs = $projString;
     if (preg_match('/^\\d+$/', $projString)) {
         $this->format = 'wkid';
     } elseif (preg_match('/^\\w+\\[/', $projString)) {
         $this->format = 'wkt';
     } elseif (preg_match('/^\\+/', $projString)) {
         $this->format = 'proj4';
     }
     switch ($this->format) {
         case 'wkid':
             $projString = MapProjector::getProjSpecs($projString);
             $params = self::parseProj4String($projString);
             $this->initFromProj4Params($params);
             break;
         case 'wkt':
             $params = WKTParser::parseWKTString($projString);
             $this->initFromWKTParams($params);
             break;
         case 'proj4':
         default:
             $params = self::parseProj4String($projString);
             $this->initFromProj4Params($params);
             break;
     }
 }
示例#2
0
 public function dbFields()
 {
     $styleId = isset($this->style) && $this->style instanceof MapDBStyle ? $this->style->getId() : null;
     $fields = array('placemark_id' => $this->id, 'name' => $this->title, 'address' => $this->address, 'lat' => $this->centroid['lat'], 'lon' => $this->centroid['lon'], 'geometry' => WKTParser::wktFromGeometry($this->geometry), 'style_id' => $styleId);
     return $fields;
 }
示例#3
0
文件: MapDB.php 项目: nncsang/Kurogo
 public static function updateFeature(Placemark $feature, $parentCategoryId, $projector = null)
 {
     $style = $feature->getStyle();
     if (method_exists($style, 'getId')) {
         $styleId = $style->getId();
     } else {
         $styleId = null;
     }
     $geometry = $feature->getGeometry();
     if ($geometry) {
         if ($projector) {
             $geometry = $projector->projectGeometry($geometry);
         }
         $centroid = $geometry->getCenterCoordinate();
         $wkt = WKTParser::wktFromGeometry($geometry);
     } else {
         // TODO: handle this instead of throwing exception
         throw new KurogoDataException("feature has no geometry");
     }
     $placemarkId = $feature->getId();
     // placemark table
     $isStored = $feature instanceof MapDBPlacemark && $feature->isStored();
     if (!$isStored) {
         $sql = 'SELECT * FROM ' . self::PLACEMARK_TABLE . ' WHERE placemark_id=? AND lat=? AND lon=?';
         $params = array($placemarkId, $centroid['lat'], $centroid['lon']);
         $results = self::connection()->query($sql, $params);
         if ($results->fetch()) {
             $isStored = true;
         }
     }
     $params = array($feature->getTitle(), $feature->getAddress(), $styleId, $wkt, $placemarkId, $centroid['lat'], $centroid['lon']);
     if ($isStored) {
         $sql = 'UPDATE ' . self::PLACEMARK_TABLE . '   SET name=?, address=?, style_id=?, geometry=?' . ' WHERE placemark_id=? AND lat=? AND lon=?';
     } else {
         $sql = 'INSERT INTO ' . self::PLACEMARK_TABLE . ' (name, address, style_id, geometry, placemark_id, lat, lon)' . ' VALUES (?, ?, ?, ?, ?, ?, ?)';
     }
     self::connection()->query($sql, $params);
     if ($placemarkId === null) {
         // TODO: check db compatibility for this function
         $placemarkId = self::connection()->lastInsertId();
     }
     // categories
     $categories = $feature->getCategoryIds();
     if (!is_array($categories)) {
         $categories = array();
     }
     if (!in_array($parentCategoryId, $categories)) {
         $categories[] = $parentCategoryId;
     }
     foreach ($categories as $categoryId) {
         $sql = 'INSERT INTO ' . self::PLACEMARK_CATEGORY_TABLE . ' (placemark_id, lat, lon, category_id)' . ' VALUES (?, ?, ?, ?)';
         $params = array($placemarkId, $centroid['lat'], $centroid['lon'], $categoryId);
         self::connection()->query($sql, $params, db::IGNORE_ERRORS);
     }
     // properties
     $sql = 'DELETE FROM ' . self::PLACEMARK_PROPERTIES_TABLE . ' WHERE placemark_id=?';
     $params = array($placemarkId);
     self::connection()->query($sql, $params);
     $properties = $feature->getFields();
     foreach ($properties as $name => $value) {
         $sql = 'INSERT INTO ' . self::PLACEMARK_PROPERTIES_TABLE . ' (placemark_id, lat, lon, property_name, property_value)' . ' VALUES (?, ?, ?, ?, ?)';
         $params = array($placemarkId, $centroid['lat'], $centroid['lon'], $name, $value);
         self::connection()->query($sql, $params);
     }
 }