[fusion-dev] extendselection in mapserver

Paul Spencer pspencer at dmsolutions.ca
Fri Nov 14 07:00:57 EST 2008


Hi,

thanks for posting this, this is a nice improvement to incorporate -  
the formatting seems to have been lost entirely though, so it is  
almost impossible to tell where your changes are.

If possible, try to post a diff rather than the whole file.  You can  
use svn for this or a variety of other tools depending on your platform.

And don't forget to register to the mailing list ;)

Cheers

Paul

On 14-Nov-08, at 4:05 AM, klementszabolcs wrote:

> Hi.
> I make a solution for mapserver extendselection.
> The file Mapserver/php/Query.php is attached.
> The interested lines is 123-160
>
>
> numlayers; $bAllLayers = true; } $result = NULL; $result- 
> >hasSelection = false; $result->layers = array();  
> $sellayers=array(); for ($i=0; $i<$nLayers; $i++) { if (! 
> $bAllLayers) { $oLayer = $oMap->GetLayerByName($layers[$i]); } else  
> { $oLayer = $oMap->GetLayer($i); } $oLayer->set('tolerance', 0); // 
> klement //if (strcasecmp($layers[$i],'ing_telepulesrol')==0) { // 
> $oLayer->set('data',str_replace('%x_ing_telepulesre%', 
> $_REQUEST['x_ing_telepulesre'],$oLayer->data)); $oLayer- 
> >set('data',str_replace('%x_ing_telepulesrol%', 
> $_REQUEST['x_ing_telepulesrol'],$oLayer->data)); $oLayer- 
> >set('data',str_replace('%x_fo%',$_REQUEST['x_fo'],$oLayer->data));  
> $oLayer->set('data',str_replace('%x_column%',$_REQUEST['x_column'], 
> $oLayer->data)); $oLayer- 
> >set('data',str_replace('%x_elerhetoseg_tazon%', 
> $_REQUEST['x_elerhetoseg_tazon'],$oLayer->data)); $oLayer- 
> >set('data',str_replace('%x_min%',$_REQUEST['x_min'],$oLayer- 
> >data)); $oLayer->set('data',str_replace('%x_max%', 
> $_REQUEST['x_max'],$oLayer->data)); // } if ($oLayer->type ==  
> MS_LAYER_RASTER || $oLayer->type == MS_LAYER_QUERY || $oLayer->type  
> == MS_LAYER_CIRCLE || $oLayer->type == MS_LAYER_CHART) { continue; }  
> if (@$oLayer->queryByShape($oSpatialFilter) == MS_SUCCESS) { $result- 
> >hasSelection = true; $layerName = $oLayer->name; array_push($result- 
> >layers, $layerName); $result->$layerName->featureCount = $oLayer- 
> >getNumResults(); if ($bExtendSelection) { $selfeatures=array(); for  
> ($iRes=0; $iRes < $oLayer->getNumResults(); $iRes++) { $oRes =  
> $oLayer->getResult($iRes); $selfe=NULL; $selfe->tileindex=$oRes- 
> >tileindex; $selfe->shapeindex=$oRes->shapeindex;  
> array_push($selfeatures,$selfe); } array_push($sellayers,  
> $selfeatures); } } } if ($bExtendSelection) { $oMap- 
> >loadquery(getSessionSavePath()."query.qry"); for  
> ($i=0;$iGetLayerByName($result->layers[$i]); //$AAA=$oMap- 
> >GetLayer($la->index); //echo ($AAA->name); //echo count($ss).','. 
> $la->index.':'; for ($j=0;$jindex.':'.$xx->tileindex.','.$xx- 
> >shapeindex.';'; $aa=$oMap->queryByIndex($la->index,$xx->tileindex, 
> $xx->shapeindex,MS_TRUE); } } } header('Content-type: text/x-json');  
> header('X-JSON: true'); if ($result->hasSelection) { $oMap- 
> >savequery(getSessionSavePath()."query.qry"); $result->queryFile =  
> getSessionSavePath()."query.qry"; /*holds selection array*/  
> $properties = NULL; $properties->layers = array(); $totalminx = 0;  
> $totalminy = 0; $totalmaxx = 0; $totalmaxy = 0; $bFirstElement = 1;  
> $nLayers = $oMap->numlayers; for ($i=0; $i<$nLayers; $i++) { $oLayer  
> = $oMap->GetLayer($i); $numResults = $oLayer->getNumResults(); if  
> ($numResults == 0){ continue; } $oLayer->open(); $layerName =  
> $oLayer->name != "" ? $oLayer->name : "Layer_".$i;  
> array_push($properties->layers, $layerName); $properties->$layerName- 
> >numelements = $numResults; $properties->$layerName->propertynames =  
> array(); $properties->$layerName->propertyvalues = array();  
> $properties->$layerName->propertytypes = array(); $properties-> 
> $layerName->values = array(); $properties->$layerName- 
> >metadatanames= array(); array_push($properties->$layerName- 
> >metadatanames, 'dimension'); array_push($properties->$layerName- 
> >metadatanames, 'bbox'); array_push($properties->$layerName- 
> >metadatanames, 'center'); array_push($properties->$layerName- 
> >metadatanames, 'area'); array_push($properties->$layerName- 
> >metadatanames, 'length'); /*get first shape to get the attributes*/  
> $oRes = $oLayer->getResult(0); $oShape = $oLayer->getShape($oRes- 
> >tileindex,$oRes->shapeindex); $selFields = array(); if  
> (isset($_SESSION[$mapName][$layerName]['query_items']))  
> { $aQueryItems = $_SESSION[$mapName][$layerName]['query_items']; }  
> else { //token separator (for parsing displayed attributes on a  
> query) $tokenSeparator = ","; // checking if metadata  
> "query_include_items" is set $metadataItems = $oLayer- 
> >getMetaData('query_include_items'); if ( ($metadataItems == "") ||  
> ($metadataItems == "all") ) { while ( list($key,$val) = each($oShape- 
> >values) ) { $aQueryItems[$key] = NULL; } } else { $token =  
> strtok($metadataItems, $tokenSeparator); while ($token !== false)  
> { $aQueryItems[trim($token)] = NULL; $token =  
> strtok($tokenSeparator);              } } // checking if metadata  
> "query_exclude_items" is set $metadataItems = $oLayer- 
> >getMetaData('query_exclude_items'); if ($metadataItems != "")  
> { $token = strtok($metadataItems, $tokenSeparator);                 
> while ($token !== false) { if (array_key_exists($token,  
> $aQueryItems)) { unset($aQueryItems[$token]); } $token =  
> strtok($tokenSeparator); } } // get all alias while ( list($key, 
> $val) = each($aQueryItems) ) { $keyAlias = $oLayer- 
> >getMetaData("query_".$key."_alias"); trim($keyAlias); if  
> ($keyAlias != "") { $aQueryItems[$key] = $keyAlias; } }  
> $_SESSION[$mapName][$layerName]['query_items'] = $aQueryItems; }  
> $oShape = $oLayer->getShape($oRes->tileindex,$oRes->shapeindex);  
> while ( list($key,$val) = each($oShape->values) ) { if  
> (array_key_exists($key, $aQueryItems)) { array_push($selFields,  
> $key); //we check if an alias if provided if  
> (isset($aQueryItems[$key]) && ($aQueryItems[$key] != "")){ $key =  
> $aQueryItems[$key]; } array_push($properties->$layerName- 
> >propertynames, $key); //TODO : we should define away to give alias  
> to field names array_push($properties->$layerName->propertyvalues,  
> $key); //TODO we do not know the types of the attributes in MS. Just  
> output 0 //we shouls possibly use OGR to get the attributes  
> array_push($properties->$layerName->propertytypes, 0); } } for  
> ($iRes=0; $iRes < $numResults; $iRes++) { $properties->$layerName- 
> >values[$iRes] = array(); $properties->$layerName->metadata[$iRes] =  
> array(); $oRes = $oLayer->getResult($iRes); $oShape = $oLayer- 
> >getShape($oRes->tileindex,$oRes->shapeindex); //TODO : area, length  
> and distance are not set $minx = $oShape->bounds->minx; $miny =  
> $oShape->bounds->miny; $maxx = $oShape->bounds->maxx; $maxy =  
> $oShape->bounds->maxy; if ($bFirstElement) { $bFirstElement = 0;  
> $totalminx = $minx; $totalminy = $miny; $totalmaxx = $maxx;  
> $totalmaxy = $maxy; } else { if ($totalminx > $minx) { $totalminx =  
> $minx; } if ($totalminy > $miny) { $totalminy = $miny; } if  
> ($totalmaxx < $maxx) { $totalmaxx = $maxx; } if ($totalmaxy < $maxy)  
> { $totalmaxy = $maxy; } } //metadata : TODO dimension, area, length  
> and distance are not set $dimension = 0; $center = 0; $area = 0;  
> $length = 0; $bbox = $minx.','.$miny.','.$maxx.','.$maxy;  
> array_push($properties->$layerName->metadata[$iRes], $dimension);  
> array_push($properties->$layerName->metadata[$iRes], $bbox);  
> array_push($properties->$layerName->metadata[$iRes], $center);  
> array_push($properties->$layerName->metadata[$iRes], $area);  
> array_push($properties->$layerName->metadata[$iRes], $length); // 
> field values for($iField=0; $iField < count($selFields); $iField++)  
> { $value = $oShape->values[$selFields[$iField]]; //$value =  
> preg_replace( "/\r?\n/", "
> ", $value ); $value = str_replace("'", "\'", $value);  
> array_push($properties->$layerName->values[$iRes],  
> $value);            } } $oLayer->close(); } //extents $properties- 
> >extents = NULL; $properties->extents->minx = $totalminx;  
> $properties->extents->miny = $totalminy; $properties->extents->maxx  
> = $totalmaxx; $properties->extents->maxy = $totalmaxy; /*save  
> selection in the session*/ $_SESSION['selection_array'] =  
> $properties; } echo var2json($result); ?>  
> _______________________________________________
> fusion-dev mailing list
> fusion-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/fusion-dev


__________________________________________

    Paul Spencer
    Chief Technology Officer
    DM Solutions Group Inc
    http://research.dmsolutions.ca/



More information about the fusion-dev mailing list