Beispiel #1
0
 public static function fromXmlObj(SimpleXMLElement $xmlObj)
 {
     $relation = new OSM_Objects_Relation();
     $processedElements = $relation->_fromXmlObj($xmlObj);
     foreach ($xmlObj->children() as $child) {
         if (in_array($child->getName(), $processedElements)) {
             continue;
         }
         OSM_ZLog::debug(__METHOD__, 'Found child: ', $child->getName());
         switch ($child->getName()) {
             case self::OBJTYPE_MEMBER:
                 $member = OSM_Objects_Member::fromXmlObj($child);
                 $relation->addMember($member);
                 break;
             default:
                 throw new OSM_Exception('Object "' . $xmlObj->getName() . '" is not supported in relation');
         }
     }
     $relation->setDirty(false);
     return $relation;
 }
Beispiel #2
0
 /**
  * Return relation's way ordered by nodes position, like we can draw a well formed polygon.
  *
  * @param OSM_Objects_Relation $relation
  * @return OSM_Objects_Way[]
  */
 public function getRelationWaysOrdered(OSM_Objects_Relation $relation)
 {
     $membersWays = $relation->findMembersByType(self::OBJTYPE_WAY);
     $w1 = $membersWays[0];
     if (!array_key_exists($w1->getRef(), $this->_ways)) {
         throw new OSM_Exception('Way not loaded, you must load the full relation.');
     }
     $waysOrderedIds = array();
     $waysOrdered = array();
     $ww1 = $this->_ways[$w1->getRef()];
     $waysOrderedIds[$ww1->getId()] = $ww1;
     $waysOrdered[] = $ww1;
     for ($i = 0; $i < count($membersWays); $i++) {
         if (!array_key_exists($w1->getRef(), $this->_ways)) {
             throw new OSM_Exception('Way not loaded, you must load the full relation.');
         }
         $ww1 = $this->_ways[$w1->getRef()];
         for ($j = 0; $j < count($membersWays); $j++) {
             $w2 = $membersWays[$j];
             if ($w1->getRef() == $w2->getRef()) {
                 continue;
             }
             if (array_key_exists($w2->getRef(), $waysOrderedIds)) {
                 continue;
             }
             if (!array_key_exists($w2->getRef(), $this->_ways)) {
                 throw new OSM_Exception('Way not loaded, you must load the full relation.');
             }
             $ww2 = $this->_ways[$w2->getRef()];
             $nId1F = $ww1->getFirstNodeRef();
             $nId1L = $ww1->getLastNodeRef();
             $nId2F = $ww2->getFirstNodeRef();
             $nId2L = $ww2->getLastNodeRef();
             if ($nId1F == $nId2F || $nId1F == $nId2L || $nId1L == $nId2F || $nId1L == $nId2L) {
                 $waysOrderedIds[$ww2->getId()] = $ww2;
                 $waysOrdered[] = $ww2;
                 $w1 = $w2;
                 break;
             }
         }
     }
     return $waysOrdered;
 }