Forráskód Böngészése

added multiple DescribeFeatureType in WFS for AUTO CAD 3d

Piotr Labudda 10 éve
szülő
commit
7c1b55cc3d

+ 6 - 91
SE/se-lib/Api/WfsDataServer.php

@@ -157,7 +157,7 @@ if($DBG){echo 'item['.$itemKey.'] ('.$geomFld.')isEmpty('.empty($item->{$geomFld
 							$featureFldNode->appendChild($geomNode);
 						} else {
 							$featureFldNode->nodeValue = str_replace('&', '&', $item->{$fldName});
-							if (empty($featureFldNode->nodeValue)) {
+							if (empty($featureFldNode->nodeValue) && '0' !== $featureFldNode->nodeValue) {
 								continue;
 							}
 						}
@@ -171,102 +171,17 @@ if($DBG){echo 'item['.$itemKey.'] ('.$geomFld.')isEmpty('.empty($item->{$geomFld
 	public function describeFeatureTypeAction() {
 		$type = V::get('TYPENAME', '', $_REQUEST);
 		if (empty($type)) {
+			$reqContent = Request::getRequestBody();
+			if (!empty($reqContent)) {
+				return $this->_parseDescribeFeatureTypeRequest($reqContent);
+			}
 			throw new HttpException("Wrong param TYPENAME", 400);
 		}
 		$typeEx = explode(':', $type);
 		if (count($typeEx) != 2) {
 			throw new HttpException("Wrong param TYPENAME", 400);
 		}
-		return $this->getDescribeFeatureType($typeEx[0], $typeEx[1]);
-	}
-
-	public function getDescribeFeatureType($nsPrefix, $type) {
-		$typeName = "{$nsPrefix}:{$type}";
-		$acl = $this->getAclFromTypeName($typeName);
-
-		$baseNsUri = $this->getBaseNamespaceUri();
-		$wfsNs = 'p5_default_db_' . $type;//$nsPrefix;
-		$wfsNsUri = "{$baseNsUri}/" . substr($nsPrefix, 3) . '/' . $type;
-
-		if (empty($type)) {
-			throw new HttpException("Feature Type Name not defined", 400);
-		}
-		if (!$this->isAllowedFeatureType($nsPrefix, $type)) {
-			throw new Api_WfsException("Could not find type: " . htmlspecialchars($type));
-		}
-
-		$typeName = $type . 'Type';
-		$fldList = $acl->getRealFieldList();
-		header('Content-type: application/xml');
-		// <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://webgis.regione.sardegna.it:80/geoserver/schemas/gml/2.1.2/feature.xsd"/>
-		//	<xsd:element name="{type}" substitutionGroup="gml:_Feature" type="dbu:{typeName}"/>
-
-		$dom = new DOMDocument('1.0', 'utf-8');
-		$dom->formatOutput = true;
-		$dom->preserveWhiteSpace = false;
-		$rootNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
-		$dom->appendChild($rootNode);
-		$rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
-		$rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $wfsNs, $wfsNsUri);
-		$rootNode->setAttribute('elementFormDefault', 'qualified');
-		$rootNode->setAttribute('targetNamespace', $wfsNsUri);
-
-		$cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
-		$rootNode->appendChild($cTypeNode);
-		$cTypeNode->setAttribute('name', $typeName);
-
-		$cConNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexContent');
-		$cTypeNode->appendChild($cConNode);
-
-		$extNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:extension');
-		$cConNode->appendChild($extNode);
-		$extNode->setAttribute('base', 'gml:AbstractFeatureType');
-
-		$seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
-		$extNode->appendChild($seqNode);
-
-		// <xsd:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xsd:integer"/>
-		$pKeyField = $acl->getPrimaryKeyField();
-		foreach ($fldList as $fldName) {
-			$elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
-			$seqNode->appendChild($elNode);
-			$elNode->setAttribute('name', $fldName);
-			$minOccurs = 0;
-			if ($pKeyField == $fldName) {
-				$minOccurs = '1';
-			} else {
-				$minOccurs = '0';
-			}
-			$elNode->setAttribute('minOccurs', $minOccurs);
-			if ($acl->isIntegerField($fldName)) {
-				$fldType = 'xsd:integer';
-			}
-			else if ($acl->isDecimalField($fldName)) {
-				$fldType = 'xsd:decimal';
-			}
-			else if ($acl->isDateField($fldName)) {
-				$fldType = 'xsd:date';
-			}
-			else if ($acl->isDateTimeField($fldName)) {
-				$fldType = 'xsd:dateTime';
-			}
-			else if ($acl->isGeomField($fldName)) {
-				$fldType = 'gml:GeometryPropertyType';
-				//$fldType = 'gml:Polygon';// nie działa musi być gml:GeometryPropertyType
-			}
-			else {
-				$fldType = 'xsd:string';
-			}
-			$elNode->setAttribute('type', $fldType);
-			$elNode->setAttribute('nillable', 'true');
-		}
-
-		$elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
-		$rootNode->appendChild($elNode);
-		$elNode->setAttribute('name', $type);
-		$elNode->setAttribute('type', $wfsNs . ':' . $typeName);
-
-		echo $dom->saveXML();
+		return $this->_getDescribeFeatureType($typeEx[0], $typeEx[1]);
 	}
 
 	public function getCapabilitiesAction() {

+ 5 - 90
SE/se-lib/Api/WfsQgisServer.php

@@ -177,102 +177,17 @@ if(0){// TODO: get BBOX
 	public function describeFeatureTypeAction() {
 		$type = V::get('TYPENAME', '', $_REQUEST);
 		if (empty($type)) {
+			$reqContent = Request::getRequestBody();
+			if (!empty($reqContent)) {
+				return $this->_parseDescribeFeatureTypeRequest($reqContent);
+			}
 			throw new HttpException("Wrong param TYPENAME", 400);
 		}
 		$typeEx = explode(':', $type);
 		if (count($typeEx) != 2) {
 			throw new HttpException("Wrong param TYPENAME", 400);
 		}
-		return $this->getDescribeFeatureType($typeEx[0], $typeEx[1]);
-	}
-
-	public function getDescribeFeatureType($nsPrefix, $type) {
-		$typeName = "{$nsPrefix}:{$type}";
-		$acl = $this->getAclFromTypeName($typeName);
-
-		$baseNsUri = $this->getBaseNamespaceUri();
-		$wfsNs = 'p5_default_db_' . $type;//$nsPrefix;
-		$wfsNsUri = "{$baseNsUri}/" . substr($nsPrefix, 3) . '/' . $type;
-
-		if (empty($type)) {
-			throw new HttpException("Feature Type Name not defined", 400);
-		}
-		if (!$this->isAllowedFeatureType($nsPrefix, $type)) {
-			throw new Api_WfsException("Could not find type: " . htmlspecialchars($type));
-		}
-
-		$typeName = $type . 'Type';
-		$fldList = $acl->getRealFieldList();
-		header('Content-type: application/xml');
-		// <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://webgis.regione.sardegna.it:80/geoserver/schemas/gml/2.1.2/feature.xsd"/>
-		//	<xsd:element name="{type}" substitutionGroup="gml:_Feature" type="dbu:{typeName}"/>
-
-		$dom = new DOMDocument('1.0', 'utf-8');
-		$dom->formatOutput = true;
-		$dom->preserveWhiteSpace = false;
-		$rootNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
-		$dom->appendChild($rootNode);
-		$rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
-		$rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $wfsNs, $wfsNsUri);
-		$rootNode->setAttribute('elementFormDefault', 'qualified');
-		$rootNode->setAttribute('targetNamespace', $wfsNsUri);
-
-		$cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
-		$rootNode->appendChild($cTypeNode);
-		$cTypeNode->setAttribute('name', $typeName);
-
-		$cConNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexContent');
-		$cTypeNode->appendChild($cConNode);
-
-		$extNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:extension');
-		$cConNode->appendChild($extNode);
-		$extNode->setAttribute('base', 'gml:AbstractFeatureType');
-
-		$seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
-		$extNode->appendChild($seqNode);
-
-		// <xsd:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xsd:integer"/>
-		$pKeyField = $acl->getPrimaryKeyField();
-		foreach ($fldList as $fldName) {
-			$elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
-			$seqNode->appendChild($elNode);
-			$elNode->setAttribute('name', $fldName);
-			$minOccurs = 0;
-			if ($pKeyField == $fldName) {
-				$minOccurs = '1';
-			} else {
-				$minOccurs = '0';
-			}
-			$elNode->setAttribute('minOccurs', $minOccurs);
-			if ($acl->isIntegerField($fldName)) {
-				$fldType = 'xsd:integer';
-			}
-			else if ($acl->isDecimalField($fldName)) {
-				$fldType = 'xsd:decimal';
-			}
-			else if ($acl->isDateField($fldName)) {
-				$fldType = 'xsd:date';
-			}
-			else if ($acl->isDateTimeField($fldName)) {
-				$fldType = 'xsd:dateTime';
-			}
-			else if ($acl->isGeomField($fldName)) {
-				$fldType = 'gml:GeometryPropertyType';
-				//$fldType = 'gml:Polygon';// nie działa musi być gml:GeometryPropertyType
-			}
-			else {
-				$fldType = 'xsd:string';
-			}
-			$elNode->setAttribute('type', $fldType);
-			$elNode->setAttribute('nillable', 'true');
-		}
-
-		$elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
-		$rootNode->appendChild($elNode);
-		$elNode->setAttribute('name', $type);
-		$elNode->setAttribute('type', $wfsNs . ':' . $typeName);
-
-		echo $dom->saveXML();
+		return $this->_getDescribeFeatureType($typeEx[0], $typeEx[1]);
 	}
 
 	public function getCapabilitiesAction() {

+ 222 - 0
SE/se-lib/Api/WfsServerBase.php

@@ -1289,4 +1289,226 @@ EOF;
 		return $typeXsd;
 	}
 
+	public function _getDescribeFeatureType($nsPrefix, $type) {
+		$typeName = "{$nsPrefix}:{$type}";
+		$acl = $this->getAclFromTypeName($typeName);
+
+		$baseNsUri = $this->getBaseNamespaceUri();
+		$wfsNs = 'p5_default_db_' . $type;//$nsPrefix;
+		$wfsNsUri = "{$baseNsUri}/" . substr($nsPrefix, 3) . '/' . $type;
+
+		if (empty($type)) {
+			throw new HttpException("Feature Type Name not defined", 400);
+		}
+		if (!$this->isAllowedFeatureType($nsPrefix, $type)) {
+			throw new Api_WfsException("Could not find type: " . htmlspecialchars($type));
+		}
+
+		$typeName = $type . 'Type';
+		$fldList = $acl->getRealFieldList();
+		header('Content-type: application/xml');
+		// <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://webgis.regione.sardegna.it:80/geoserver/schemas/gml/2.1.2/feature.xsd"/>
+		//	<xsd:element name="{type}" substitutionGroup="gml:_Feature" type="dbu:{typeName}"/>
+
+		$dom = new DOMDocument('1.0', 'utf-8');
+		$dom->formatOutput = true;
+		$dom->preserveWhiteSpace = false;
+		$rootNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
+		$dom->appendChild($rootNode);
+		$rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
+		$rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $wfsNs, $wfsNsUri);
+		$rootNode->setAttribute('elementFormDefault', 'qualified');
+		$rootNode->setAttribute('targetNamespace', $wfsNsUri);
+
+		$cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
+		$rootNode->appendChild($cTypeNode);
+		$cTypeNode->setAttribute('name', $typeName);
+
+		$cConNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexContent');
+		$cTypeNode->appendChild($cConNode);
+
+		$extNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:extension');
+		$cConNode->appendChild($extNode);
+		$extNode->setAttribute('base', 'gml:AbstractFeatureType');
+
+		$seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
+		$extNode->appendChild($seqNode);
+
+		// <xsd:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xsd:integer"/>
+		$pKeyField = $acl->getPrimaryKeyField();
+		foreach ($fldList as $fldName) {
+			$elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
+			$seqNode->appendChild($elNode);
+			$elNode->setAttribute('name', $fldName);
+			$minOccurs = 0;
+			if ($pKeyField == $fldName) {
+				$minOccurs = '1';
+			} else {
+				$minOccurs = '0';
+			}
+			$elNode->setAttribute('minOccurs', $minOccurs);
+			if ($acl->isIntegerField($fldName)) {
+				$fldType = 'xsd:integer';
+			}
+			else if ($acl->isDecimalField($fldName)) {
+				$fldType = 'xsd:decimal';
+			}
+			else if ($acl->isDateField($fldName)) {
+				$fldType = 'xsd:date';
+			}
+			else if ($acl->isDateTimeField($fldName)) {
+				$fldType = 'xsd:dateTime';
+			}
+			else if ($acl->isGeomField($fldName)) {
+				$fldType = 'gml:GeometryPropertyType';
+				//$fldType = 'gml:Polygon';// nie działa musi być gml:GeometryPropertyType
+			}
+			else {
+				$fldType = 'xsd:string';
+			}
+			$elNode->setAttribute('type', $fldType);
+			$elNode->setAttribute('nillable', 'true');
+		}
+
+		$elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
+		$rootNode->appendChild($elNode);
+		$elNode->setAttribute('name', $type);
+		$elNode->setAttribute('type', $wfsNs . ':' . $typeName);
+
+		echo $dom->saveXML();
+	}
+
+	public function _parseDescribeFeatureTypeRequest($reqContent) {
+		$parserXml = xml_parser_create();
+		xml_parser_set_option($parserXml, XML_OPTION_CASE_FOLDING, 0);
+		xml_parser_set_option($parserXml, XML_OPTION_SKIP_WHITE, 1);
+		if (0 == xml_parse_into_struct($parserXml, $reqContent, $tags)) {
+			throw new Exception("Error parsing xml");
+		}
+		xml_parser_free($parserXml);
+		if (empty($tags)) {
+			throw new Exception("Empty structure from request");
+		}
+
+		$rootTagName = V::get('tag', '', $tags[0]);
+		if ('DescribeFeatureType' != $rootTagName) {
+			throw new Api_WfsException("Wrong xml root tag '{$rootTagName}' #" . __LINE__, 501);
+		}
+		$requestXmlTags = $tags;
+		$DBG = (V::get('DBG_XML', '', $_GET) > 0);// TODO: Profiler
+		$rootTagName = V::get('tag', '', $requestXmlTags[0]);
+		if ('DescribeFeatureType' != $rootTagName) {
+			throw new Exception("Parse Request xml error #" . __LINE__);
+		}
+		/*[1] => Array(
+						[tag] => TypeName
+						[type] => complete
+						[level] => 2
+						[value] => p5_default_db:Rozdzielcza_rurociag_wsg84)
+		*/
+		$typeNames = array();
+		$totalTypes = count($requestXmlTags) - 1;
+		for ($i = 1; $i < $totalTypes; $i++) {
+			if($DBG){echo "TAG[{$i}]:" . json_encode($requestXmlTags[$i]) . "\n";}
+			$typeNames[] = explode(':', $requestXmlTags[$i]['value'], 2);
+		}
+		//echo "typeNames: " . json_encode($typeNames) . "\n";
+		return $this->_getDescribeFeatureTypes($typeNames);
+	}
+
+	// @param $typeNames = array( array( $nsPrefix, $type ) )
+	public function _getDescribeFeatureTypes($typeNames) {
+		if (empty($typeNames)) {
+			throw new HttpException("Feature Type Names not defined", 400);
+		}
+		$baseNsUri = $this->getBaseNamespaceUri();
+
+		$wfsNs = 'p5_default_db';
+		$wfsNsUri = "{$baseNsUri}/default_db";
+
+		header('Content-type: application/xml');
+		// <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://webgis.regione.sardegna.it:80/geoserver/schemas/gml/2.1.2/feature.xsd"/>
+		//	<xsd:element name="{type}" substitutionGroup="gml:_Feature" type="dbu:{typeName}"/>
+
+		$dom = new DOMDocument('1.0', 'utf-8');
+		$dom->formatOutput = true;
+		$dom->preserveWhiteSpace = false;
+		$rootNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
+		$dom->appendChild($rootNode);
+		$rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
+		$rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $wfsNs, $wfsNsUri);
+		$rootNode->setAttribute('elementFormDefault', 'qualified');
+		$rootNode->setAttribute('targetNamespace', $wfsNsUri);
+
+		foreach ($typeNames as $typeNameEx) {
+			$nsPrefix = $typeNameEx[0];
+			$type = $typeNameEx[1];
+
+			$typeName = "{$nsPrefix}:{$type}";
+			$acl = $this->getAclFromTypeName($typeName);
+			if (!$this->isAllowedFeatureType($nsPrefix, $type)) {
+				throw new Api_WfsException("Could not find type: " . htmlspecialchars($type));
+			}
+			$typeName = $type . 'Type';
+			$fldList = $acl->getRealFieldList();
+
+			$cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
+			$rootNode->appendChild($cTypeNode);
+			$cTypeNode->setAttribute('name', $typeName);
+
+			$cConNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexContent');
+			$cTypeNode->appendChild($cConNode);
+
+			$extNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:extension');
+			$cConNode->appendChild($extNode);
+			$extNode->setAttribute('base', 'gml:AbstractFeatureType');
+
+			$seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
+			$extNode->appendChild($seqNode);
+
+			// <xsd:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xsd:integer"/>
+			$pKeyField = $acl->getPrimaryKeyField();
+			foreach ($fldList as $fldName) {
+				$elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
+				$seqNode->appendChild($elNode);
+				$elNode->setAttribute('name', $fldName);
+				$minOccurs = 0;
+				if ($pKeyField == $fldName) {
+					$minOccurs = '1';
+				} else {
+					$minOccurs = '0';
+				}
+				$elNode->setAttribute('minOccurs', $minOccurs);
+				if ($acl->isIntegerField($fldName)) {
+					$fldType = 'xsd:integer';
+				}
+				else if ($acl->isDecimalField($fldName)) {
+					$fldType = 'xsd:decimal';
+				}
+				else if ($acl->isDateField($fldName)) {
+					$fldType = 'xsd:date';
+				}
+				else if ($acl->isDateTimeField($fldName)) {
+					$fldType = 'xsd:dateTime';
+				}
+				else if ($acl->isGeomField($fldName)) {
+					$fldType = 'gml:GeometryPropertyType';
+					//$fldType = 'gml:Polygon';// nie działa musi być gml:GeometryPropertyType
+				}
+				else {
+					$fldType = 'xsd:string';
+				}
+				$elNode->setAttribute('type', $fldType);
+				$elNode->setAttribute('nillable', 'true');
+			}
+
+			$elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
+			$rootNode->appendChild($elNode);
+			$elNode->setAttribute('name', $type);
+			$elNode->setAttribute('type', $wfsNs . ':' . $typeName);
+		}
+
+		echo $dom->saveXML();
+	}
+
 }