Hello,
I have 2 layers, one is the US States and the other one is my US customers and I want when clicking on a state be able to extract all the customers belonging to this states. How should I proceed?
Thanks a lot.
jm.
Hello,
I have 2 layers, one is the US States and the other one is my US customers and I want when clicking on a state be able to extract all the customers belonging to this states. How should I proceed?
Thanks a lot.
jm.
Jean,
Thank you for interest in our products.
I think you can try code follow this logic as below:
1. Get the clicked location when user click on map. (Here we get point A)
2. Spatial query (shapeFileFeatureLayer.QueryTools) in states layer to find which state contains point A. (I think we can get a PolygonShape B)
3. Spatial query in customers layer, find the customers (Points?) within area B. (We get a collection of customer points).
Wish helpful and any question please let us know.
Thanks
Yigit
Thanks for theLogic!
But I am not that good with this kind of programming then if you could tell me more on how to get this done? The idea is really to use states(LAYER) like MN as container to query the customers layer and extract all the data points (customers) belonging to this state. When I click on the map I know in which state the click take place.
Thanks a lot.
jm.
Jean,
I haven’t post code because I am not sure what’s your programming for detail. Are your customers saved by point feature in shape file or have been added to an InmemoryFeatureLayer?
I think you can find how to use our related APIs from the “Winforms How do I Samples”.
In my logic for item 1 and item 2, you can find the code in sample: Querying Feature Layers/Find the feature(s) a user clicked on
For item 3, you can view the sample: Querying Feature Layers/Spatial Query a feature layer
Any question please let me know.
Regards,
Yigit
******** my customers are loaded using the following code:
featureLayer_ASD_NEW_BUSINESS = new TDPointFeatureLayer("DBIPAD02.GIS_ASD_NEW_HEAT", __where__);
featureLayer_ASD_NEW_BUSINESS.Name = "featureLayer_ASD_NEW_BUSINESS";
featureLayer_ASD_NEW_BUSINESS.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.Black, 6, GeoColor.StandardColors.Black);
featureLayer_ASD_NEW_BUSINESS.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
******** my states are loaded using the following code:
ShapeFileFeatureLayer tmpLayer = new ShapeFileFeatureLayer(path);
tmpLayer.Name = name;
tmpLayer.ZoomLevelSet.ZoomLevel04.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(color, c1), c2, 1);
tmpLayer.ZoomLevelSet.ZoomLevel04.DefaultAreaStyle.OutlinePen.LineJoin = DrawingLineJoin.Round;
tmpLayer.ZoomLevelSet.ZoomLevel04.DefaultAreaStyle.OutlinePen.Color =lc;
tmpLayer.ZoomLevelSet.ZoomLevel04.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
Jean-marie,
Thanks for your post and question.
I think Yigit’ suggestion is correct.
You can follow the HowDoI sample (Find the feature(s) a user clicked on) to find out which state is clicked on, this query should be against to the tmpLayer which stands for the US states.
After we select out the feature in above step, we can follow the HowDoI sample (Spatial Query a feature layer) to do a spatial query to find out which points are contained in the specified feature, the difference is that this query should be based on the featureLayer_ASD_NEW_BUSINESS and the pass-in feature should be feature selected out by mouse clicked.
Any more questions please feel free to let me know.
Thanks.
Yale
Thanks for your reply!
I am able to find the feature the user clicked on and show for instance the name of the state but I still have trouble implementing the query on the other layer (customers layer)… I do ot see how to get the list of polygones used to draw the state boundary line and then use them to capture all the customers (data point) within the customer layer.
jm.
Jean,
Here is some code from how do I sample, I think they should be helpful.
Code segment 1, we find the selectedState and use it in the next step.
void winformsMap1_MapClick(object sender, MapClickWinformsMapEventArgs e)
{
FeatureLayer worldLayer = winformsMap1.FindFeatureLayer("WorldLayer");
worldLayer.Open();
Collection<FEATURE> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(e.WorldLocation, ReturningColumnsType.AllColumns);
worldLayer.Close();
if (selectedFeatures.Count > 0)
{
Feature selectedState = selectedFeatures[0];
}
}
Code segment 2, we query in customers layer
PolygonShape stateShape = selectedState.GetShape() as PolygonShape;
Collection<Feature> customers= tmpLayer.QueryTools.GetFeaturesWithin(rectangleFeature, ReturningColumnsType.AllColumns);
The "customers" should be what we want.
Any question please let us know.
Thanks,
Yigit
Thanks a lot!
Question: my C# doesn’t like the fact that we try to cast a BaseShape as PolygoneShape???
c# selectedState.GetShape() return BaseShape.
thanks!
Jean,
I guess your state data should be PolygoneShape but cannot make sure, so you can add “selectedState.GetShape() is PolygonShape” to watch for make sure that when debug.
Or if you can make sure the state data is not pointshape or lineshape, you don’t need cast its type.
I found I make a mistake in Code segment 2, it should be:
Collection<Feature> customers= tmpLayer.QueryTools.GetFeaturesWithin(stateShape, ReturningColumnsType.AllColumns);
I am sorry for that.
Any question please let us know.
Thanks,
Yigit
?
Is this code valid? :
custWithin = featureLayer_ASD_MF.QueryTools.GetFeaturesWithin(selectedFeaturesCounty[0].GetShape(), ReturningColumnsType.AllColumns);
The selectedFeaturesCounty is the result of :
selectedFeaturesCounty = featureCounty.QueryTools.GetFeaturesContaining(e.WorldLocation, ReturningColumnsType.AllColumns);
and Does work.
I cannot make it to work!
jm.
Jean-marie,
Thanks for your post and question.
I think you are doing right, is it possible that there is no "customers" within the specified polygon country? If you want, could you send us your sample code which definitely will be helpful to identify and fix the issue.
Any more questions please feel free to let me know.
Thanks.
Yale