[mapguide-users] Zooming to extent of multiple selections

Jo Cook j.cook at oxfordarch.co.uk
Mon Dec 21 13:28:41 EST 2009


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-tp4199009p4199822.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list