Select to view content in your preferred language

How to determine whether two features are intersecting?

3641
11
01-15-2013 05:22 AM
Labels (1)
GeorgeFaraj
Frequent Contributor
How can I test whether the symbol of one feature is intersecting the geometry of another feature? For example, I have a feature whose geometry is a MapPoint, but has a TextSymbol set. I want to know if the text is intersecting/overlapping another feature whose geometry is a Polygon.

Is this doable?
0 Kudos
11 Replies
MichaelBranscomb
Esri Frequent Contributor
Exactly. Mike mentioned that there were talks about adding advanced labeling in next versions of the Runtime. Is there an estimated time frame for that by any chance?


Unfortunately there is no timescale yet, but I wanted to let you know that we're aware that client-side labelling control is lacking from the API and that we are working to address this.

Cheers

Mike
0 Kudos
GeorgeFaraj
Frequent Contributor
Thanks guys.

I managed to get something working. Here's my code:

geometryTask.LabelPointsCompleted += delegate(object snd, GraphicsEventArgs le)
{
 graphicsLayer.Graphics.Clear();
 
 for (int i = 0; i < le.Results.Count; ++i)
 {
  var graphic = le.Results;
  var feature = features;
  if (feature.Geometry != null && feature.Attributes["PROP_ID"] != null && Convert.ToInt32(feature.Attributes["PROP_ID"]) > 0)
  {
   var extent = feature.Geometry.Extent;
   var point1 = MyMap.MapToScreen(new MapPoint(extent.XMin, extent.YMin, extent.ZMin, extent.MMin, extent.SpatialReference));
   var point2 = MyMap.MapToScreen(new MapPoint(extent.XMax, extent.YMax, extent.ZMax, extent.MMax, extent.SpatialReference));

   if (Point.Subtract(point1, point2).Length > 110)
   {
    var symbol = new TextSymbol()
    {
     Text = feature.Attributes["PROP_ID"].ToString(),
     ControlTemplate = LayoutRoot.Resources["LabelTemplate"] as ControlTemplate,
     FontSize = 12,
     OffsetX = 50,
     OffsetY = 6
    };
    graphic.Symbol = symbol;
    var mapPoint = graphic.Geometry as MapPoint;
    graphic.Attributes.Add("X", mapPoint.X);
    graphic.Attributes.Add("Y", mapPoint.Y);
    graphicsLayer.Graphics.Add(graphic);
   }
  }
 }
};


This actually makes the labels get hidden when they're too big for the polygon. I'm checking to see if the polygon's extent's diagonal's length is enough to house the label. But this works best (or only) on certain polygons, and doesn't work for others, for obvious reasons.

Any pointers on getting it to work with any or most polygons would be appreciated.


EDIT: Changing the condition to:

if ((point2.X - point1.X) > 110)


seems to approximate it better.
0 Kudos