[mapguide-internals] MapGuide RFC 33 - Convenience Methods for Selection

Paul Spencer pspencer at dmsolutions.ca
Thu Sep 6 07:34:24 EDT 2007


Hi Trevor,

to figure out what this saves in realistic terms (in PHP anyway) I  
wrote a sample of the difference in the code:

Before:

MgInitializeWebTier($extensionDir. "webconfig.ini");
$user = new MgUserInformation('Anonymous', '');
$siteConnection = new MgSiteConnection();
$siteConnection->Open($user);
$resourceService = $siteConnection->CreateService 
(MgServiceType::ResourceService);
$featureService = $siteConnection->CreateService 
(MgServiceType::FeatureService);
$map = new MgMap();
$map->Open($resourceService, $mapname);
$selection = new MgSelection($map);
$selection->Open($resourceService, $mapname);
$layers = $selection->GetLayers();
for ($i=0; $i<$layers->GetCount(); $i++) {
     $layer = $layers->GetItem($i);
     $featureId = $layer->GetFeatureSourceId();
     $featureResource = new MgResourceIdentifier($featureId);
     $className = $layer->GetFeatureClassName();
     $selectionString = $selection->GenerateFilter($layer, $className);
     $queryOptions = new MgFeatureQueryOptions();
     $queryOptions->SetFilter($selectionString);
     $featureReader = $featureService->SelectFeatures($featureSource,  
$className, $queryOptions);
     // do something with the feature reader
}

After:

MgInitializeWebTier($extensionDir. "webconfig.ini");
$user = new MgUserInformation('Anonymous', '');
$siteConnection = new MgSiteConnection();
$siteConnection->Open($user);
$resourceService = $siteConnection->CreateService 
(MgServiceType::ResourceService);
$featureService = $siteConnection->CreateService 
(MgServiceType::FeatureService);
$map = new MgMap();
$map->Open($resourceService, $mapname);
$selection = new MgSelection($map);
$selection->Open($resourceService, $mapname);
$layers = $selection->GetLayers();
for ($i=0; $i<$layers->GetCount(); $i++) {
     $layer = $layers->GetItem($i);
     //$featureId = $layer->GetFeatureSourceId();
     //$featureResource = new MgResourceIdentifier($featureId);
     $className = $layer->GetFeatureClassName();
     //$selectionString = $selection->GenerateFilter($layer,  
$className);
     //$queryOptions = new MgFeatureQueryOptions();
     //$queryOptions->SetFilter($selectionString);
     //$featureReader = $featureService->SelectFeatures 
($featureSource, $className, $queryOptions);
     $featureReader = $selection->GetSelectedFeatures($layer,  
$className);
     // do something with the feature reader
}

It looks like this will save about 5 lines of code, is that right?

Also, the code I took the example from also modified the  
$queryOptions to call AddFeaturePropertyName for each of the property  
mappings in the associated layer so that I only get back the  
properties that the layer is configured for.  If I use the new API, I  
would have to actually do that for every feature as it comes out of  
the feature reader, and FDO would have to pass back all the  
properties, regardless of the property mappings.

So I guess, for me, I won't really be able to use these new  
convenience APIs :(  I'm not against adding them, and it would  
probably be nice to save those 5 lines of code for some people (or  
not have to go through the learning curve of figuring out how to get  
features from a selection is more likely), but I'm not sure in  
practice how much of a convenience it would be.  Depending on FDO  
performance handling properties, it may actually encourage writing  
code that performs more poorly (since you can't limit feature  
properties).

Cheers

Paul

On 5-Sep-07, at 3:49 PM, Trevor Wekel wrote:

> Hello list,
>
> MapGuide RFC 33 is ready for review and posted on the Wiki at
> http://trac.osgeo.org/mapguide/wiki/MapGuideRfc33.
>
> Feel free to post any comments to the internals list and I will be  
> happy
> to respond.
>
> Thanks,
> Trevor Wekel
>
> _______________________________________________
> mapguide-internals mailing list
> mapguide-internals at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-internals

+-----------------------------------------------------------------+
|Paul Spencer                          pspencer at dmsolutions.ca    |
+-----------------------------------------------------------------+
|Chief Technology Officer                                         |
|DM Solutions Group Inc                http://www.dmsolutions.ca/ |
+-----------------------------------------------------------------+







More information about the mapguide-internals mailing list