[mapguide-users] SetSpatialFilter and MgFeatureSpatialOperations
problem with search
Maciej Skorczewski
maciej.skorczewski at procad.pl
Thu Jan 22 11:07:26 EST 2009
Hi
my problem is with "SetSpatialFilter" , in my application user click on
PARCEL (on map) , and after click on "get REGION name" application
should try to search in which REGION (biger surface) is the PARCEL.
what i want to get is:
help image :)
http://img171.imageshack.us/img171/8450/51030812fq1.png
so when user click on small parcel (in grey REGION), first pictures he
should get ID of big grey REGION.
i you see on second image if parcel is nearly yellow REGION user should
get ID ONLY grey region ....
I try use all method like:
MgFeatureSpatialOperations::Intersects
it is work but i get all REGION who Intersects my parcel (yellow and
grey region ), after try another MgFeatureSpatialOperations like:
MgFeatureSpatialOperations::Contains = 0
MgFeatureSpatialOperations::CoveredBy = 8
MgFeatureSpatialOperations::Crosses = 1
MgFeatureSpatialOperations::Disjoint = 2
MgFeatureSpatialOperations::EnvelopeIntersects = 10
MgFeatureSpatialOperations::Equals = 3
MgFeatureSpatialOperations::Inside = 9
MgFeatureSpatialOperations::Intersects = 4
MgFeatureSpatialOperations::Overlaps = 5
MgFeatureSpatialOperations::Touches = 6
MgFeatureSpatialOperations::Within = 7
but get wrong/or none results
That is may procedure
1. user click on map
2. he press button "REGION info"
3. application use Getselection method to get selected parcel info:
ID,NAME, and x,y Coordinates
4. I create new polygon (Coordinates come from selected parcel)
5. i use SetSpatialFilter and by iteration on all map layer i check
what layer is in selected polygon range (REGION).
//------------my code
$selectedFeatures2=array(); //REGION ID,NAME etc.
//$coords -- come from selected parcel (GetCoordinates())
//generate new polygon from selected parcel
$linearRing = $geometryFactory->CreateLinearRing($coords);
$parcel_polygon = $geometryFactory->CreatePolygon($linearRing, null);
$resourceService=$siteConnection->CreateService(MgServiceType::ResourceService);
///--------BEGIN layer iteration...on all map layer
$layer = $map->GetLayers()->GetItem($layer_name[$i]);
$resId = new MgResourceIdentifier($layer->GetFeatureSourceId());
$featureGeometry = $layer->GetFeatureGeometryName();
$featureClass = $layer->GetFeatureClassName();
$schemaAndClass = explode(":", $featureClass);
$featureService
=$siteConnection->CreateService(MgServiceType::FeatureService);
$queryOptions = new MgFeatureQueryOptions();
$queryOptions->SetSpatialFilter($featureGeometry,
$polygon,MgFeatureSpatialOperations::Intersects);
$featureReader = $featureService->SelectFeatures($resId,
$layer->GetFeatureClassName(), $queryOptions);
while ($featureReader->ReadNext())
{
$selectedFeatures2[]=array("layer_name"=>$featureReader->GetString('Layer'),"FeatureId"=>$featureReader->GetInt32('FeatureId'));
}
///--------END layer iteration...on all map layer
Can you pleas give me some sample code for this?
macieksk
More information about the mapguide-users
mailing list