Example #1
0
        public void AddIssue(Issue issue, IGeometry issueGeometry)
        {
            Assert.ArgumentNotNull(issue, nameof(issue));

            try
            {
                if (IssueGeometryTransformation != null)
                {
                    issueGeometry = IssueGeometryTransformation.TransformGeometry(issue,
                                                                                  issueGeometry);
                }

                IGeometry storableIssueGeometry = GetStorableIssueGeometry(issueGeometry);

                IssueWriter issueWriter = GetIssueWriter(storableIssueGeometry);

                issueWriter.Write(issue, storableIssueGeometry);
            }
            catch (Exception e)
            {
                _msg.ErrorFormat("Error adding issue: {0} ({1})",
                                 FormatIssue(issue),
                                 e.Message);
                throw;
            }
        }
        /// <summary>
        /// Calculates the segments shorter than the specified length per feature
        /// within the provided perimeter.
        /// </summary>
        /// <param name="forFeatureVertexInfos"></param>
        /// <param name="use2DLengthOnly"></param>
        /// <param name="perimeter"></param>
        /// <param name="trackCancel"></param>
        /// <returns>The short segments per feature</returns>
        public static void CalculateShortSegments(
            [NotNull] ICollection <FeatureVertexInfo> forFeatureVertexInfos,
            bool use2DLengthOnly,
            [CanBeNull] IGeometry perimeter,
            [CanBeNull] ITrackCancel trackCancel)
        {
            Assert.ArgumentNotNull(forFeatureVertexInfos, nameof(forFeatureVertexInfos));

            Stopwatch watch =
                _msg.DebugStartTiming(
                    "Getting short segments for {0} features.",
                    forFeatureVertexInfos.Count);

            var shortSegmentCount = 0;
            var shortFeatureCount = 0;

            foreach (FeatureVertexInfo vertexInfo in forFeatureVertexInfos)
            {
                if (trackCancel != null && !trackCancel.Continue())
                {
                    return;
                }

                try
                {
                    IList <esriSegmentInfo> removableSegments = CalculateShortSegments(vertexInfo,
                                                                                       use2DLengthOnly,
                                                                                       perimeter);

                    shortSegmentCount += removableSegments.Count;
                    shortFeatureCount++;
                }
                catch (Exception)
                {
                    _msg.ErrorFormat("Error calculating generalized points for {0}",
                                     GdbObjectUtils.ToString(vertexInfo.Feature));
                    throw;
                }
            }

            _msg.DebugStopTiming(watch,
                                 "Found {0} segments shorter than minimum segment length in {1} of {2} features.",
                                 shortSegmentCount, shortFeatureCount,
                                 forFeatureVertexInfos.Count);
        }
Example #3
0
        private Color CreateColor()
        {
            Color defaultColor = Color.White;

            if (!string.IsNullOrEmpty(_knownColor))
            {
                try
                {
                    return(Color.FromKnownColor(
                               (KnownColor)Enum.Parse(typeof(KnownColor), _knownColor)));
                }
                catch (Exception)
                {
                    _msg.ErrorFormat("Unknown 'known color' value: {0})", _knownColor);
                    return(defaultColor);
                }
            }

            if (!string.IsNullOrEmpty(_colorName))
            {
                try
                {
                    return(Color.FromName(_colorName));
                }
                catch (Exception)
                {
                    _msg.ErrorFormat("Unknown color name: {0})", _colorName);
                    return(defaultColor);
                }
            }

            try
            {
                return(Color.FromArgb(_red, _green, _blue));
            }
            catch (Exception e)
            {
                _msg.ErrorFormat(
                    "Error creating color from RGB values {0},{1},{2} ({3})",
                    _red, _green, _blue, e.Message);
                return(defaultColor);
            }
        }
Example #4
0
        public static T CreateObject <T>([NotNull] string progId)
        {
            Assert.ArgumentNotNullOrEmpty(progId, nameof(progId));

            Type type = Type.GetTypeFromProgID(progId);

            Assert.NotNull(type, "Unable to get type for progId: {0}", progId);

            try
            {
                return((T)Activator.CreateInstance(type));
            }
            catch (Exception e)
            {
                _msg.ErrorFormat("Error instantiating object for {0}: {1}",
                                 progId, e.Message);
                throw;
            }
        }
Example #5
0
        private Polygon GetIntersection([NotNull] Polygon[] perimeters, int index)
        {
            Assert.ArgumentNotNull(perimeters, nameof(perimeters));

            if (_msg.IsVerboseDebugEnabled)
            {
                _msg.DebugFormat("Intersecting perimeters {0} to {1}",
                                 index, perimeters.Length - 1);
            }

            Polygon intersection = GeometryFactory.Clone(perimeters[index]);

            // todo daro old implementation
            //GeometryUtils.EnsureSpatialReference(intersection, SpatialReference, true);

            // intersect with all following perimeters, if any
            int nextIndex = index + 1;

            if (nextIndex < perimeters.Length)
            {
                for (int combineIndex = nextIndex;
                     combineIndex < perimeters.Length;
                     combineIndex++)
                {
                    //Polygon projectedPerimeter =
                    //	GetInWorkListSpatialReference(perimeters[combineIndex]);

                    Polygon projectedPerimeter = perimeters[combineIndex];

                    if (intersection.IsEmpty)
                    {
                        // no further intersection, result is empty
                        return(intersection);
                    }
                    if (projectedPerimeter.IsEmpty)
                    {
                        // no further intersection, result is empty
                        return(projectedPerimeter);
                    }

                    // both are not empty; calculate intersection
                    try
                    {
                        // todo daro: old implementation
                        //var topoOp = (ITopologicalOperator)intersection;

                        //intersection =
                        //	(IPolygon)topoOp.Intersect(
                        //		projectedPerimeter,
                        //		esriGeometryDimension.esriGeometry2Dimension);

                        intersection =
                            (Polygon)GeometryEngine.Instance.Intersection(
                                intersection, projectedPerimeter,
                                GeometryDimension.esriGeometry2Dimension);
                    }
                    catch (Exception e)
                    {
                        try
                        {
                            _msg.ErrorFormat(
                                "Error intersecting perimeters ({0}). See log file for details",
                                e.Message);

                            _msg.DebugFormat("Perimeter index={0}:", combineIndex);
                            // todo daro: old implementation
                            //_msg.Debug(GeometryUtils.ToString(projectedPerimeter));

                            _msg.DebugFormat(
                                "Input intersection at nextIndex={0}:", nextIndex);
                            // todo daro: old implementation
                            //_msg.Debug(GeometryUtils.ToString(intersection));

                            // leave intersection as is, and continue
                        }
                        catch (Exception e1)
                        {
                            _msg.Warn("Error writing details to log", e1);
                        }
                    }

                    // todo daro: old implementation
                    //if (_msg.IsVerboseDebugEnabled)
                    //{
                    //	_msg.DebugFormat("Intersection {0}: {1}",
                    //					 combineIndex,
                    //					 IntersectionToString(intersection));
                    //}
                }
            }

            return(intersection);
        }