コード例 #1
0
        private static ISegment GetConnectSegment([NotNull] IPath ofPath,
                                                  [NotNull] IPoint sourceConnectPoint,
                                                  double tolerance)
        {
            // Always gets the previous segment in case of To-Point (even for the 0th)
            int partIndex;
            int segmentIndex = SegmentReplacementUtils.GetSegmentIndex(
                ofPath, sourceConnectPoint, tolerance, out partIndex);

            ISegment sourceSegment =
                ((ISegmentCollection)ofPath).Segment[segmentIndex];

            return(sourceSegment);
        }
コード例 #2
0
        private static ISegment GetConnectSegment([NotNull] IPath sourceReplacementPath,
                                                  [NotNull] ICurve curveToReshape,
                                                  [NotNull] IPoint sourceConnectPoint,
                                                  double tolerance)
        {
            // Always gets the previous segment in case of To-Point (even for the 0th)
            int partIndex;
            int segmentIndex = SegmentReplacementUtils.GetSegmentIndex(
                curveToReshape, sourceConnectPoint, tolerance, out partIndex);

            ISegment sourceSegment =
                ((ISegmentCollection)curveToReshape).Segment[segmentIndex];

            IGeometry highLevelSourceSegment = GeometryUtils.GetHighLevelGeometry(
                sourceSegment, true);

            // if the reshape line connects in the segment's interior, it should be always used
            bool sourceConnectPointIsSegmentToPoint =
                GeometryUtils.Touches(highLevelSourceSegment, sourceConnectPoint);

            IGeometry highLevelSourceReplacement =
                GeometryUtils.GetHighLevelGeometry(sourceReplacementPath, true);

            // however, if the reshape line connects in the segment's to-point, the segment that
            // is not part of the source replacement should be used -> it's part of the shared boundary
            if (sourceConnectPointIsSegmentToPoint &&
                GeometryUtils.InteriorIntersects(
                    highLevelSourceReplacement, highLevelSourceSegment))
            {
                if (segmentIndex == ((ISegmentCollection)curveToReshape).SegmentCount - 1)
                {
                    segmentIndex = 0;
                }
                else
                {
                    segmentIndex++;
                }
            }

            sourceSegment = ((ISegmentCollection)curveToReshape).Segment[segmentIndex];

            Marshal.ReleaseComObject(highLevelSourceSegment);
            Marshal.ReleaseComObject(highLevelSourceReplacement);

            return(sourceSegment);
        }
コード例 #3
0
        public void CanGetSegmentIndexRing()
        {
            const double xyTolerance = 0.0125;
            IPolygon     poly        = GeometryFactory.CreatePolygon(1000, 2000, 1500, 2500);

            poly.SpatialReference = CreateSpatialReference(xyTolerance, 0.0125);

            var ring = (IRing)((IGeometryCollection)poly).get_Geometry(0);

            IPoint searchPoint = new PointClass();

            searchPoint.PutCoords(234, 34675);
            int partIndex;

            int?resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                ring, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.IsNull(resultIndex, "Point is not on geometry but segment index returned.");

            searchPoint.PutCoords(1000, 2000);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                ring, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.IsNotNull(resultIndex, "Point is on geometry but segment index not found.");
            Assert.AreEqual(0, resultIndex);

            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                ring, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(3, resultIndex);

            searchPoint.PutCoords(1000, 2500);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                ring, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.AreEqual(1, resultIndex);

            searchPoint.PutCoords(1500, 2000);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                ring, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.AreEqual(3, resultIndex);
        }
コード例 #4
0
        public void CanGetSegmentIndexMultipartPolyline()
        {
            const double xyTolerance = 0.0125;

            IPolyline polyline = GeometryFactory.CreatePolyline(1000, 2000, 1500, 2500);

            ISpatialReference lv95 = CreateSpatialReference(0.0125, 0.0125);

            polyline.SpatialReference = lv95;

            object missing = Type.Missing;

            ((IPointCollection)polyline).AddPoint(
                GeometryFactory.CreatePoint(2000, 3000), ref missing, ref missing);

            IGeometry secondLine = GeometryFactory.CreatePolyline(5000, 8000, 5500, 8500);

            ((IPointCollection)secondLine).AddPoint(
                GeometryFactory.CreatePoint(6000, 9000), ref missing, ref missing);

            ((IGeometryCollection)polyline).AddGeometryCollection(
                (IGeometryCollection)secondLine);

            GeometryUtils.Simplify(polyline);

            IPoint searchPoint = new PointClass();

            searchPoint.PutCoords(234, 34675);
            int partIndex;

            int?resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                polyline, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.IsNull(resultIndex,
                          "Point is not on geometry but non-null segment index returned.");

            // 1. point, segment from-point
            searchPoint.PutCoords(1000, 2000);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                polyline, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.IsNotNull(resultIndex, "Point is on geometry but segment index not found.");
            Assert.AreEqual(0, resultIndex);
            Assert.AreEqual(0, partIndex);

            // 1. point, segment to-point (actually incorrect parameter combination)
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                polyline, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(0, resultIndex);
            Assert.AreEqual(0, partIndex);

            // 2. point, segment from-point
            searchPoint.PutCoords(1500, 2500);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                polyline, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.AreEqual(1, resultIndex);
            Assert.AreEqual(0, partIndex);

            // 2. point, segment to-point
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                polyline, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(0, resultIndex);
            Assert.AreEqual(0, partIndex);

            // 3. point, segment from-point (actually incorrect parameter combination)
            searchPoint.PutCoords(2000, 3000);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                polyline, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.AreEqual(1, resultIndex);
            Assert.AreEqual(0, partIndex);

            // 3. point, segment to-point
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                polyline, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(1, resultIndex);
            Assert.AreEqual(0, partIndex);

            // 1. point of second, segment from-point
            searchPoint.PutCoords(5000, 8000);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                polyline, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.AreEqual(0, resultIndex);
            Assert.AreEqual(1, partIndex);

            // 1. point of inner ring, segment to-point (incorrect parameter combination)
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                polyline, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(0, resultIndex);
            Assert.AreEqual(1, partIndex);

            // 2. point of inner ring, segment from-point
            searchPoint.PutCoords(5500, 8500);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                polyline, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.AreEqual(1, resultIndex);
            Assert.AreEqual(1, partIndex);

            // 2. point of inner ring, segment to-point
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                polyline, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(0, resultIndex);
            Assert.AreEqual(1, partIndex);

            // 3. point of inner ring, segment from-point (actually incorrect parameter combination)
            searchPoint.PutCoords(6000, 9000);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                polyline, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.AreEqual(1, resultIndex);
            Assert.AreEqual(1, partIndex);

            // 3. point of inner ring, segment to-point
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                polyline, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(1, resultIndex);
            Assert.AreEqual(1, partIndex);
        }
コード例 #5
0
        public void CanGetSegmentIndexMultipartPolygon()
        {
            const double xyTolerance = 0.0125;
            IPolygon     poly        = GeometryFactory.CreatePolygon(1000, 2000, 1500, 2500);
            IGeometry    hole        = GeometryFactory.CreatePolygon(1100, 2100, 1400, 2400);

            ((IGeometryCollection)poly).AddGeometryCollection((IGeometryCollection)hole);

            poly.SpatialReference = CreateSpatialReference(xyTolerance, 0.0125);

            GeometryUtils.Simplify(poly);

            IPoint searchPoint = new PointClass();

            searchPoint.PutCoords(234, 34675);
            int partIndex;

            int?resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.IsNull(resultIndex, "Point is not on geometry but segment index returned.");

            // 1. point, segment from-point
            searchPoint.PutCoords(1000, 2000);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.IsNotNull(resultIndex, "Point is on geometry but segment index not found.");
            Assert.AreEqual(0, resultIndex);
            Assert.AreEqual(0, partIndex);

            // 1. point, segment to-point
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(3, resultIndex);
            Assert.AreEqual(0, partIndex);

            // 2. point, segment from-point
            searchPoint.PutCoords(1000, 2500);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.AreEqual(1, resultIndex);
            Assert.AreEqual(0, partIndex);

            // 2. point, segment to-point
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(0, resultIndex);
            Assert.AreEqual(0, partIndex);

            // 3. point, segment from-point
            searchPoint.PutCoords(1500, 2500);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.AreEqual(2, resultIndex);
            Assert.AreEqual(0, partIndex);

            // 3. point, segment to-point
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(1, resultIndex);
            Assert.AreEqual(0, partIndex);

            // 4. point, segment from-point
            searchPoint.PutCoords(1500, 2000);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.AreEqual(3, resultIndex);
            Assert.AreEqual(0, partIndex);

            // 4. point, segment to-point
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(2, resultIndex);
            Assert.AreEqual(0, partIndex);

            // 1. point of inner ring, segment from-point
            searchPoint.PutCoords(1100, 2100);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.AreEqual(0, resultIndex);
            Assert.AreEqual(1, partIndex);

            // 1. point of inner ring, segment to-point
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(3, resultIndex);
            Assert.AreEqual(1, partIndex);

            // 2. point of inner ring, segment from-point
            searchPoint.PutCoords(1400, 2100);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.AreEqual(1, resultIndex);
            Assert.AreEqual(1, partIndex);

            // 2. point of inner ring, segment to-point
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(0, resultIndex);
            Assert.AreEqual(1, partIndex);

            // 3. point of inner ring, segment from-point
            searchPoint.PutCoords(1400, 2400);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.AreEqual(2, resultIndex);
            Assert.AreEqual(1, partIndex);

            // 3. point of inner ring, segment to-point
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(1, resultIndex);
            Assert.AreEqual(1, partIndex);

            // 4. point of inner ring, segment from-point
            searchPoint.PutCoords(1100, 2400);
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, true, true);

            Assert.AreEqual(3, resultIndex);
            Assert.AreEqual(1, partIndex);

            // 4. point of inner ring, segment to-point
            resultIndex = SegmentReplacementUtils.GetSegmentIndex(
                poly, searchPoint, xyTolerance, out partIndex, false, true);

            Assert.AreEqual(2, resultIndex);
            Assert.AreEqual(1, partIndex);
        }