In MapXtreme applications we can do a selection of objects within a certain radius from a certain point. Usually this kind of selection is applied to determine the number of competitors, or the number of POI around a central point. For example how many motor dealers who are within 2 km of the motor dealer A.
Here is a sample program selection radius:
view source
print?
01 private void SearchWithinRadius (double x, double y, double rad)
02 {
03 Map map = MapInfo.Engine.Session.Current.MapFactory [MapControl1.MapAlias];
04 MapInfo.Data.SearchInfo's;
05 si = MapInfo.Data.SearchInfoFactory.SearchWithinDistance (new MapInfo.Geometry.DPoint (x, y),
06 MapInfo.Engine.Session.Current.CoordSysFactory.CreateLongLat (DatumID.WGS84),
07 new MapInfo.Geometry.Distance (rad, DistanceUnit.Kilometer), MapInfo.Data.ContainsType.Centroid);
08 si.QueryDefinition.Columns = new string [] {"*"};
09
10 MapInfo.Data.IResultSetFeatureCollection irfc;
11 irfc = MapInfo.Engine.Session.Current.Catalog.Search ("NamaLayer", si);
12 / / zoom the map to the object selected
13 peta.SetView (irfc);
14
15 if (irfc.Count == 0)
16 {
17 / / No object within a radius sought. Do something here
18 return;
19}
20
21 / / if the object is met
22 foreach (f in irfc MapInfo.Data.Feature)
23 {
24 / / Do something with the objects found here.
25}
26
27 MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear ();
28 MapInfo.Engine.Session.Current.Selections.DefaultSelection.Add (irfc);
29}
To illustrate the circle radius on the map:
view source
print?
01 private void CreateCircle (double x, double y, Single radius)
02 {
03 Map map = GetMapObjek ();
04 / / because the circle will be created in the temporary layer, then if the temp layer already exists,
05 / / temp this layer must be removed first
06 if (peta.Layers ["temp"]! = Null)
07 {
08 FeatureLayer FTR = (FeatureLayer) peta.Layers ["temp"];
09 ftr.Modifiers.Clear ();
10 ftr.Table.Close ();
11}
12 / / close temp table if it turns out, there is a temp table the rest of the user laen
13 MapInfo.Engine.Session.Current.Catalog.CloseTable ("temp");
14
15 MapInfo.Data.TableInfo ti = MapInfo.Data.TableInfoFactory.CreateTemp ("temp");
16 MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable (ti);
17
18 DPoint center = new DPoint (x, y);
19 Ellipse circle = new Ellipse (peta.GetDisplayCoordSys (), center,
20 radius, radius, DistanceUnit.Kilometer, DistanceType.Spherical);
21 MapInfo.Styles.AreaStyle MapInfo.Styles.AreaStyle circlestyle = new ();
22 circlestyle.Interior = new MapInfo.Styles.SimpleInterior (8,
23 System.Drawing.Color.Aqua, System.Drawing.Color.Transparent, true);
24
25 MapInfo.Data.Feature f = new MapInfo.Data.Feature (circle, circlestyle);
26 tabel.InsertFeature (f);
27
28 FeatureLayer fl = new FeatureLayer (table);
29 peta.Layers.Add (fl);
Here is a sample program selection radius:
view source
print?
01 private void SearchWithinRadius (double x, double y, double rad)
02 {
03 Map map = MapInfo.Engine.Session.Current.MapFactory [MapControl1.MapAlias];
04 MapInfo.Data.SearchInfo's;
05 si = MapInfo.Data.SearchInfoFactory.SearchWithinDistance (new MapInfo.Geometry.DPoint (x, y),
06 MapInfo.Engine.Session.Current.CoordSysFactory.CreateLongLat (DatumID.WGS84),
07 new MapInfo.Geometry.Distance (rad, DistanceUnit.Kilometer), MapInfo.Data.ContainsType.Centroid);
08 si.QueryDefinition.Columns = new string [] {"*"};
09
10 MapInfo.Data.IResultSetFeatureCollection irfc;
11 irfc = MapInfo.Engine.Session.Current.Catalog.Search ("NamaLayer", si);
12 / / zoom the map to the object selected
13 peta.SetView (irfc);
14
15 if (irfc.Count == 0)
16 {
17 / / No object within a radius sought. Do something here
18 return;
19}
20
21 / / if the object is met
22 foreach (f in irfc MapInfo.Data.Feature)
23 {
24 / / Do something with the objects found here.
25}
26
27 MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear ();
28 MapInfo.Engine.Session.Current.Selections.DefaultSelection.Add (irfc);
29}
To illustrate the circle radius on the map:
view source
print?
01 private void CreateCircle (double x, double y, Single radius)
02 {
03 Map map = GetMapObjek ();
04 / / because the circle will be created in the temporary layer, then if the temp layer already exists,
05 / / temp this layer must be removed first
06 if (peta.Layers ["temp"]! = Null)
07 {
08 FeatureLayer FTR = (FeatureLayer) peta.Layers ["temp"];
09 ftr.Modifiers.Clear ();
10 ftr.Table.Close ();
11}
12 / / close temp table if it turns out, there is a temp table the rest of the user laen
13 MapInfo.Engine.Session.Current.Catalog.CloseTable ("temp");
14
15 MapInfo.Data.TableInfo ti = MapInfo.Data.TableInfoFactory.CreateTemp ("temp");
16 MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable (ti);
17
18 DPoint center = new DPoint (x, y);
19 Ellipse circle = new Ellipse (peta.GetDisplayCoordSys (), center,
20 radius, radius, DistanceUnit.Kilometer, DistanceType.Spherical);
21 MapInfo.Styles.AreaStyle MapInfo.Styles.AreaStyle circlestyle = new ();
22 circlestyle.Interior = new MapInfo.Styles.SimpleInterior (8,
23 System.Drawing.Color.Aqua, System.Drawing.Color.Transparent, true);
24
25 MapInfo.Data.Feature f = new MapInfo.Data.Feature (circle, circlestyle);
26 tabel.InsertFeature (f);
27
28 FeatureLayer fl = new FeatureLayer (table);
29 peta.Layers.Add (fl);