hasAttribute("srsDimension")) { return 2; } $dim = intval($domNode->getAttribute("srsDimension"), 10); if (2 == $dim || 3 == $dim) { return $dim; } return 2; } function findNameSpace($s){ list($ns,$FeaturePropertyName) = split(":",$s); $nodeName = array('ns' => $ns, 'value' => $FeaturePropertyName); return $nodeName; } private function parsePoint ($domNode, $gmlPoint) { $currentSibling = $domNode->firstChild; while ($currentSibling) { $coordArray = explode(" ", $currentSibling->nodeValue); $gmlPoint->setPoint($coordArray[0], $coordArray[1]); $currentSibling = $currentSibling->nextSibling; } } private function parseLine ($domNode, $gmlLine) { $currentSibling = $domNode->firstChild; while ($currentSibling) { $dim = $this->getDimensionFromNode($currentSibling); $coordArray = explode(' ', trim($currentSibling->nodeValue)); for ($i = 0; $i < count($coordArray); $i += $dim) { $x = $coordArray[$i]; $y = $coordArray[$i+1]; $gmlLine->addPoint($x, $y); } $currentSibling = $currentSibling->nextSibling; } } private function parsePolygon ($domNode, $gmlPolygon) { $simpleXMLNode = simplexml_import_dom($domNode); $simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml'); $allCoords = $simpleXMLNode->xpath("gml:exterior/gml:LinearRing/gml:posList"); $cnt=0; foreach ($allCoords as $Coords) { $coordsDom = dom_import_simplexml($Coords); $dim = $this->getDimensionFromNode($coordsDom); $coordArray = explode(' ', trim($coordsDom->nodeValue)); for ($i = 0; $i < count($coordArray); $i += $dim) { $x = $coordArray[$i]; $y = $coordArray[$i+1]; $gmlPolygon->addPoint($x, $y); } $cnt++; } $innerRingNodeArray = $simpleXMLNode->xpath("gml:innerBoundaryIs/gml:LinearRing"); if ($innerRingNodeArray) { $ringCount = 0; foreach ($innerRingNodeArray as $ringNode) { $coordinates = $ringNode->xpath("gml:coordinates"); foreach ($coordinates as $coordinate) { $coordsDom = dom_import_simplexml($coordinate); $dim = $this->getDimensionFromNode($coordsDom); $coordArray = explode(' ', trim($coordsDom->nodeValue)); for ($i = 0; $i < count($coordArray); $i += $dim) { $x = $coordArray[$i]; $y = $coordArray[$i+1]; $gmlPolygon->addPointToRing($ringCount, $x, $y); } } $ringCount++; } } } private function parseMultiLine ($domNode, $gmlMultiLine) { $simpleXMLNode = simplexml_import_dom($domNode); $simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml'); $allCoords = $simpleXMLNode->xpath("gml:curveMember/gml:LineString/gml:posList"); $cnt=0; foreach ($allCoords as $Coords) { $gmlMultiLine->lineArray[$cnt] = array(); $coordsDom = dom_import_simplexml($Coords); $dim = $this->getDimensionFromNode($coordsDom); $coordArray = explode(' ', trim($coordsDom->nodeValue)); for ($i = 0; $i < count($coordArray); $i += $dim) { $x = $coordArray[$i]; $y = $coordArray[$i+1]; $gmlMultiLine->addPoint($x, $y, $cnt); } $cnt++; } } private function parseMultiPolygon ($domNode, $gmlMultiPolygon) { $simpleXMLNode = simplexml_import_dom($domNode); $simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml'); $allPolygons = $simpleXMLNode->xpath("gml:surfaceMember/gml:Polygon"); $cnt=0; foreach ($allPolygons as $polygon) { $allCoords = $polygon->xpath("gml:exterior/gml:LinearRing/gml:posList"); $gmlMultiPolygon->polygonArray[$cnt] = array(); foreach ($allCoords as $Coords) { $coordsDom = dom_import_simplexml($Coords); $dim = $this->getDimensionFromNode($coordsDom); $coordArray = explode(' ', trim($coordsDom->nodeValue)); for ($i = 0; $i < count($coordArray); $i += $dim) { $x = $coordArray[$i]; $y = $coordArray[$i+1]; $gmlMultiPolygon->addPoint($x, $y, $cnt); } } $gmlMultiPolygon->innerRingArray[$cnt] = array(); $innerRingNodeArray = $polygon->xpath("gml:interior"); if ($innerRingNodeArray) { $ringCount = 0; foreach ($innerRingNodeArray as $ringNode) { $currentRingNode = $ringNode->xpath("gml:LinearRing"); foreach ($currentRingNode as $node) { $coordinates = $node->xpath("gml:posList"); foreach ($coordinates as $coordinate) { $coordsDom = dom_import_simplexml($coordinate); $dim = $this->getDimensionFromNode($coordsDom); $coordArray = explode(' ', trim($coordsDom->nodeValue)); for ($i = 0; $i < count($coordArray); $i += $dim) { $x = $coordArray[$i]; $y = $coordArray[$i+1]; $gmlMultiPolygon->addPointToRing($cnt, $ringCount, $x, $y); } } $ringCount++; } } } $cnt++; // new mb_exception("create multipolygon " . serialize($gmlMultiPolygon->innerRingArray)); } } /** * Parses the feature segment of a GML and stores the geometry in the * $geometry variable of the class. * * Example of a feature segment of a GML. * * * * * * 39.700000 29.400000 * 46.400000 35.400000 * * * * * * * * * * 43.200000 35.400000 * 46.400000 31.700000 * 44.100000 31.000000 * 41.700000 29.400000 * 39.700000 31.400000 * 43.300000 32.300000 * 43.200000 35.400000 * * * * * * * * 16752039 * 624 * inter_08 * * * 3 * * * * @return void * @param $domNode DOMNodeObject the feature tag of the GML * ( in the above example) */ protected function parseFeature($domNode, $feature, $wfsConf) { $geomFeaturetypeElement = $wfsConf->getGeometryColumnName(); $feature->fid = $domNode->getAttribute("gml:id"); $currentSibling = $domNode->firstChild; while ($currentSibling) { $name = $currentSibling->nodeName; $value = $currentSibling->nodeValue; $namespace = $this->findNameSpace($name); $ns = $namespace['ns']; $columnName = $namespace['value']; $isGeomColumn = ($geomFeaturetypeElement == null || $columnName == $geomFeaturetypeElement); // check if this node is a geometry node. // however, even if it is a property node, // it has a child node, the text node! // So we might need to do something more // sophisticated here... if ($currentSibling->hasChildNodes() && $isGeomColumn){ $geomNode = $currentSibling->firstChild; $geomType = $geomNode->nodeName; if ($geomNode->hasAttribute("srsName")) { $srs = $geomNode->getAttribute("srsName"); } switch ($geomType) { case "gml:Polygon" :// untested! $feature->geometry = new GMLPolygon(); $feature->geometry->srs = $srs; $this->parsePolygon($geomNode, $feature->geometry); break; case "gml:LineString" :// untested! $feature->geometry = new GMLLine(); $feature->geometry->srs = $srs; $this->parseLine($geomNode, $feature->geometry); break; case "gml:Point" : $feature->geometry = new GMLPoint(); $feature->geometry->srs = $srs; $this->parsePoint($geomNode, $feature->geometry); break; case "gml:MultiCurve" : $feature->geometry = new GMLMultiLine(); $feature->geometry->srs = $srs; $this->parseMultiLine($geomNode, $feature->geometry); break; case "gml:MultiSurface" : $feature->geometry = new GMLMultiPolygon(); $feature->geometry->srs = $srs; $this->parseMultiPolygon($geomNode, $feature->geometry); break; default: $feature->properties[$columnName] = $value; break; } } else { if ($currentSibling->hasChildNodes() && $currentSibling->firstChild instanceof DOMText) { $feature->properties[$columnName] = $value; } } $currentSibling = $currentSibling->nextSibling; } } } ?>