[mapguide-users] Re: problem when using same code for MapGuideEnterprise2009 with MapGuideEnterprise2010

ehsan ehsan85 at yahoo.com
Tue Feb 9 22:46:44 EST 2010


Sorry for the late reply, busy with assignment..when i get through the code
again i forget to give this code:

//create a multi-polygon or a multi-geometry containing the input selected
features
$inputGeom = MultiGeometryFromSelection($featureSrvc, $map, $selectionXml);

// Query all the features belonging the the layer list that intersects with
the input geometries
$fi = $renderingSrvc->QueryFeatures($map, $layerNames,
$inputGeom,MgFeatureSpatialOperations::Intersects, -1);

       if($fi)
              {
                	$resultSel = $fi->GetSelection();
                if($resultSel)
                {
                    	$selxml=$resultSel->ToXml();//change the selection to
XML
                    	
                    	$selection = new MgSelection($map, $selxml);//get the
Intersects Layer on the selection
    					                 $layers_selection = $selection->GetLayers();//get
layers
    					                 if($layers_selection)
    					                 {
    						                   for ($i = 0; $i <
$layers_selection->GetCount(); $i++)
    						                   {
    							                    $layer = $layers_selection->GetItem($i);
                       $selectlayer_name[$i]=$layer->GetName();
	              }
    					                 }
                 }
               }

function MultiGeometryFromSelection($featureSrvc, $map, $selText)
{
    $sel = new MgSelection($map, $selText);
    $selLayers = $sel->GetLayers();
    $geomColl = new MgGeometryCollection();
    $agfRW = new MgAgfReaderWriter();
    $polyOnly = true;
	
    for($i = 0; $i < $selLayers->GetCount(); $i++)
    {
        $layer = $selLayers->GetItem($i);

        // TODO:  How to get $selectionSize?
        $selectionSize = 20;
        $filters = $sel->GenerateFilters($layer,
$layer->GetFeatureClassName(), $selectionSize);

        $numFilters = $filters->GetCount();

        for ($filterIndex = 0; $filterIndex < $numFilters; $filterIndex++)
        {
            $filter = $filters->GetItem($filterIndex);
            if ($filter == "")
                continue;

            $query = new MgFeatureQueryOptions();
            $query->SetFilter($filter);
            $featureSource = new
MgResourceIdentifier($layer->GetFeatureSourceId());
            $features = $featureSrvc->SelectFeatures($featureSource,
$layer->GetFeatureClassName(), $query);
            if($features)
            {
                $classDef = $features->GetClassDefinition();
                $geomPropName = $classDef->GetDefaultGeometryPropertyName();
                $j = 0;
                $isPoly = true;
                while($features->ReadNext())
                {
                    $geomReader = $features->GetGeometry($geomPropName);
                    $geom = $agfRW->Read($geomReader);
                    if($j ++ == 0)
                    {
                        $type = $geom->GetGeometryType();
                        if($type == MgGeometryType::MultiPolygon || $type ==
MgGeometryType::CurvePolygon || $type == MgGeometryType::MultiCurvePolygon)
                        {
                            $isPoly = false;
                            $polyOnly = false;
                        }
                        else if($type != MgGeometryType::Polygon)
                            break;
                    }
                    $geomColl->Add($geom);
                }
                $features->Close();
            }
        }
    }
    if($geomColl->GetCount() == 0)
        return null;

    $gf = new MgGeometryFactory();
    if($polyOnly)
    {
        $polyColl = new MgPolygonCollection();
        for($i = 0; $i < $geomColl->GetCount(); $i++)
            $polyColl->Add($geomColl->GetItem($i));
        return $gf->CreateMultiPolygon($polyColl);
    }
    else
        return $gf->CreateMultiGeometry($geomColl);
}

i use these code to get the intersect with the select layer, i realize that
this code did not return any value from the function
MultiGeometryFromSelection..

thanks..
-- 
View this message in context: http://n2.nabble.com/problem-when-using-same-code-for-MapGuideEnterprise2009-with-MapGuideEnterprise2010-tp4492918p4545782.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list