Exemple #1
0
        /// <summary>
        /// Here we need to create the lines of sight and determine is a target can be seen or not
        /// Visualize the visible targets with GREEN circles
        /// Visualize the non visible targets with RED circles
        /// Visualize the number of observers that can see a target with a label #
        /// Visualize an observer that can see no targets with a RED circle on top of a BLUE circle
        /// Visualize an observer that can see at least one target with a GREEN circle on top of a BLUE circle
        /// </summary>
        internal override void CreateMapElement()
        {
            try
            {
                IsRunning = true;
                IPolyline longestLine = new PolylineClass();

                if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null || string.IsNullOrWhiteSpace(SelectedSurfaceName))
                {
                    return;
                }

                //base.CreateMapElement();

                // take your observer and target points and get lines of sight

                var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);

                if (surface == null)
                {
                    return;
                }

                // Determine if selected surface is projected or geographic
                ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
                var    geoDataset   = surfaceLayer as IGeoDataset;
                SelectedSurfaceSpatialRef = geoDataset.SpatialReference;

                if (SelectedSurfaceSpatialRef is IGeographicCoordinateSystem)
                {
                    MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSUserPrompt, VisibilityLibrary.Properties.Resources.LLOSUserPromptCaption);
                    return;
                }

                if (geoDataset != null && ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode)
                {
                    MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSDataFrameMatch, VisibilityLibrary.Properties.Resources.LOSSpatialReferenceCaption);
                    return;
                }

                SelectedSurfaceSpatialRef = geoDataset.SpatialReference;

                var geoBridge = new GeoDatabaseHelperClass() as IGeoDatabaseBridge2;

                if (geoBridge == null)
                {
                    return;
                }

                IPoint    pointObstruction = null;
                IPolyline polyVisible      = null;
                IPolyline polyInvisible    = null;
                bool      targetIsVisible  = false;

                double finalObserverOffset = GetOffsetInZUnits(ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
                double finalTargetOffset   = GetOffsetInZUnits(TargetOffset.Value, surface.ZFactor, OffsetUnitType);

                var DictionaryTargetObserverCount = new Dictionary <IPoint, int>();

                foreach (var observerPoint in ObserverAddInPoints)
                {
                    // keep track of visible targets for this observer
                    var CanSeeAtLeastOneTarget = false;

                    var z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset;

                    if (double.IsNaN(z1))
                    {
                        System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
                        return;
                    }

                    foreach (var targetPoint in TargetAddInPoints)
                    {
                        var z2 = surface.GetElevation(targetPoint.Point) + finalTargetOffset;

                        if (double.IsNaN(z2))
                        {
                            System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
                            return;
                        }

                        var fromPoint = new PointClass()
                        {
                            Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true
                        } as IPoint;
                        var toPoint = new PointClass()
                        {
                            Z = z2, X = targetPoint.Point.X, Y = targetPoint.Point.Y, ZAware = true
                        } as IPoint;

                        geoBridge.GetLineOfSight(surface, fromPoint, toPoint,
                                                 out pointObstruction, out polyVisible, out polyInvisible, out targetIsVisible, false, false);

                        var pcol = new PolylineClass() as IPointCollection;
                        pcol.AddPoint(fromPoint);
                        pcol.AddPoint(toPoint);
                        IPolyline pcolPolyline = pcol as IPolyline;

                        longestLine = (longestLine != null && longestLine.Length < pcolPolyline.Length) ? pcolPolyline : longestLine;

                        // set the flag if we can see at least one target
                        if (targetIsVisible)
                        {
                            CanSeeAtLeastOneTarget = true;

                            // update target observer count
                            UpdateTargetObserverCount(DictionaryTargetObserverCount, targetPoint.Point);
                        }

                        if (polyVisible != null)
                        {
                            AddGraphicToMap(polyVisible, new RgbColorClass()
                            {
                                Green = 255
                            });
                        }

                        if (polyInvisible != null)
                        {
                            AddGraphicToMap(polyInvisible, new RgbColorClass()
                            {
                                Red = 255
                            });
                        }

                        if (polyVisible == null && polyInvisible == null)
                        {
                            if (targetIsVisible)
                            {
                                AddGraphicToMap(pcol as IPolyline, new RgbColorClass()
                                {
                                    Green = 255
                                });
                            }
                            else
                            {
                                AddGraphicToMap(pcol as IPolyline, new RgbColorClass()
                                {
                                    Red = 255
                                });
                            }
                        }
                    }

                    // visualize observer

                    // add blue dot
                    AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                    {
                        Blue = 255
                    }, size: 10);

                    if (CanSeeAtLeastOneTarget)
                    {
                        // add green dot
                        AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                        {
                            Green = 255
                        });
                    }
                    else
                    {
                        // add red dot
                        AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                        {
                            Red = 255
                        });
                    }
                }

                VisualizeTargets(DictionaryTargetObserverCount);
                ZoomToExtent(longestLine);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(VisibilityLibrary.Properties.Resources.ExceptionSomethingWentWrong,
                                                     VisibilityLibrary.Properties.Resources.CaptionError);
            }
            finally
            {
                IsRunning = false;
            }
        }
        /// <summary>
        /// Here we need to create the lines of sight and determine is a target can be seen or not
        /// Visualize the visible targets with GREEN circles
        /// Visualize the non visible targets with RED circles
        /// Visualize the number of observers that can see a target with a label #
        /// Visualize an observer that can see no targets with a RED circle on top of a BLUE circle
        /// Visualize an observer that can see at least one target with a GREEN circle on top of a BLUE circle
        /// </summary>
        internal override void CreateMapElement()
        {
            try
            {
                IsRunning = true;

                if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null || string.IsNullOrWhiteSpace(SelectedSurfaceName))
                {
                    return;
                }

                base.CreateMapElement();

                // take your observer and target points and get lines of sight

                var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);

                if (surface == null)
                {
                    return;
                }

                var geoBridge = new GeoDatabaseHelperClass() as IGeoDatabaseBridge2;

                if (geoBridge == null)
                {
                    return;
                }

                IPoint    pointObstruction = null;
                IPolyline polyVisible      = null;
                IPolyline polyInvisible    = null;
                bool      targetIsVisible  = false;

                double finalObserverOffset = GetOffsetInZUnits(ArcMap.Document.FocusMap, ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
                double finalTargetOffset   = GetOffsetInZUnits(ArcMap.Document.FocusMap, TargetOffset.Value, surface.ZFactor, OffsetUnitType);

                var DictionaryTargetObserverCount = new Dictionary <IPoint, int>();

                foreach (var observerPoint in ObserverAddInPoints)
                {
                    // keep track of visible targets for this observer
                    var CanSeeAtLeastOneTarget = false;

                    var z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset;

                    if (surface.IsVoidZ(z1))
                    {
                        if (double.IsNaN(z1))
                        {
                            z1 = 0.000001;
                        }
                    }

                    foreach (var targetPoint in TargetAddInPoints)
                    {
                        var z2 = surface.GetElevation(targetPoint.Point) + finalTargetOffset;

                        if (surface.IsVoidZ(z2))
                        {
                            if (double.IsNaN(z2))
                            {
                                z2 = 0.000001;
                            }
                        }

                        var fromPoint = new PointClass()
                        {
                            Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true
                        } as IPoint;
                        var toPoint = new PointClass()
                        {
                            Z = z2, X = targetPoint.Point.X, Y = targetPoint.Point.Y, ZAware = true
                        } as IPoint;

                        geoBridge.GetLineOfSight(surface, fromPoint, toPoint,
                                                 out pointObstruction, out polyVisible, out polyInvisible, out targetIsVisible, false, false);

                        // set the flag if we can see at least one target
                        if (targetIsVisible)
                        {
                            CanSeeAtLeastOneTarget = true;

                            // update target observer count
                            UpdateTargetObserverCount(DictionaryTargetObserverCount, targetPoint.Point);
                        }

                        if (polyVisible != null)
                        {
                            AddGraphicToMap(polyVisible, new RgbColorClass()
                            {
                                Green = 255
                            });
                        }

                        if (polyInvisible != null)
                        {
                            AddGraphicToMap(polyInvisible, new RgbColorClass()
                            {
                                Red = 255
                            });
                        }

                        if (polyVisible == null && polyInvisible == null)
                        {
                            var pcol = new PolylineClass() as IPointCollection;
                            pcol.AddPoint(fromPoint);
                            pcol.AddPoint(toPoint);

                            if (targetIsVisible)
                            {
                                AddGraphicToMap(pcol as IPolyline, new RgbColorClass()
                                {
                                    Green = 255
                                });
                            }
                            else
                            {
                                AddGraphicToMap(pcol as IPolyline, new RgbColorClass()
                                {
                                    Red = 255
                                });
                            }
                        }
                    }

                    // visualize observer

                    // add blue dot
                    AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                    {
                        Blue = 255
                    }, size: 10);

                    if (CanSeeAtLeastOneTarget)
                    {
                        // add green dot
                        AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                        {
                            Green = 255
                        });
                    }
                    else
                    {
                        // add red dot
                        AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                        {
                            Red = 255
                        });
                    }
                }

                VisualizeTargets(DictionaryTargetObserverCount);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(VisibilityLibrary.Properties.Resources.ExceptionSomethingWentWrong);
            }
            finally
            {
                IsRunning = false;
            }
        }
        /// <summary>
        /// Here we need to create the lines of sight and determine is a target can be seen or not
        /// Visualize the visible targets with GREEN circles
        /// Visualize the non visible targets with RED circles
        /// Visualize the number of observers that can see a target with a label #
        /// Visualize an observer that can see no targets with a RED circle on top of a BLUE circle
        /// Visualize an observer that can see at least one target with a GREEN circle on top of a BLUE circle
        /// </summary>
        internal override void CreateMapElement()
        {
            try
            {
                IsRunning = true;

                if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null || string.IsNullOrWhiteSpace(SelectedSurfaceName))
                    return;

                base.CreateMapElement();

                // take your observer and target points and get lines of sight

                var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);

                if (surface == null)
                    return;

                var geoBridge = new GeoDatabaseHelperClass() as IGeoDatabaseBridge2;

                if (geoBridge == null)
                    return;

                IPoint pointObstruction = null;
                IPolyline polyVisible = null;
                IPolyline polyInvisible = null;
                bool targetIsVisible = false;

                double finalObserverOffset = GetOffsetInZUnits(ArcMap.Document.FocusMap, ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
                double finalTargetOffset = GetOffsetInZUnits(ArcMap.Document.FocusMap, TargetOffset.Value, surface.ZFactor, OffsetUnitType);

                var DictionaryTargetObserverCount = new Dictionary<IPoint, int>();

                foreach (var observerPoint in ObserverAddInPoints)
                {
                    // keep track of visible targets for this observer
                    var CanSeeAtLeastOneTarget = false;

                    var z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset;

                    if (surface.IsVoidZ(z1))
                    {
                        if (double.IsNaN(z1))
                            z1 = 0.000001;
                    }

                    foreach (var targetPoint in TargetAddInPoints)
                    {
                        var z2 = surface.GetElevation(targetPoint.Point) + finalTargetOffset;

                        if (surface.IsVoidZ(z2))
                        {
                            if (double.IsNaN(z2))
                                z2 = 0.000001;
                        }

                        var fromPoint = new PointClass() { Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true } as IPoint;
                        var toPoint = new PointClass() { Z = z2, X = targetPoint.Point.X, Y = targetPoint.Point.Y, ZAware = true } as IPoint;

                        geoBridge.GetLineOfSight(surface, fromPoint, toPoint,
                            out pointObstruction, out polyVisible, out polyInvisible, out targetIsVisible, false, false);

                        // set the flag if we can see at least one target
                        if (targetIsVisible)
                        {
                            CanSeeAtLeastOneTarget = true;

                            // update target observer count
                            UpdateTargetObserverCount(DictionaryTargetObserverCount, targetPoint.Point);
                        }

                        if (polyVisible != null)
                        {
                            AddGraphicToMap(polyVisible, new RgbColorClass() { Green = 255 });
                        }

                        if (polyInvisible != null)
                        {
                            AddGraphicToMap(polyInvisible, new RgbColorClass() { Red = 255 });
                        }

                        if (polyVisible == null && polyInvisible == null)
                        {
                            var pcol = new PolylineClass() as IPointCollection;
                            pcol.AddPoint(fromPoint);
                            pcol.AddPoint(toPoint);

                            if (targetIsVisible)
                                AddGraphicToMap(pcol as IPolyline, new RgbColorClass() { Green = 255 });
                            else
                                AddGraphicToMap(pcol as IPolyline, new RgbColorClass() { Red = 255 });
                        }
                    }

                    // visualize observer

                    // add blue dot
                    AddGraphicToMap(observerPoint.Point, new RgbColorClass() { Blue = 255 }, size: 10);

                    if (CanSeeAtLeastOneTarget)
                    {
                        // add green dot
                        AddGraphicToMap(observerPoint.Point, new RgbColorClass() { Green = 255 });
                    }
                    else
                    {
                        // add red dot
                        AddGraphicToMap(observerPoint.Point, new RgbColorClass() { Red = 255 });
                    }
                }

                VisualizeTargets(DictionaryTargetObserverCount);
            }
            catch(Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(VisibilityLibrary.Properties.Resources.ExceptionSomethingWentWrong);
            }
            finally
            {
                IsRunning = false;
            }
        }