|
|
@@ -46,11 +46,8 @@ class Api_WfsQgisServer extends Api_WfsServerBase {
|
|
|
$typeEx = explode(':', $type);
|
|
|
$maxFeatures = V::get('MAXFEATURES', '10000', $_REQUEST, 'int');// TODO: Set Deafult Limit
|
|
|
$srsname = V::get('SRSNAME', '', $_REQUEST);// eg. EPSG:4326
|
|
|
- if (count($typeEx) == 2) {
|
|
|
- return $this->getFeatures($typeEx[0], $typeEx[1], $maxFeatures, $srsname);
|
|
|
- } else {
|
|
|
- throw new HttpException("Wrong param TYPENAME", 400);
|
|
|
- }
|
|
|
+ if (count($typeEx) != 2) throw new HttpException("Wrong param TYPENAME", 400);
|
|
|
+ return $this->getFeatures($typeEx[0], $typeEx[1], $maxFeatures, $srsname);
|
|
|
}
|
|
|
|
|
|
public function getFeatures($nsPrefix, $type, $maxFeatures, $srsname) {
|
|
|
@@ -83,11 +80,102 @@ class Api_WfsQgisServer extends Api_WfsServerBase {
|
|
|
$searchParams['limit'] = $maxFeatures;
|
|
|
$searchParams['order_by'] = $acl->getPrimaryKeyField();
|
|
|
$searchParams['order_dir'] = 'DESC';
|
|
|
- if ($geomFld) $searchParams["f_{$geomFld}"] = 'IS NOT NULL';
|
|
|
- if ($geomFld) $searchParams["f_{$geomFld}"] = 'GeometryType=' . strtoupper($dbGeomType);
|
|
|
- //if ($geomFld) $searchParams["f_{$geomFld}"] = 'GeometryType=LINESTRING';
|
|
|
+ //if ($geomFld) $searchParams["f_{$geomFld}"] = 'IS NOT NULL';
|
|
|
+ //if ($geomFld) $searchParams["f_{$geomFld}"] = 'GeometryType=' . strtoupper($dbGeomType);
|
|
|
+ $geomType = strtoupper($dbGeomType);
|
|
|
+ if ($geomFld) $searchParams["ogc:Filter"] = <<<OGC_FILTER
|
|
|
+<ogc:Filter>
|
|
|
+ <ogc:Or>
|
|
|
+ <ogc:Not>
|
|
|
+ <ogc:PropertyIsNull>
|
|
|
+ <ogc:PropertyName>{$geomFld}</ogc:PropertyName>
|
|
|
+ </ogc:PropertyIsNull>
|
|
|
+ </ogc:Not>
|
|
|
+ <ogc:PropertyIsEqualTo>
|
|
|
+ <ogc:Function name="GeometryType">
|
|
|
+ <ogc:PropertyName>{$geomFld}</ogc:PropertyName>
|
|
|
+ </ogc:Function>
|
|
|
+ <ogc:Literal>{$geomType}</ogc:Literal>
|
|
|
+ </ogc:PropertyIsEqualTo>
|
|
|
+ </ogc:Or>
|
|
|
+</ogc:Filter>
|
|
|
+OGC_FILTER;
|
|
|
if($DBG){echo 'getItems:';print_r($searchParams);echo "\n";}
|
|
|
+ $this->DBG("getItems:" . json_encode($searchParams), __LINE__, __FUNCTION__, __CLASS__);
|
|
|
$items = $acl->getItems($searchParams);
|
|
|
+ $this->DBG("items(" . count($items) . ")", __LINE__, __FUNCTION__, __CLASS__);
|
|
|
+
|
|
|
+if (true) {//1 == V::get('XML_WRITER', 0, $_GET, 'int')) {
|
|
|
+ header('Content-type: application/xml; charset=utf-8');
|
|
|
+ $xmlWriter = new XMLWriter();
|
|
|
+ $xmlWriter->openUri('php://output');
|
|
|
+ $xmlWriter->setIndent(true);
|
|
|
+ if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
|
|
|
+ $xmlWriter->startDocument('1.0','UTF-8');
|
|
|
+ //$xmlWriter->startElementNS('wfs', 'FeatureCollection', 'http://www.opengis.net/wfs');
|
|
|
+ $xmlWriter->startElement('wfs:FeatureCollection');
|
|
|
+// $xmlWriter->writeAttributeNS('xmlns', 'wfs', 'http://www.w3.org/2000/xmlns/', 'http://www.opengis.net/wfs');
|
|
|
+ $xmlWriter->writeAttribute('xmlns:wfs', 'http://www.opengis.net/wfs');
|
|
|
+ $xmlWriter->writeAttribute('xmlns', 'http://www.opengis.net/wfs');
|
|
|
+// $xmlWriter->writeAttributeNS('xmlns', 'gml', 'http://www.w3.org/2000/xmlns/', 'http://www.opengis.net/gml');
|
|
|
+// $xmlWriter->writeAttributeNS('xmlns', 'xsi', 'http://www.w3.org/2000/xmlns/', 'http://www.w3.org/2001/XMLSchema-instance');
|
|
|
+// $xmlWriter->writeAttributeNS('xmlns', $wfsNs, 'http://www.w3.org/2000/xmlns/', $wfsNsUri);
|
|
|
+ $xmlWriter->writeAttribute('xmlns:gml', 'http://www.opengis.net/gml');
|
|
|
+ $xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
|
|
|
+ $xmlWriter->writeAttribute("xmlns:{$wfsNs}", $wfsNsUri);
|
|
|
+ $xmlWriter->writeAttribute('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;
|
|
|
+ if ('polygon' == $dbGeomType) {
|
|
|
+ $fakeItem->the_geom = "POLYGON(())";
|
|
|
+ } else if ('linestring' == $dbGeomType) {
|
|
|
+ $fakeItem->the_geom = "LINESTRING()";
|
|
|
+ } else if ('point' == $dbGeomType) {
|
|
|
+ $fakeItem->the_geom = "POINT(0,0)";
|
|
|
+ }
|
|
|
+ $items[0] = $fakeItem;
|
|
|
+ }
|
|
|
+ $dbgLoop = 0;
|
|
|
+ foreach ($items as $itemKey => $item) {
|
|
|
+ if (0 == (++$dbgLoop) % 1000) $this->DBG("items loop:{$dbgLoop}", __LINE__, __FUNCTION__, __CLASS__);
|
|
|
+if($DBG){echo 'item['.$itemKey.'] ('.$geomFld.')isEmpty('.empty($item->{$geomFld}).'):';print_r($item->{$geomFld});echo "\n";}
|
|
|
+ if ($geomFld) {
|
|
|
+ if (empty($item->{$geomFld})) {
|
|
|
+ continue;// QGIS crash when WFS contain features with empty geom field
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $xmlWriter->startElement('gml:featureMember');
|
|
|
+ $xmlWriter->startElement("{$wfsNs}:{$type}");
|
|
|
+ $xmlWriter->writeAttribute('fid', "{$type}.{$itemKey}");
|
|
|
+ foreach ($fldList as $fldName) {
|
|
|
+ if ($acl->isGeomField($fldName)) {
|
|
|
+ $xmlWriter->startElement("{$wfsNs}:{$fldName}");
|
|
|
+ $this->_typeConverter->createGmlFromWkt_xmlWriter($item->{$fldName}, $xmlWriter);
|
|
|
+ $xmlWriter->endElement();// {$wfsNs}:{$fldName}
|
|
|
+ } else {
|
|
|
+ $value = str_replace('&', '&', $item->{$fldName});
|
|
|
+ if (empty($value) && '0' !== $value) {
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ $xmlWriter->startElement("{$wfsNs}:{$fldName}");
|
|
|
+ $xmlWriter->text($value);
|
|
|
+ $xmlWriter->endElement();// {$wfsNs}:{$fldName}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $xmlWriter->endElement();// {$wfsNs}:{$type}
|
|
|
+ $xmlWriter->endElement();// gml:featureMember
|
|
|
+ }
|
|
|
+ $xmlWriter->endElement();// wfs:FeatureCollection
|
|
|
+ $xmlWriter->endDocument();
|
|
|
+ $this->DBG("items loop END", __LINE__, __FUNCTION__, __CLASS__);
|
|
|
+ //'<!-- .EOF -->';
|
|
|
+ exit;
|
|
|
+}
|
|
|
|
|
|
$dom = new DOMDocument('1.0', 'utf-8');
|
|
|
$dom->formatOutput = true;
|
|
|
@@ -130,8 +218,9 @@ if($DBG){echo '(geomFld: '.$geomFld.'):';print_r($acl->getFieldType($geomFld));e
|
|
|
}
|
|
|
$items[0] = $fakeItem;
|
|
|
}
|
|
|
+ $dbgLoop = 0;
|
|
|
foreach ($items as $itemKey => $item) {
|
|
|
-
|
|
|
+ $dbgLoop++; if (0 == $dbgLoop % 100) $this->DBG("items loop:{$dbgLoop}", __LINE__, __FUNCTION__, __CLASS__);
|
|
|
if($DBG){echo 'item['.$itemKey.'] ('.$geomFld.')isEmpty('.empty($item->{$geomFld}).'):';print_r($item->{$geomFld});echo "\n";}
|
|
|
if ($geomFld) {
|
|
|
if (empty($item->{$geomFld})) {
|
|
|
@@ -173,6 +262,7 @@ if(0){// TODO: get BBOX
|
|
|
$featureNode->appendChild($featureFldNode);
|
|
|
}
|
|
|
}
|
|
|
+ $this->DBG("items loop END", __LINE__, __FUNCTION__, __CLASS__);
|
|
|
|
|
|
return $dom->saveXml();
|
|
|
}
|