[mapguide-users] Zooming to extent of multiple selections

Jason Birch jason at jasonbirch.com
Tue Dec 22 13:38:14 EST 2009


If it's any comfort, I had no clue from the look I took :)

Are you using try/catch exception handling? It can make it easier to
figure out what's going on sometimes.

Jason

On 2009-12-22, Jo Cook <j.cook at oxfordarch.co.uk> wrote:
>
> Answered my own question :-)
>
> For information, and future people having a similar problem, the issue was
> not with the code but with the fact that the layer came from an odbc data
> source, so consequently had no geometry or extents. I figured that out using
> the web tier tests. Once I realised that (which was no doubt obvious to most
> people) I could extract the values for the coordinates from the table and
> use that to construct an envelope for zooming to.
>
> Jo
>
>
> Jo Cook wrote:
>>
>> OK, with some serious searching through the mailing lists, and looking at
>> the showgeom.php example in the schemareport folder, I have learnt a
>> little more about GetExtents, but I'm still stuck and would very much
>> appreciate some assistance. My code is as follows:
>>
>> MgInitializeWebTier ($webconfigFilePath);
>>
>>                 $userInfo = new MgUserInformation($sessionId);
>>                 $siteConnection = new MgSiteConnection();
>>                 $siteConnection->Open($userInfo);
>>
>>                 echo "Map: ".$mapName."<br />";
>>                 $map = new MgMap($siteConnection);
>>                 $map->Open($mapName);
>>
>>                 $cfilter = "POSTCODE = '$ccode'";
>>                 echo "Query: ".$cfilter.'<br />';
>>
>>
>>                 $queryOptions = new MgFeatureQueryOptions();
>>                 $queryOptions->SetFilter($cfilter);
>>
>>                 echo "Layer: ".$SMAlayer.'<br />';
>>                 $layers = $map->GetLayers();
>>                 $selLayer = $layers->GetItem($SMAlayer);
>>
>>
>>                 $featureresourceID = new
>> MgResourceIdentifier($selLayer->GetFeatureSourceId());
>>                 //print_r($featureresourceID);
>> 		$featureclassname = $selLayer->GetFeatureClassName();
>>                 $featureService =
>> $siteConnection->CreateService(MgServiceType::FeatureService);
>>                 $dataReader =
>> $featureService->SelectFeatures($featureresourceID, $featureclassname,
>> $queryOptions);
>>                 $dataReader->ReadNext();
>>                 $resourceService =
>> $siteConnection->CreateService(MgServiceType::ResourceService);
>>
>>                 $selection = new MgSelection($map);
>>                 $selection->AddFeatures($selLayer, $dataReader, 0);
>>
>>                 $selection->Save($resourceService, $mapName);
>>                 $dataReader->Close();
>>
>>
>>                 $count =
>> $selection->GetSelectedFeaturesCount($selLayer,$featureclassname);
>>                 echo 'Count: '.$count.'<br />';
>>
>>           	$agfReaderWriter = new MgAgfReaderWriter();
>>                 // this seems to be the problem line
>> 		$spatialcontextReader =
>> $featureService->GetSpatialContexts($featureresourceID, false);
>>    		while ($spatialcontextReader->ReadNext())
>>                 {
>>                         // Finds the extent
>>                         $extentByteReader =
>> $spatialcontextReader->GetExtent();
>>
>>                 }
>>                 $spatialcontextReader->Close();
>> 					
>>
>>
>> 		// Get the extent geometry from the spatial context
>>                 $extentGeometry =
>> $agfReaderWriter->Read($extentByteReader);
>> 		
>> 		$iterator = $extentGeometry->GetCoordinates();
>>                 while($iterator->MoveNext())
>>                 {	
>>                     $x = $iterator->GetCurrent()->GetX();
>>                     $y = $iterator->GetCurrent()->GetY();
>>                     if($firstTime)
>>                     {
>>                         $maxX = $x;
>>                         $minX = $x;
>>                         $maxY = $y;
>>                         $minY = $y;
>>                         $firstTime = false;
>>                     }
>>                     if($maxX<$x)
>>                         $maxX = $x;
>>                     if($minX>$x||$minX==0)
>>                         $minX = $x;
>>                     if($maxY<$y)
>>                         $maxY = $y;
>>                     if($minY>$y||$minY==0)
>>                         $minY = $y;
>>                 }
>>
>> 		echo "extent lower left: ".$minX.",".$minY."<br />";
>>
>> 				
>> }
>>
>> When this runs I get an error that "the argument is null". I believe the
>> error is something to do with the spatialcontextreader line, but I can't
>> figure out what's wrong with it.
>>
>> Any thoughts?
>>
>> Jo
>>
>>
>
> --
> View this message in context:
> http://n2.nabble.com/Zooming-to-extent-of-multiple-selections-tp4199009p4203040.html
> Sent from the MapGuide Users mailing list archive at Nabble.com.
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>


More information about the mapguide-users mailing list