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; } public static function parsePoint ($domNode) { $gmlPoint = new GmlPoint(); $currentSibling = $domNode->firstChild; while ($currentSibling) { $coordArray = explode(" ", $currentSibling->nodeValue); $gmlPoint->setPoint($coordArray[0], $coordArray[1]); $currentSibling = $currentSibling->nextSibling; } return $gmlPoint; } public static function parseLine ($domNode) { $gmlLine = new GmlLine(); $currentSibling = $domNode->firstChild; while ($currentSibling) { $dim = self::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; } return $gmlLine; } public static function parsePolygon ($domNode) { $gmlPolygon = new 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 = self::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 = self::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++; } } return $gmlPolygon; } public static function parseMultiLine ($domNode) { $gmlMultiLine = new GmlMultiLine(); $simpleXMLNode = simplexml_import_dom($domNode); $simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml'); $allCoords = $simpleXMLNode->xpath("gml:lineStringMember/gml:LineString/gml:posList"); if (count($allCoords) === 0) { $allCoords = $simpleXMLNode->xpath("gml:lineStringMembers/gml:LineString/gml:posList"); } $cnt=0; foreach ($allCoords as $Coords) { $gmlMultiLine->lineArray[$cnt] = array(); $coordsDom = dom_import_simplexml($Coords); $dim = self::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++; } return $gmlMultiLine; } public static function parseMultiPoint ($domNode) { $gmlMultiPoint = new GmlMultiPoint(); $simpleXMLNode = simplexml_import_dom($domNode); $simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml'); $allCoords = $simpleXMLNode->xpath("gml:pointMember/gml:Point/gml:pos"); if (count($allCoords) === 0) { $allCoords = $simpleXMLNode->xpath("gml:pointMembers/gml:Point/gml:pos"); } foreach ($allCoords as $Coords) { $coordsDom = dom_import_simplexml($Coords); $dim = self::getDimensionFromNode($coordsDom); $coordArray = explode(' ', trim($coordsDom->nodeValue)); for ($i = 0; $i < count($coordArray); $i += $dim) { $x = $coordArray[$i]; $y = $coordArray[$i+1]; $gmlMultiPoint->addPoint($x, $y); break; } } return $gmlMultiPoint; } public static function parseMultiCurve ($domNode) { $gmlMultiLine = new GmlMultiLine(); $simpleXMLNode = simplexml_import_dom($domNode); $simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml'); $allCoords = $simpleXMLNode->xpath("gml:curveMembers/gml:LineString/gml:posList"); if (count($allCoords) === 0) { $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 = self::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++; } return $gmlMultiLine; } public static function parseMultiPolygon ($domNode) { $gmlMultiPolygon = new GmlMultiPolygon(); $simpleXMLNode = simplexml_import_dom($domNode); $simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml'); $allPolygons = $simpleXMLNode->xpath("gml:surfaceMember/gml:Polygon"); if (count($allPolygons) === 0) { $allPolygons = $simpleXMLNode->xpath("gml:surfaceMembers/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 = self::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 = self::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)); } return $gmlMultiPolygon; } /** * 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 = self::parsePolygon($geomNode); if ($feature->geometry->isEmpty()) { $feature->geometry = Gml_2_Factory::parsePolygon($geomNode); } $feature->geometry->srs = $srs; break; case "gml:LineString" :// untested! $feature->geometry = self::parseLine($geomNode); if ($feature->geometry->isEmpty()) { $feature->geometry = Gml_2_Factory::parseLine($geomNode); } $feature->geometry->srs = $srs; break; case "gml:Point" : $feature->geometry = self::parsePoint($geomNode); if ($feature->geometry->isEmpty()) { $feature->geometry = Gml_2_Factory::parsePoint($geomNode); } $feature->geometry->srs = $srs; break; case "gml:MultiPoint" : $feature->geometry = self::parseMultiPoint($geomNode); if ($feature->geometry->isEmpty()) { $feature->geometry = Gml_2_Factory::parseMultiPoint($geomNode); } $feature->geometry->srs = $srs; break; case "gml:MultiLineString" : new mb_exception("found multilinestring"); $feature->geometry = self::parseMultiLine($geomNode); if ($feature->geometry->isEmpty()) { $feature->geometry = Gml_2_Factory::parseMultiLine($geomNode); } $feature->geometry->srs = $srs; break; case "gml:MultiCurve" : $feature->geometry = self::parseMultiCurve($geomNode); if ($feature->geometry->isEmpty()) { $feature->geometry = Gml_2_Factory::parseMultiLine($geomNode); } $feature->geometry->srs = $srs; break; case "gml:MultiSurface" : $feature->geometry = self::parseMultiPolygon($geomNode); if ($feature->geometry->isEmpty()) { $feature->geometry = Gml_2_Factory::parseMultiPolygon($geomNode); } $feature->geometry->srs = $srs; break; default: $feature->properties[$columnName] = $value; break; } } else { if ($currentSibling->hasChildNodes() && $currentSibling->firstChild instanceof DOMText) { $feature->properties[$columnName] = $value; } } $currentSibling = $currentSibling->nextSibling; } } } ?>