|
@@ -31,62 +31,20 @@ class Api_WfsDataServer extends Api_WfsServerBase {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function getFeatureAction() {
|
|
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 = '';
|
|
|
|
|
- $ogcFilter = V::get('FILTER', $ogcFilter, $_REQUEST);
|
|
|
|
|
- $ogcFilter = V::get('Filter', $ogcFilter, $_REQUEST);
|
|
|
|
|
- $ogcFilter = urldecode($ogcFilter);
|
|
|
|
|
- $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) throw new HttpException("Wrong param TYPENAME", 400);
|
|
|
|
|
- if (empty($ogcFilter)) {// read ogc:Filter from POST body if not defined in GET
|
|
|
|
|
- $reqBody = Request::getRequestBody();
|
|
|
|
|
- if (!empty($reqBody)) {
|
|
|
|
|
- $ogcFilter = $this->convertOgcFilterFromRequestBody($reqBody);
|
|
|
|
|
- if (empty($ogcFilter)) throw new Api_WfsException("Error Processing ogc:Filter", 501);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if ('hits' == V::get('resultType', '', $_REQUEST)) {// resultType=hits
|
|
|
|
|
- return $this->getTotalFeatures($typeEx[0], $typeEx[1], $maxFeatures, $srsname, $ogcFilter, $sortBy, $startIndex, $propertyName, $simple = true);
|
|
|
|
|
|
|
+ $args = $this->parseGetFeatureArgsFromRequest();
|
|
|
|
|
+ if ('hits' == $args['resultType']) {
|
|
|
|
|
+ return $this->getTotalFeatures($args, $simple = true);
|
|
|
} else {
|
|
} else {
|
|
|
- return $this->getFeatures($typeEx[0], $typeEx[1], $maxFeatures, $srsname, $ogcFilter, $sortBy, $startIndex, $propertyName, $simple = true);
|
|
|
|
|
|
|
+ return $this->getFeatures($args, $simple = true);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function getFeatureAdvancedAction() {
|
|
public function getFeatureAdvancedAction() {
|
|
|
- $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 = '';
|
|
|
|
|
- $ogcFilter = V::get('FILTER', $ogcFilter, $_REQUEST);
|
|
|
|
|
- $ogcFilter = V::get('Filter', $ogcFilter, $_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) throw new HttpException("Wrong param TYPENAME", 400);
|
|
|
|
|
- if (empty($ogcFilter)) {// read ogc:Filter from POST body if not defined in GET
|
|
|
|
|
- $reqBody = Request::getRequestBody();
|
|
|
|
|
- if (!empty($reqBody)) {
|
|
|
|
|
- $ogcFilter = $this->convertOgcFilterFromRequestBody($reqBody);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if ('hits' == V::get('resultType', '', $_REQUEST)) {// resultType=hits
|
|
|
|
|
- return $this->getTotalFeatures($typeEx[0], $typeEx[1], $maxFeatures, $srsname, $ogcFilter, $sortBy, $startIndex, $propertyName, $simple = false);
|
|
|
|
|
|
|
+ $args = $this->parseGetFeatureArgsFromRequest();
|
|
|
|
|
+ if ('hits' == $args['resultType']) {
|
|
|
|
|
+ return $this->getTotalFeatures($args, $simple = false);
|
|
|
} else {
|
|
} else {
|
|
|
- return $this->getFeatures($typeEx[0], $typeEx[1], $maxFeatures, $srsname, $ogcFilter, $sortBy, $startIndex, $propertyName, $simple = false);
|
|
|
|
|
|
|
+ return $this->getFeatures($args, $simple = false);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -107,20 +65,18 @@ class Api_WfsDataServer extends Api_WfsServerBase {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function getTotalFeatures($nsPrefix, $type, $maxFeatures, $srsname, $ogcFilter = '', $sortBy = '', $startIndex = 0, $propertyName = '', $simple = true) {
|
|
|
|
|
|
|
+ public function getTotalFeatures($args, $simple = true) {
|
|
|
$DBG = (V::get('DBG_GEO', '', $_GET) > 0);// TODO: Profiler
|
|
$DBG = (V::get('DBG_GEO', '', $_GET) > 0);// TODO: Profiler
|
|
|
- $typeName = "{$nsPrefix}:{$type}";
|
|
|
|
|
- if($DBG){echo "typeName($typeName})\n";}
|
|
|
|
|
- $acl = $this->getAclFromTypeName($typeName);
|
|
|
|
|
|
|
+ if($DBG){echo "typeName({$args['xsd:type']})\n";}
|
|
|
|
|
+ $acl = $this->getAclFromTypeName($args['xsd:type']);
|
|
|
$fldList = $this->_getFieldListFromAcl($acl);
|
|
$fldList = $this->_getFieldListFromAcl($acl);
|
|
|
|
|
|
|
|
$baseNsUri = Api_WfsNs::getBaseWfsUri();
|
|
$baseNsUri = Api_WfsNs::getBaseWfsUri();
|
|
|
$rootWfsNs = 'p5';
|
|
$rootWfsNs = 'p5';
|
|
|
$rootWfsNsUri = "{$baseNsUri}";
|
|
$rootWfsNsUri = "{$baseNsUri}";
|
|
|
- //$wfsNs = 'p5_default_db_' . $type;//$nsPrefix;
|
|
|
|
|
- $wfsNs = $nsPrefix;//'p5_default_db';
|
|
|
|
|
- $wfsNsUri = "{$baseNsUri}/" . substr($nsPrefix, 3);
|
|
|
|
|
- $featureTypeUri = $this->getBaseUri() . "?SERVICE=WFS&VERSION=1.0.0&TYPENAME={$typeName}&REQUEST=DescribeFeatureType";
|
|
|
|
|
|
|
+ $wfsNs = $args['typePrefix'];
|
|
|
|
|
+ $wfsNsUri = "{$baseNsUri}/" . substr($args['typePrefix'], 3);
|
|
|
|
|
+ $featureTypeUri = $this->getBaseUri() . "?SERVICE=WFS&VERSION=1.0.0&TYPENAME={$args['xsd:type']}&REQUEST=DescribeFeatureType";
|
|
|
|
|
|
|
|
// get BBox from geom_field (only one geom fld is allowed)
|
|
// get BBox from geom_field (only one geom fld is allowed)
|
|
|
$geomFld = null;
|
|
$geomFld = null;
|
|
@@ -132,37 +88,20 @@ class Api_WfsDataServer extends Api_WfsServerBase {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if($DBG){echo "ogcFilter(" . strlen($ogcFilter) . "): {$ogcFilter}\n";}
|
|
|
|
|
|
|
+ if($DBG){echo "ogcFilter(" . strlen($args['ogc:Filter']) . "): {$args['ogc:Filter']}\n";}
|
|
|
$searchParams = array();
|
|
$searchParams = array();
|
|
|
- $searchParams['limit'] = $maxFeatures;
|
|
|
|
|
- $searchParams['limitstart'] = $startIndex;
|
|
|
|
|
- if (!empty($sortBy)) {
|
|
|
|
|
- $searchParams['sortBy'] = $sortBy;
|
|
|
|
|
|
|
+ $searchParams['limit'] = $args['limit'];
|
|
|
|
|
+ $searchParams['limitstart'] = $args['offset'];
|
|
|
|
|
+ if (!empty($args['sortBy'])) {
|
|
|
|
|
+ $searchParams['sortBy'] = $args['sortBy'];
|
|
|
} else {
|
|
} else {
|
|
|
$searchParams['order_by'] = $acl->getPrimaryKeyField();
|
|
$searchParams['order_by'] = $acl->getPrimaryKeyField();
|
|
|
$searchParams['order_dir'] = 'DESC';
|
|
$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;
|
|
|
|
|
- }
|
|
|
|
|
- {// BBOX
|
|
|
|
|
- // 54.26931096743426,18.48242909824306,54.26738118403914,18.478738378639246
|
|
|
|
|
- $bbox = V::get('BBOX', '', $_GET);
|
|
|
|
|
- if (!empty($bbox)) {
|
|
|
|
|
- if (preg_match("/^\d+(.\d+)?,\d+(.\d+)?,\d+(.\d+)?,\d+(.\d+)?$/", $bbox, $matches)) {
|
|
|
|
|
- $searchParams['f_the_geom'] = "BBOX:{$bbox}";
|
|
|
|
|
- } else {
|
|
|
|
|
- // throw new Exception("Error Processing Request", 1);// ?
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (strlen($args['ogc:Filter']) > 0) $searchParams['ogc:Filter'] = $args['ogc:Filter'];
|
|
|
|
|
+ if (!empty($args['filterFields'])) $searchParams['cols'] = $args['filterFields'];// propertyName
|
|
|
|
|
+ if (!empty($args['primaryKey'])) $searchParams['primaryKey'] = $args['primaryKey'];// featureID
|
|
|
|
|
+ if (!empty($args['bbox'])) $searchParams['f_the_geom'] = "BBOX:{$args['bbox']}";
|
|
|
if($DBG){echo 'getItems() searchParams:';print_r($searchParams);echo "\n";}
|
|
if($DBG){echo 'getItems() searchParams:';print_r($searchParams);echo "\n";}
|
|
|
$totalItems = $acl->getTotal($searchParams);
|
|
$totalItems = $acl->getTotal($searchParams);
|
|
|
if($DBG){echo 'totalItems:';print_r($totalItems);echo "\n";}
|
|
if($DBG){echo 'totalItems:';print_r($totalItems);echo "\n";}
|
|
@@ -186,21 +125,20 @@ class Api_WfsDataServer extends Api_WfsServerBase {
|
|
|
exit;
|
|
exit;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function getFeatures($nsPrefix, $type, $maxFeatures, $srsname, $ogcFilter = '', $sortBy = '', $startIndex = 0, $propertyName = '', $simple = true) {
|
|
|
|
|
|
|
+ public function getFeatures($args, $simple = true) {
|
|
|
$DBG = (V::get('DBG_GEO', '', $_GET) > 0);// TODO: Profiler
|
|
$DBG = (V::get('DBG_GEO', '', $_GET) > 0);// TODO: Profiler
|
|
|
$DBG_DS = V::get('DBG_DS', 0, $_GET, 'int');
|
|
$DBG_DS = V::get('DBG_DS', 0, $_GET, 'int');
|
|
|
- $typeName = "{$nsPrefix}:{$type}";
|
|
|
|
|
- if($DBG){echo "typeName($typeName})\n";}
|
|
|
|
|
- $acl = $this->getAclFromTypeName($typeName);
|
|
|
|
|
|
|
+ $type = $args['typeName'];
|
|
|
|
|
+ if($DBG){echo "typeName({$args['xsd:type']})\n";}
|
|
|
|
|
+ $acl = $this->getAclFromTypeName($args['xsd:type']);
|
|
|
$fldList = $this->_getFieldListFromAcl($acl);
|
|
$fldList = $this->_getFieldListFromAcl($acl);
|
|
|
|
|
|
|
|
$baseNsUri = Api_WfsNs::getBaseWfsUri();
|
|
$baseNsUri = Api_WfsNs::getBaseWfsUri();
|
|
|
$rootWfsNs = 'p5';
|
|
$rootWfsNs = 'p5';
|
|
|
$rootWfsNsUri = "{$baseNsUri}";
|
|
$rootWfsNsUri = "{$baseNsUri}";
|
|
|
- //$wfsNs = 'p5_default_db_' . $type;//$nsPrefix;
|
|
|
|
|
- $wfsNs = $nsPrefix;//'p5_default_db';
|
|
|
|
|
- $wfsNsUri = "{$baseNsUri}/" . substr($nsPrefix, 3);
|
|
|
|
|
- $featureTypeUri = $this->getBaseUri() . "?SERVICE=WFS&VERSION=1.0.0&TYPENAME={$typeName}&REQUEST=DescribeFeatureType";
|
|
|
|
|
|
|
+ $wfsNs = $args['typePrefix'];
|
|
|
|
|
+ $wfsNsUri = "{$baseNsUri}/" . substr($args['typePrefix'], 3);
|
|
|
|
|
+ $featureTypeUri = $this->getBaseUri() . "?SERVICE=WFS&VERSION=1.0.0&TYPENAME={$args['xsd:type']}&REQUEST=DescribeFeatureType";
|
|
|
|
|
|
|
|
// get BBox from geom_field (only one geom fld is allowed)
|
|
// get BBox from geom_field (only one geom fld is allowed)
|
|
|
$geomFld = null;
|
|
$geomFld = null;
|
|
@@ -212,38 +150,21 @@ class Api_WfsDataServer extends Api_WfsServerBase {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-if($DBG){echo "ogcFilter(" . strlen($ogcFilter) . "): {$ogcFilter}\n";}
|
|
|
|
|
|
|
+ if($DBG){echo "ogcFilter(" . strlen($args['ogc:Filter']) . "): {$args['ogc:Filter']}\n";}
|
|
|
$searchParams = array();
|
|
$searchParams = array();
|
|
|
- $searchParams['limit'] = $maxFeatures;
|
|
|
|
|
- $searchParams['limitstart'] = $startIndex;
|
|
|
|
|
- if (!empty($sortBy)) {
|
|
|
|
|
- $searchParams['sortBy'] = $sortBy;
|
|
|
|
|
|
|
+ $searchParams['limit'] = $args['limit'];
|
|
|
|
|
+ $searchParams['limitstart'] = $args['offset'];
|
|
|
|
|
+ if (!empty($args['sortBy'])) {
|
|
|
|
|
+ $searchParams['sortBy'] = $args['sortBy'];
|
|
|
} else {
|
|
} else {
|
|
|
$searchParams['order_by'] = $acl->getPrimaryKeyField();
|
|
$searchParams['order_by'] = $acl->getPrimaryKeyField();
|
|
|
$searchParams['order_dir'] = 'DESC';
|
|
$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;
|
|
|
|
|
- }
|
|
|
|
|
- {// BBOX
|
|
|
|
|
- // 54.26931096743426,18.48242909824306,54.26738118403914,18.478738378639246
|
|
|
|
|
- $bbox = V::get('BBOX', '', $_GET);
|
|
|
|
|
- if (!empty($bbox)) {
|
|
|
|
|
- if (preg_match("/^\d+(.\d+)?,\d+(.\d+)?,\d+(.\d+)?,\d+(.\d+)?$/", $bbox, $matches)) {
|
|
|
|
|
- $searchParams['f_the_geom'] = "BBOX:{$bbox}";
|
|
|
|
|
- } else {
|
|
|
|
|
- // throw new Exception("Error Processing Request", 1);// ?
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-if($DBG){echo 'getItems:';print_r($searchParams);echo "\n";}
|
|
|
|
|
|
|
+ if (strlen($args['ogc:Filter']) > 0) $searchParams['ogc:Filter'] = $args['ogc:Filter'];
|
|
|
|
|
+ if (!empty($args['filterFields'])) $searchParams['cols'] = $args['filterFields'];// PropertyName
|
|
|
|
|
+ if (!empty($args['primaryKey'])) $searchParams['primaryKey'] = $args['primaryKey'];// featureID
|
|
|
|
|
+ if (!empty($args['bbox'])) $searchParams['f_the_geom'] = "BBOX:{$args['bbox']}";
|
|
|
|
|
+ if($DBG){echo 'getItems:';print_r($searchParams);echo "\n";}
|
|
|
$items = $acl->getItems($searchParams);
|
|
$items = $acl->getItems($searchParams);
|
|
|
|
|
|
|
|
$dom = new DOMDocument('1.0', 'utf-8');
|
|
$dom = new DOMDocument('1.0', 'utf-8');
|
|
@@ -261,7 +182,7 @@ if($DBG){echo 'getItems:';print_r($searchParams);echo "\n";}
|
|
|
//$rootNode->setAttribute('xsi:schemaLocation', 'http://www.opengis.net/wfs');
|
|
//$rootNode->setAttribute('xsi:schemaLocation', 'http://www.opengis.net/wfs');
|
|
|
$rootNode->setAttribute('xsi:schemaLocation', "{$wfsNsUri} {$featureTypeUri}");
|
|
$rootNode->setAttribute('xsi:schemaLocation', "{$wfsNsUri} {$featureTypeUri}");
|
|
|
|
|
|
|
|
-if($DBG){echo '(geomFld: '.$geomFld.'):';print_r($acl->getFieldType($geomFld));echo "\n";}
|
|
|
|
|
|
|
+ if($DBG){echo '(geomFld: '.$geomFld.'):';print_r($acl->getFieldType($geomFld));echo "\n";}
|
|
|
if (empty($items)) {
|
|
if (empty($items)) {
|
|
|
$pKeyField = $acl->getPrimaryKeyField();
|
|
$pKeyField = $acl->getPrimaryKeyField();
|
|
|
$fakeItem = new stdClass();
|
|
$fakeItem = new stdClass();
|
|
@@ -273,7 +194,7 @@ if($DBG){echo '(geomFld: '.$geomFld.'):';print_r($acl->getFieldType($geomFld));e
|
|
|
foreach ($items as $itemKey => $item) {
|
|
foreach ($items as $itemKey => $item) {
|
|
|
if (!is_array($item)) $item = (array)$item;
|
|
if (!is_array($item)) $item = (array)$item;
|
|
|
|
|
|
|
|
-if($DBG && !empty($geomFld)){echo 'item['.$itemKey.'] ('.$geomFld.')isEmpty('.empty($item[$geomFld]).'):';print_r($item[$geomFld]);echo "\n";}
|
|
|
|
|
|
|
+ if($DBG && !empty($geomFld)){echo 'item['.$itemKey.'] ('.$geomFld.')isEmpty('.empty($item[$geomFld]).'):';print_r($item[$geomFld]);echo "\n";}
|
|
|
if($DBG_DS){echo ">>> loop({$itemKey}) item: ";print_r($item);echo "\n";}
|
|
if($DBG_DS){echo ">>> loop({$itemKey}) item: ";print_r($item);echo "\n";}
|
|
|
|
|
|
|
|
$featureMemberNode = $dom->createElementNS('http://www.opengis.net/gml', 'gml:featureMember');
|
|
$featureMemberNode = $dom->createElementNS('http://www.opengis.net/gml', 'gml:featureMember');
|