_parseTransactionXmlStruct($reqContent, $tags); } throw new Api_WfsException("TODO ... L." . __LINE__, 501); $xml = new SimpleXMLElement($reqContent); $namespaces = $xml->getNameSpaces(true); if ('Transaction' == $xml->getName()) { $this->_parseTransactionXml($xml); } else { throw new Api_WfsException("Not Implemented " . htmlspecialchars($xml->getName()), 501); } } public function getFeatureAction() { $type = V::get('TYPENAME', '', $_REQUEST); $typeEx = explode(':', $type); $maxFeatures = '10000';// TODO: Set Deafult Limit $maxFeatures = V::get('MAXFEATURES', $maxFeatures, $_REQUEST, 'int'); $maxFeatures = V::get('maxFeatures', $maxFeatures, $_REQUEST, 'int'); $maxFeatures = V::get('count', $maxFeatures, $_REQUEST, 'int'); $startIndex = V::get('startIndex', 0, $_REQUEST, 'int');// sql offset $ogcFilter = V::get('Filter', '', $_REQUEST); $sortBy = V::get('sortBy', '', $_REQUEST); $propertyName = V::get('propertyName', '', $_REQUEST); $propertyName = trim($propertyName); $srsname = V::get('SRSNAME', '', $_REQUEST);// eg. EPSG:4326 if (count($typeEx) == 2) { if (empty($ogcFilter)) {// read ogc:Filter from POST body if not defined in GET $reqBody = Request::getRequestBody(); if (!empty($reqBody)) { $ogcFilter = $this->convertOgcFilterFromRequestBody($reqBody); } } return $this->getFeatures($typeEx[0], $typeEx[1], $maxFeatures, $srsname, $ogcFilter, $sortBy, $startIndex, $propertyName); } else { throw new HttpException("Wrong param TYPENAME", 400); } } public function testOgcFilterAction() { $type = V::get('TYPENAME', '', $_REQUEST); $typeEx = explode(':', $type); $maxFeatures = V::get('MAXFEATURES', '10000', $_REQUEST, 'int');// TODO: Set Deafult Limit $ogcFilter = V::get('Filter', '', $_REQUEST); $srsname = V::get('SRSNAME', '', $_REQUEST);// eg. EPSG:4326 if (count($typeEx) == 2) { Lib::loadClass('ParseOgcFilter'); $parser = new ParseOgcFilter(); $parser->loadOgcFilter($ogcFilter); $queryWhereBuilder = $parser->convertToSqlQueryWhereBuilder(); echo $queryWhereBuilder->getQueryWhere('t'); } else { throw new HttpException("Wrong param TYPENAME", 400); } } public function getFeatures($nsPrefix, $type, $maxFeatures, $srsname, $ogcFilter = '', $sortBy = '', $startIndex = 0, $propertyName = '') { $DBG = (V::get('DBG_GEO', '', $_GET) > 0);// TODO: Profiler $typeName = "{$nsPrefix}:{$type}"; $acl = $this->getAclFromTypeName($typeName); $fldList = $this->_getFieldListFromAcl($acl); $baseNsUri = $this->getBaseNamespaceUri(); //$wfsNs = 'p5_default_db_' . $type;//$nsPrefix; $wfsNs = 'p5_default_db';//$nsPrefix; $wfsNsUri = "{$baseNsUri}/" . substr($nsPrefix, 3); $featureTypeUri = $this->getBaseUri() . "?SERVICE=WFS&VERSION=1.0.0&TYPENAME={$typeName}&REQUEST=DescribeFeatureType"; // get BBox from geom_field (only one geom fld is allowed) $geomFld = null; { foreach ($fldList as $fldName) { if ($acl->isGeomField($fldName)) { $geomFld = $fldName; } } } if($DBG){echo "ogcFilter(" . strlen($ogcFilter) . "): {$ogcFilter}\n";} $searchParams = array(); $searchParams['limit'] = $maxFeatures; $searchParams['limitstart'] = $startIndex; if (!empty($sortBy)) { $searchParams['sortBy'] = $sortBy; } else { $searchParams['order_by'] = $acl->getPrimaryKeyField(); $searchParams['order_dir'] = 'DESC'; } if (strlen($ogcFilter) > 0) $searchParams['ogc:Filter'] = $ogcFilter; if (strlen($propertyName) > 0) { $propertyNamesEx = explode(',', $propertyName); $onlyCols = array(); foreach ($propertyNamesEx as $colName) { $colName = trim($colName); $onlyCols[] = $colName; } if (!empty($onlyCols)) $searchParams['cols'] = $onlyCols; } if($DBG){echo 'getItems:';print_r($searchParams);echo "\n";} $items = $acl->getItems($searchParams); $dom = new DOMDocument('1.0', 'utf-8'); $dom->formatOutput = true; $dom->preserveWhiteSpace = false; $rootNode = $dom->createElementNS('http://www.opengis.net/wfs', 'wfs:FeatureCollection'); $dom->appendChild($rootNode); $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', 'http://www.opengis.net/wfs'); $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:wfs', 'http://www.opengis.net/wfs'); $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml'); $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $wfsNs, $wfsNsUri); //$rootNode->setAttribute('xsi:schemaLocation', 'http://www.opengis.net/wfs'); $rootNode->setAttribute('xsi:schemaLocation', "{$wfsNsUri} {$featureTypeUri}"); if($DBG){echo '(geomFld: '.$geomFld.'):';print_r($acl->getFieldType($geomFld));echo "\n";} if (empty($items)) { $pKeyField = $acl->getPrimaryKeyField(); $fakeItem = new stdClass(); $fakeItem->{$pKeyField} = 0; $items[0] = $fakeItem; } foreach ($items as $itemKey => $item) { if($DBG){echo 'item['.$itemKey.'] ('.$geomFld.')isEmpty('.empty($item->{$geomFld}).'):';print_r($item->{$geomFld});echo "\n";} $featureMemberNode = $dom->createElementNS('http://www.opengis.net/gml', 'gml:featureMember'); $rootNode->appendChild($featureMemberNode); $featureNode = $dom->createElementNS($wfsNsUri, "{$wfsNs}:{$type}"); $featureMemberNode->appendChild($featureNode); $featureNode->setAttribute('fid', "{$type}.{$itemKey}"); foreach ($fldList as $fldName) { $featureFldNode = $dom->createElementNS($wfsNsUri, "{$wfsNs}:{$fldName}"); if ($acl->isGeomField($fldName)) { $geomNode = $this->_typeConverter->createGmlFromWkt($item->{$fldName}, $dom); if (!$geomNode) continue; $featureFldNode->appendChild($geomNode); } else { $featureFldNode->nodeValue = str_replace('&', '&', $item->{$fldName}); if (empty($featureFldNode->nodeValue) && '0' !== $featureFldNode->nodeValue) { continue; } } $featureNode->appendChild($featureFldNode); } } return $dom->saveXml(); } public function describeFeatureTypeAction() { $type = V::get('TYPENAME', '', $_REQUEST); if (empty($type)) { $reqContent = Request::getRequestBody(); if (!empty($reqContent)) { return $this->_parseDescribeFeatureTypeRequest($reqContent); } else { return $this->_getDescribeFeatureAllTypes(); } //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 describeFeatureTypeAdvancedAction() { $type = V::get('TYPENAME', '', $_REQUEST); if (empty($type)) { $reqContent = Request::getRequestBody(); if (!empty($reqContent)) { return $this->_parseDescribeFeatureTypeRequest($reqContent, $simple = false); } else { return $this->_getDescribeFeatureAllTypes($simple = false); } //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], $simple = false); } public function getCapabilitiesAction() { $wfsServerUrl = $this->getBaseUri(); $serviceTitle = "Web Feature Service"; $serviceDescription = "This is the reference implementation of WFS 1.0.0 and WFS 1.1.0, supports all WFS operations including Transaction."; //header('Content-type: application/xml; charset="utf-8"'); header('Content-type: application/xml'); $this->_getCapabilities($wfsServerUrl, $serviceTitle, $serviceDescription); } }