[mapguide-users] PostGIS selection bug?

gabrimonfa gabrimonfa at gmail.com
Sat May 17 01:11:16 EDT 2008


I've found that if I don't have an ogc_fid field neither PGSQL_OGR_FID
variable is set, feature selection doesn't work correctly in MapGuide OS
1.2.

Not only the feature is not selected in blue also programmatically
retreiving selected feature (as suggested in the manual) doesn't work. This
is the code (well most of it since it is too long)

$map = new MgMap();
$map->Open($resourceService, $mapName); //$resourceService is initialized
before, $mapName is passed by js

$selection = new MgSelection($map, $selection);  //$selection is the result
of getSelectionXML() js viewer function
$layers = $selection->GetLayers();

if ($layers) {
	$queryOptions = new MgFeatureQueryOptions();
	for ($i = 0; $i < $layers->GetCount(); $i++) {
		$layer = $layers->GetItem($i);
		if ($layer) { 
			// Create a filter containing the IDs of the selected features on this
layer
			$layerClassName = $layer->GetFeatureClassName();
			$selectionString = $selection->GenerateFilter($layer,$layerClassName);
			// Get the feature resource for the selected layer
			$layerFeatureId = $layer->GetFeatureSourceId();
			$layerFeatureResource = new MgResourceIdentifier($layerFeatureId);
			// Apply the filter to the feature resource for the selected layer. This
returns an MgFeatureReader of all the selected features.
			$queryOptions->SetFilter($selectionString);
			$featureReader =
$featureService->SelectFeatures($layerFeatureResource,$layerClassName,
$queryOptions);
			
			// Process each item in the MgFeatureReader, displaying the owner name
			while ($featureReader->ReadNext()) {
				$val = $featureReader->GetString(<your_string_field_name>);
				echo $val;
			}
                }
	}
}


if you print $selectionString it is like "FID=0" where FID is a field that
is not in the table but automatically added by the server
The problem is that selection is always empty (ie.
$featureReader->ReadNext() is always false), no matter how many feature are
selected.

If I change the code filtering for an existing attribute and an existing
value, such as

$queryOptions->SetFilter("id=14");

I'm able to recover the other fields (btw the FID field added automatically
has exactly the value given into the $selectionString, but filtering by FID
seems to be bugged).

When I jump into this post I add a field called ogc_fid to my table, and now
all works correctly.

In my opinion this is severe bug, because it affects feature selection that
is a primary feature of a mapserver and the solution is somewhat hard to
find.

Hoping to save some time so someone...

Gabriele

-----------------------------------------------------------------------------

I have the same problem and have not dug deep enough into the problem to fix
it, however I do have the instructions.  You need to set the
PGSQL_OGR_FID configuration variable to equal the name of the ID column
of your data. I was told this was documented in the OGR Postgres page (see
http://www.gdal.org/ogr/drv_pg.html).

Please let me know if you get it and anything odd about the fix....because I
still have to do it!

Mark


-- 
View this message in context: http://www.nabble.com/PostGIS-selection-bug--tp9043604p17206510.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list