[Mapbender-commits] r8244 - trunk/mapbender/http/geoportal

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Feb 13 11:16:37 EST 2012


Author: armin11
Date: 2012-02-13 08:16:37 -0800 (Mon, 13 Feb 2012)
New Revision: 8244

Modified:
   trunk/mapbender/http/geoportal/gaz.php
   trunk/mapbender/http/geoportal/mod_readCSWResults.php
Log:
Allow spatial search for CSW 2.0.2 - BBOX, Within, Disjoint

Modified: trunk/mapbender/http/geoportal/gaz.php
===================================================================
--- trunk/mapbender/http/geoportal/gaz.php	2012-02-13 08:00:28 UTC (rev 8243)
+++ trunk/mapbender/http/geoportal/gaz.php	2012-02-13 16:16:37 UTC (rev 8244)
@@ -59,7 +59,7 @@
 
 $searchTextOS = str_replace(",","+",$searchText);
 if ($searchTextOS ==='false' || $searchTextOS ==='*'){
-	$searchTextOS = '1';
+	$searchTextOS = '*';
 }
 
 $openSearchFilter = "";
@@ -92,12 +92,12 @@
         $openSearchFilter .= "+y2:".$spatialFilterCoords[3];
 }
 if (isset($searchTypeBbox) & ($searchTypeBbox != 'false')){
-	#if ($searchTypeBbox == 'intersects') {
-	#	$openSearchFilter .= "+coord:intersect";
-	#}
-	#if ($searchTypeBbox == 'outside') {
-	#	$openSearchFilter .= "+coord:include";
-	#}
+	if ($searchTypeBbox == 'intersects') {
+		$openSearchFilter .= "+coord:intersect";
+	}
+	if ($searchTypeBbox == 'outside') {
+		$openSearchFilter .= "+coord:outside";
+	}
 	if ($searchTypeBbox == 'inside') {
 		$openSearchFilter .= "+coord:inside";
 	}
@@ -116,7 +116,7 @@
 }
 //apply filter
 //following part is only set if the portalu opensearch is used!
-//$searchTextOS .= $openSearchFilter;
+$searchTextOS .= $openSearchFilter;
 
 
 // check if some extended is requested - in the old version this is defined by one parameter. The new interface would not distinguish between this two kind of search cases. Every search is a also an extented search. See mod_callMetadata.php

Modified: trunk/mapbender/http/geoportal/mod_readCSWResults.php
===================================================================
--- trunk/mapbender/http/geoportal/mod_readCSWResults.php	2012-02-13 08:00:28 UTC (rev 8243)
+++ trunk/mapbender/http/geoportal/mod_readCSWResults.php	2012-02-13 16:16:37 UTC (rev 8244)
@@ -99,10 +99,102 @@
 
 //convert the the opensearch filter to ogc filter encoding
 
+//extract query string - explode by +
+$queryString  = $_REQUEST["q"];
+$queryStringParts = explode("+",$queryString);
+//extract single elements into variables
+//first entry is allways the query string for any text
+$queryText = $queryStringParts[0];
 
+//extract the other elements
+for ($i=1;$i < count($queryStringParts);$i++) {
+	//check the elements
+	$queryParam = explode(":",$queryStringParts[$i]);
+	switch ($queryParam[0]) {
+		case "x1":
+			$x1 = $queryParam[1];
+		break;
+		case "x2":
+			$x2 = $queryParam[1];
+		break;	
+		case "y1":
+			$y1 = $queryParam[1];
+		break;	
+		case "y2":
+			$y2 = $queryParam[1];
+		break;
+		case "coord":
+			$coord = $queryParam[1];
+		break;
+		case "ranking":
+			$ranking = $queryParam[1];
+		break;	
+	}	
+}
+//build bbox if all infos are given
+$e = new mb_exception("q= : ".$_REQUEST["q"]);
+$e = new mb_notice("ranking: ".$ranking);
+$e = new mb_notice("coord: ".$coord);
+$e = new mb_exception("queryText: ".$queryText);
+if (isset($x1) && isset($x2) && isset($y1) && isset($y2) && isset($coord)) {
+/*	<BBOX>
+            <PropertyName>ows:BoundingBox</PropertyName>
+            <gml:Envelope>
+              <gml:lowerCorner>-180 -90</gml:lowerCorner>
+              <gml:upperCorner>180 90</gml:upperCorner>
+            </gml:Envelope>
+          </BBOX>*/
+/*<ogc:Intersects> <ogc:PropertyName>ows:BoundingBox</ogc:PropertyName>
+<gml:Envelope>
+<gml:lowerCorner>14.05 46.46</gml:lowerCorner>
+<gml:upperCorner>17.24 48.42</gml:upperCorner>
+</gml:Envelope>
+</ogc:Intersects>*/
+	$existsSpatialFilter = true;
+	//$spatialFilter = "<BBOX>";
+	switch ($coord) {
+		case "intersect":
+			$spatialFilter .= "<ogc:BBOX>";
+		break;
+		case "inside":
+			$spatialFilter .= "<ogc:Within>";
+		break;
+		case "outside":
+			$spatialFilter .= "<ogc:Disjoint>";
+		break;
+		default:
+			$spatialFilter .= "<ogc:BBOX>";
+	}
+	$spatialFilter .= "<ogc:PropertyName>BoundingBox</ogc:PropertyName>";
+	$spatialFilter .= "<gml:Envelope>";
+	$spatialFilter .= "<gml:lowerCorner>".$x1." ".$y1."</gml:lowerCorner>";
+	$spatialFilter .= "<gml:upperCorner>".$x2." ".$y2."</gml:upperCorner>";
+	$spatialFilter .= "</gml:Envelope>";
+	switch ($coord) {
+		case "intersect":
+			$spatialFilter .= "</ogc:BBOX>";
+		break;
+		case "inside":
+			$spatialFilter .= "</ogc:Within>";
+		break;
+		case "outside":
+			$spatialFilter .= "</ogc:Disjoint>";
+		break;
+		default:
+			$spatialFilter .= "/<ogc:BBOX>";
+	}
+	//$spatialFilter .= "</BBOX>";
 
 
+} else {
+	$existsSpatialFilter = false;
+}
+//set kind of filter
 
+//debug output
+$e = new mb_notice($spatialFilter);
+
+
 #get the information out of the mapbender-db
 #get urls to search interfaces (csw):
 $sql_csw = "SELECT * from gp_csw ORDER BY csw_id";
@@ -211,61 +303,108 @@
 	//calculate the startindex for the requested pagenumber
  	$startIndex = ((real)$csw_list[$i_si] ["h"]*((integer)$request_p - 1)) + 1;
 	//$number_of_pages=ceil((real)$n_results/(real)$csw_list[$i_si] ['h']);
-	$getRecords = '<GetRecords xmlns="http://www.opengis.net/cat/csw/2.0.2"';
+	$getRecords = '<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2"';
 	$getRecords .= '            xmlns:gmd="http://www.isotc211.org/2005/gmd"';
-	$getRecords .= '            xmlns:csw="http://www.opengis.net/cat/csw/2.0.2"';
+	$getRecords .= '            xmlns:ogc="http://www.opengis.net/ogc"';
+	$getRecords .= '            xmlns:gml="http://www.opengis.net/gml"';
 	$getRecords .= '           maxRecords="'.$csw_list[$i_si] ["h"].'"';
 	$getRecords .= '           outputFormat="application/xml"';
 	$getRecords .= '           outputSchema="http://www.isotc211.org/2005/gmd"';
 	$getRecords .= '           resultType="results"';
+	//sortby
+	$getRecords .= '           sortby="Title:A"';
 	$getRecords .= '           service="CSW"';
 	$getRecords .= '          startPosition="'.$startIndex.'"'; //set this for paging - maybe it must be calculated from max count
 	$getRecords .= '          version="2.0.2">';
+
 	$getRecords .= '          <csw:Query typeNames="csw:Record">';
 	$getRecords .= '          <csw:ElementSetName>summary</csw:ElementSetName>';
 	$getRecords .= '          <csw:Constraint version="1.1.0">';
 
-	$getRecords .= '          <Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml">';
-	$getRecords .= '          <And>';
-	$getRecords .= '          <PropertyIsLike wildCard="%" singleChar="_" escape="">';
-	$getRecords .= '          <PropertyName>AnyText</PropertyName>';
-	$getRecords .= '          <Literal>%'.$_REQUEST["q"].'%</Literal>';
+	$getRecords .= '          <ogc:Filter>';
+	$getRecords .= '          <ogc:And>';
+	if ($queryText != '*') {
+		$getRecords .= '          <ogc:PropertyIsLike wildCard="%" singleChar="_" escape="">';
+		$getRecords .= '          <ogc:PropertyName>AnyText</ogc:PropertyName>';
+		$getRecords .= '          <ogc:Literal>%'.$queryText.'%</ogc:Literal>';
+		$getRecords .= '          </ogc:PropertyIsLike>';
+	}
 	$type = trim($csw_list[$i_si]['hierachylevel']);
 	switch ($type) {
     		case ($type=='dataset' || $type=='series' || $type=='service' || $type=='nonGeographicDataset' || $type=='application'):
-			$getRecords .= '          </PropertyIsLike>';
-			$getRecords .= '          <PropertyIsEqualTo>';
-			$getRecords .= '          <PropertyName>Type</PropertyName>';
-			$getRecords .= '          <Literal>'.$type.'</Literal>';
-			$getRecords .= '          </PropertyIsEqualTo>';
+
+
+			$getRecords .= '          <ogc:PropertyIsEqualTo>';
+			$getRecords .= '          <ogc:PropertyName>Type</ogc:PropertyName>';
+			$getRecords .= '          <ogc:Literal>'.$type.'</ogc:Literal>';
+			$getRecords .= '          </ogc:PropertyIsEqualTo>';
 		break;
 		case 'dataset/series':
-			$getRecords .= '          <Or>';
-			$getRecords .= '          </PropertyIsLike>';
-			$getRecords .= '          <PropertyIsEqualTo>';
-			$getRecords .= '          <PropertyName>Type</PropertyName>';
-			$getRecords .= '          <Literal>dataset</Literal>';
-			$getRecords .= '          </PropertyIsEqualTo>';
-			$getRecords .= '          </PropertyIsLike>';
-			$getRecords .= '          <PropertyIsEqualTo>';
-			$getRecords .= '          <PropertyName>Type</PropertyName>';
-			$getRecords .= '          <Literal>series</Literal>';
-			$getRecords .= '          </PropertyIsEqualTo>';
-			$getRecords .= '          </Or>';
+			$getRecords .= '          <ogc:Or>';
+			$getRecords .= '          <ogc:PropertyIsEqualTo>';
+			$getRecords .= '          <ogc:PropertyName>Type</ogc:PropertyName>';
+			$getRecords .= '          <ogc:Literal>dataset</ogc:Literal>';
+			$getRecords .= '          </ogc:PropertyIsEqualTo>';
+			$getRecords .= '          </ogc:PropertyIsLike>';
+			$getRecords .= '          <ogc:PropertyIsEqualTo>';
+			$getRecords .= '          <ogc:PropertyName>Type</ogc:PropertyName>';
+			$getRecords .= '          <ogc:Literal>series</ogc:Literal>';
+			$getRecords .= '          </ogc:PropertyIsEqualTo>';
+			$getRecords .= '          </ogc:Or>';
 		break;
 		default:
 	}
+
+/*<?xml version="1.0" encoding="UTF-8"?>
+<csw:GetRecords
+ xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" 
+ xmlns:ogc="http://www.opengis.net/ogc"
+ xmlns:gml="http://www.opengis.net/gml"
+ service="CSW" 
+ version="2.0.2" 
+ resultType="results" 
+ outputSchema="http://www.isotc211.org/2005/gmd">
+  <csw:Query typeNames="gmd:MD_Metadata">
+    <csw:ElementSetName>brief</csw:ElementSetName>
+    <csw:Constraint version="1.1.0">
+      <ogc:Filter>
+
+<ogc:And>
+<ogc:PropertyIsLike wildCard="%" singleChar="_" escape="">
+<ogc:PropertyName>AnyText</ogc:PropertyName>
+<ogc:Literal>Wald</ogc:Literal>
+</ogc:PropertyIsLike>
+
+      <ogc:BBOX>
+        <ogc:PropertyName>BoundingBox</ogc:PropertyName>
+          <gml:Envelope>
+            <gml:lowerCorner>5 49</gml:lowerCorner>
+            <gml:upperCorner>9 51</gml:upperCorner>
+          </gml:Envelope>
+      </ogc:BBOX>
+</ogc:And>
+      </ogc:Filter>
+    </csw:Constraint>
+  </csw:Query>
+</csw:GetRecords>
+*/
 	//$getRecords .= '          <Literal>dataset</Literal>';
-	
-	$getRecords .= '          </And>';
-	$getRecords .= '          </Filter>';
+	//deactivate spatialFilter cause there is a bug in geonetwork 2.6.4!
+	//http://trac.osgeo.org/geonetwork/ticket/585
+	if ($existsSpatialFilter) {
+		$getRecords .= $spatialFilter;
+	}
 
+
+	$getRecords .= '          </ogc:And>';
+	$getRecords .= '          </ogc:Filter>';
+
 	$getRecords .= '          </csw:Constraint>';          
 	$getRecords .= '          </csw:Query>';
-	$getRecords .= '</GetRecords>';
+	$getRecords .= '</csw:GetRecords>';
 
 echo "<br>REQUEST for results<br>".htmlentities($getRecords)."<br>";
-
+$e = new mb_exception($getRecords);
 //for CSW define POST REQUEST for getrecords
 	$cswInterfaceObject = new connector();
 	$cswInterfaceObject->set('httpType','POST');
@@ -288,7 +427,7 @@
 	$openSearchUrlDetail[$i_si]=$csw_list[$i_si] ['getrecordbyidurl']."?";
 	
 	//get resultlists
-	//$url=$openSearchUrlSearch[$i_si]."q=".$_REQUEST["q"].$csw_list[$i_si] ['standardfilter']."&h=".$csw_list[$i_si] ['h']."&p=".$request_p;
+	//$url=$openSearchUrlSearch[$i_si]."q=".$queryText.$csw_list[$i_si] ['standardfilter']."&h=".$csw_list[$i_si] ['h']."&p=".$request_p;
 	$url = $openSearchUrl[$i_si];
 	if (!$from_cli) {	
 	echo "<br> url: ".$url."<br>";
@@ -300,7 +439,11 @@
 	#save resultset in temporary folder identified by sessionid, katalog_id and page_id! Now there would be more tmp files than before! 
 	#this has to be done in order to give the information to typo3
 	#**************to be done!************************************
-	$e = new mb_exception('external xml : '.$openSearchResult);
+	//if ($existsSpatialFilter) {
+	//	$e = new mb_exception('external xml : '.$openSearchResult);
+	//}
+
+	$e = new mb_notice('external xml : '.$openSearchResult);
 	#parse result to simplexml 
 	$openSearchXml =  new SimpleXMLElement($openSearchResult);	
 	//$openSearchXml = ($openSearchResult);
@@ -358,8 +501,8 @@
 	if($os_catalogs_file_handle = fopen($resdir."/".$cli_id."_os".$catalog_number."_".$request_p.".xml","w")){
 		fwrite($os_catalogs_file_handle,"<resultlist>\n");
 		#logit("<resultlist>\n");
-		fwrite($os_catalogs_file_handle,"<querystring>".urlencode($_REQUEST["q"])."</querystring>\n");
-		#logit("<querystring>".urlencode($_REQUEST["q"])."</querystring>\n");
+		fwrite($os_catalogs_file_handle,"<querystring>".urlencode($queryText)."</querystring>\n");
+		#logit("<querystring>".urlencode($queryText)."</querystring>\n");
 		fwrite($os_catalogs_file_handle,"<totalresults>".$n_results."</totalresults>\n");
 		#logit("<totalresults>".$n_results."</totalresults>\n");
 		fwrite($os_catalogs_file_handle,"<npages>".$number_of_pages."</npages>\n");



More information about the Mapbender_commits mailing list