private void Stuff(MultiLineString multilinestring, IEnumerable <MultiLineString> troutStreamSections, MultiPolygon pal)
        {
            IGeometry[] t             = multilinestring.Geometries;
            var         stream        = t.First();
            var         primaryLength = stream.Length;
            var         lil           = new LocationIndexedLine(stream);
            var         lil2          = new LengthIndexedLine(stream);
            var         result        = stream.Intersection(pal) as MultiLineString;
            var         geoms         = result.Geometries;

            foreach (var part in geoms.Select(i => i as LineString))
            {
                var subParts = lil.IndicesOf(part);
                var count    = subParts.Length;
                foreach (var subPart in subParts)
                {
                    var fraction    = subPart.SegmentFraction;
                    var noIdea      = subPart.GetSegmentLength(part);
                    var otherNoIdea = subPart.GetSegmentLength(stream);
                }

                var subParts2 = lil2.IndicesOf(part);
                var count2    = subParts2.Length;
                foreach (double subPart in subParts2)
                {
//                    var fraction = subPart.
//                    var noIdea = subPart.GetSegmentLength(part);
//                    var otherNoIdea = subPart.GetSegmentLength(stream);
                }
            }
        }
Exemplo n.º 2
0
        public static INetworkSegment CreateSegment(IBranch branch, double startChainage, double endChainage)
        {
            var lengthIndexedLine = new LengthIndexedLine(branch.Geometry);

            var       geometryStartChainage = startChainage;
            var       geometryEndChainage   = endChainage;
            IGeometry geometry = null;

            if (branch.Geometry != null)
            {
                if (branch.IsLengthCustom)
                {
                    geometryStartChainage = startChainage * (branch.Geometry.Length / branch.Length);
                    geometryEndChainage   = endChainage * (branch.Geometry.Length / branch.Length);
                }

                geometry = (IGeometry)lengthIndexedLine.ExtractLine(geometryStartChainage, geometryEndChainage).Clone();
            }

            var segment = new NetworkSegment
            {
                Geometry = geometry,
                Branch   = branch,
                Chainage = startChainage,
                Length   = endChainage - startChainage
            };

            return(segment);
        }
Exemplo n.º 3
0
        private void HandleSelfClosingCase(GpxProlongerExecutorInput input, LineAndCoordinate current, LineAndCoordinate next, List <ILineString> linesToProlong)
        {
            var lengthIndexedLine             = new LengthIndexedLine(current.Line);
            var closestCoordinateCurrentIndex = lengthIndexedLine.Project(current.Coordinate);
            var closestCoordinateNextIndex    = lengthIndexedLine.Project(next.Coordinate);
            var segment     = lengthIndexedLine.ExtractLine(closestCoordinateCurrentIndex, closestCoordinateNextIndex);
            var coordinates = segment.Coordinates.Concat(new[] { segment.Coordinates.First() }).ToArray();

            if (coordinates.Length < 4)
            {
                return;
            }
            var polygon = new Polygon(new LinearRing(coordinates));

            if (polygon.Area < input.MinimalAreaSize)
            {
                return;
            }
            var currentCoordinate = lengthIndexedLine.ExtractPoint(closestCoordinateCurrentIndex);
            var nextCoordinate    = lengthIndexedLine.ExtractPoint(closestCoordinateNextIndex);

            if (!AddCoordinate(current.Line, currentCoordinate, nextCoordinate, linesToProlong, input.MinimalDistance))
            {
                linesToProlong.Add(_geometryFactory.CreateLineString(new[] { currentCoordinate, nextCoordinate }));
            }
        }
        public static IGeometry ExtractPoint(IGeometry g, double index)
        {
            var ll = new LengthIndexedLine(g);
            var p  = ll.ExtractPoint(index);

            return(g.Factory.CreatePoint(p));
        }
Exemplo n.º 5
0
        public GeometryTransformerResult Transform()
        {
            newRefGeometryOut = null;

            int n = oldRefGeometry.Coordinates.Length;

            Coordinate startCoodinate = TransformCoordiante(oldRefGeometry.Coordinates[0]);
            Coordinate endCoordinate  = TransformCoordiante(oldRefGeometry.Coordinates[n - 1]);

            LengthIndexedLine lil = new LengthIndexedLine(newSegmentGeometry);

            double projStartIndex = lil.IndexOf(startCoodinate);
            double projEndIndex   = lil.IndexOf(endCoordinate);

            if (projStartIndex > projEndIndex)
            {
                double temp = projStartIndex;
                projStartIndex = projEndIndex;
                projEndIndex   = temp;
            }
            if (Math.Abs(projStartIndex - projEndIndex) < 1)
            {
                if (projStartIndex == 0 || (Math.Abs(projStartIndex - lil.EndIndex) < double.Epsilon))
                {
                    return(new GeometryTransformerResult(GeometryTransformerResultState.FailedWouldBeOutside, newRefGeometryOut));
                }
                return(new GeometryTransformerResult(GeometryTransformerResultState.FailedWouldBeTooShort, newRefGeometryOut));
            }

            newRefGeometryOut = (ILineString)lil.ExtractLine(projStartIndex, projEndIndex);


            return(new GeometryTransformerResult(GeometryTransformerResultState.Success, newRefGeometryOut));
        }
Exemplo n.º 6
0
        /// <summary>
        /// This methods tries to find the coordinate to add on the closest line and prefers to return one of the edges if possible.
        /// </summary>
        /// <param name="lineToTestAgainst"></param>
        /// <param name="closestLine"></param>
        /// <param name="minimalDistance"></param>
        /// <returns></returns>
        private Coordinate GetCoordinateToAdd(ILineString lineToTestAgainst, ILineString closestLine, double minimalDistance)
        {
            var closestCoordinate = lineToTestAgainst.Coordinates.Last();
            var edgeCoordinate    = GetEdgeCoordiante(closestLine, closestCoordinate, minimalDistance, 1.5);

            if (edgeCoordinate != null)
            {
                return(edgeCoordinate);
            }
            if (lineToTestAgainst.Intersects(closestLine))
            {
                var intecsectionCoordinate = lineToTestAgainst.Intersection(closestLine).Coordinates.First();
                edgeCoordinate = GetEdgeCoordiante(closestLine, intecsectionCoordinate, minimalDistance, 3);
                return(edgeCoordinate ?? intecsectionCoordinate);
            }
            var closestCoordinateOnExitingLine = closestLine.Coordinates.OrderBy(c => c.Distance(closestCoordinate)).First();

            if (closestCoordinateOnExitingLine.Distance(closestCoordinate) < minimalDistance)
            {
                return(closestCoordinateOnExitingLine);
            }

            var closestLineIndexed = new LengthIndexedLine(closestLine);
            var closestCoordinateProjectedIndex = closestLineIndexed.Project(closestCoordinate);
            var projectedCoordinate             = closestLineIndexed.ExtractPoint(closestCoordinateProjectedIndex);

            _geometryFactory.PrecisionModel.MakePrecise(projectedCoordinate);
            edgeCoordinate = GetEdgeCoordiante(closestLine, projectedCoordinate, minimalDistance, 3);
            return(edgeCoordinate ?? projectedCoordinate);
        }
Exemplo n.º 7
0
        protected override bool IndexOfAfterCheck(Geometry linearGeom, Coordinate testPt)
        {
            var indexedLine = new LengthIndexedLine(linearGeom);

            // check locations are consecutive
            double loc1 = indexedLine.IndexOf(testPt);
            double loc2 = indexedLine.IndexOfAfter(testPt, loc1);

            if (loc2 <= loc1)
            {
                return(false);
            }

            // check extracted points are the same as the input
            var pt1 = indexedLine.ExtractPoint(loc1);
            var pt2 = indexedLine.ExtractPoint(loc2);

            if (!pt1.Equals2D(testPt))
            {
                return(false);
            }
            if (!pt2.Equals2D(testPt))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        public static INetworkSegment CreateSegment(IBranch branch, double startOffset, double endOffset)
        {
            var lengthIndexedLine = new LengthIndexedLine(branch.Geometry);

            var       geometryStartOffset = startOffset;
            var       geometryEndOffset   = endOffset;
            IGeometry geometry            = null;

            if (branch.Geometry != null)
            {
                if (branch.IsLengthCustom)
                {
                    geometryStartOffset = startOffset * (branch.Geometry.Length / branch.Length);
                    geometryEndOffset   = endOffset * (branch.Geometry.Length / branch.Length);
                }

                geometry = branch.Geometry == null ? null : (IGeometry)lengthIndexedLine.ExtractLine(geometryStartOffset, geometryEndOffset).Clone();
            }

            var segment = new NetworkSegment
            {
                Geometry = geometry,
                Branch   = branch,
                Offset   = startOffset,
                Length   = endOffset - startOffset
            };

            return(segment);
        }
        public IEnumerable <double> GetIntersectionOfLine(ILineString primaryLine, ILineString subline)
        {
            var lil    = new LengthIndexedLine(primaryLine);
            var result = lil.IndicesOf(subline);

            return(result);
        }
Exemplo n.º 10
0
        protected override Coordinate ExtractOffsetAt(Geometry linearGeom, Coordinate testPt, double offsetDistance)
        {
            var    indexedLine = new LengthIndexedLine(linearGeom);
            double index       = indexedLine.IndexOf(testPt);

            return(indexedLine.ExtractPoint(index, offsetDistance));
        }
Exemplo n.º 11
0
        private void HandleTwoLinesCase(GpxProlongerExecutorInput input, LineAndCoordinate current, LineAndCoordinate next, List <ILineString> linesToProlong)
        {
            var currentLengthIndexedLine = new LengthIndexedLine(current.Line);
            var currentCoordinate        = currentLengthIndexedLine.ExtractPoint(currentLengthIndexedLine.Project(current.Coordinate));
            var nextLengthIndexedLine    = new LengthIndexedLine(next.Line);
            var nextCoordinate           = nextLengthIndexedLine.ExtractPoint(nextLengthIndexedLine.Project(next.Coordinate));

            var bothLinesAreInList = linesToProlong.Contains(current.Line) && linesToProlong.Contains(next.Line);

            if (bothLinesAreInList && current.Line.Coordinates.Last().Distance(current.Coordinate) < input.MinimalDistance &&
                next.Line.Coordinates.First().Distance(next.Coordinate) < input.MinimalDistance)
            {
                linesToProlong.Remove(current.Line);
                linesToProlong.Remove(next.Line);
                linesToProlong.Add(_geometryFactory.CreateLineString(current.Line.Coordinates
                                                                     .Concat(next.Line.Coordinates).ToArray()));
            }
            else if (bothLinesAreInList &&
                     current.Line.Coordinates.First().Distance(current.Coordinate) < input.MinimalDistance &&
                     next.Line.Coordinates.Last().Distance(next.Coordinate) < input.MinimalDistance)
            {
                linesToProlong.Remove(current.Line);
                linesToProlong.Remove(next.Line);
                linesToProlong.Add(_geometryFactory.CreateLineString(next.Line.Coordinates
                                                                     .Concat(current.Line.Coordinates).ToArray()));
            }
            else if (!AddCoordinate(current.Line, currentCoordinate, nextCoordinate, linesToProlong, input.MinimalDistance))
            {
                if (!AddCoordinate(next.Line, currentCoordinate, nextCoordinate, linesToProlong, input.MinimalDistance))
                {
                    linesToProlong.Add(_geometryFactory.CreateLineString(new[] { currentCoordinate, nextCoordinate }));
                }
            }
        }
Exemplo n.º 12
0
        //INetworkCoverage coverage,
        private static IList <INetworkSegment> UpdateSegmentsBranchSegmentBetweenLocations(bool fullyCover,
                                                                                           IBranch branch,
                                                                                           IEnumerable <INetworkLocation>
                                                                                           branchLocations)
        {
            var segments = new List <INetworkSegment>();

            var length = branch.Length;

            // select all locations that have an offset within the branch
            var            factor  = 1.0; // branch.IsLengthCustom ? (branch.Geometry.Length / branch.Length) : 1.0;
            IList <double> offsets =
                branchLocations.Where(l => l.Chainage <= length).Select(l => factor * l.Chainage).ToList();

            if (0 == offsets.Count)
            {
                if (fullyCover)
                {
                    offsets.Add(0);
                    offsets.Add(length);
                }
                else
                {
                    return(segments);
                }
            }
            else
            {
                if (fullyCover)
                {
                    if (Math.Abs(offsets[0]) > BranchFeature.Epsilon)
                    {
                        offsets.Insert(0, 0.0);
                    }
                    if (Math.Abs(offsets[offsets.Count - 1] - length) > BranchFeature.Epsilon)
                    {
                        offsets.Add(length);
                    }
                }
            }

            var lengthIndexedLine = new LengthIndexedLine(branch.Geometry);

            for (int i = 1; i < offsets.Count; i++)
            {
                var segment = new NetworkSegment
                {
                    Branch              = branch,
                    Chainage            = offsets[i - 1],
                    Length              = Math.Abs(offsets[i] - offsets[i - 1]),
                    DirectionIsPositive = offsets[i] >= offsets[i - 1],
                    // thousand bombs and grenades: ExtractLine will give either a new coordinate or
                    // a reference to an existing object
                    Geometry = (IGeometry)lengthIndexedLine.ExtractLine(offsets[i - 1], offsets[i]).Clone()
                };
                segments.Add(segment);
            }
            return(segments);
        }
Exemplo n.º 13
0
        private void CheckExtractLine(String wkt, double start, double end, String expected)
        {
            IGeometry         linearGeom  = Read(wkt);
            LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom);
            IGeometry         result      = indexedLine.ExtractLine(start, end);

            CheckExpected(result, expected);
        }
Exemplo n.º 14
0
        public IEnumerable <double[]> GetIntersections(ILineString stream, IGeometry multipolygon)
        {
            var lil    = new LengthIndexedLine(stream);
            var result = stream.Intersection(multipolygon) as IMultiLineString;
            var geoms  = result.Geometries;

            return(geoms.Select(i => i as ILineString).Select(lil.IndicesOf));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Splits a branch at the given coordinate.
        /// All branch features are updated
        /// </summary>
        /// <param name="branch"></param>
        /// <param name="coordinate"></param>
        /// <param name="newBranchId"></param>
        /// <param name="newNodeId"></param>
        public static INode SplitBranchAtNode(IBranch branch, ICoordinate coordinate, long newBranchId,
                                              long newNodeId)
        {
            var    lengthIndexedLine = new LengthIndexedLine(branch.Geometry);
            double offset            = lengthIndexedLine.Project(coordinate);

            return(SplitBranchAtNode(branch, offset));
        }
Exemplo n.º 16
0
        private void CheckExtractLine(string wkt, double start, double end, string expected)
        {
            var linearGeom  = Read(wkt);
            var indexedLine = new LengthIndexedLine(linearGeom);
            var result      = indexedLine.ExtractLine(start, end);

            CheckExpected(result, expected);
        }
        public static IGeometry Project(IGeometry g, IGeometry g2)
        {
            var    ll    = new LengthIndexedLine(g);
            double index = ll.Project(g2.Coordinate);
            var    p     = ll.ExtractPoint(index);

            return(g.Factory.CreatePoint(p));
        }
Exemplo n.º 18
0
        public void TestProjectPointWithDuplicateCoords()
        {
            var    linearGeom  = Read("LINESTRING (0 0, 10 0, 10 0, 20 0)");
            var    indexedLine = new LengthIndexedLine(linearGeom);
            double projIndex   = indexedLine.Project(new Coordinate(10, 1));

            Assert.IsTrue(projIndex == 10.0);
        }
Exemplo n.º 19
0
        public void TestProjectExtractPoint()
        {
            var    linearGeom  = Read("MULTILINESTRING ((0 2, 0 0), (-1 1, 1 1))");
            var    indexedLine = new LengthIndexedLine(linearGeom);
            double index       = indexedLine.Project(new Coordinate(1, 0));
            var    pt          = indexedLine.ExtractPoint(index);

            Assert.IsTrue(pt.Equals(new Coordinate(0, 0)));
        }
Exemplo n.º 20
0
        protected override Geometry IndicesOfThenExtract(Geometry linearGeom, Geometry subLine)
        {
            var indexedLine = new LengthIndexedLine(linearGeom);

            double[] loc    = indexedLine.IndicesOf(subLine);
            var      result = indexedLine.ExtractLine(loc[0], loc[1]);

            return(result);
        }
Exemplo n.º 21
0
        public void TestComputeZNaN()
        {
            var    linearGeom  = Read("LINESTRING (0 0, 10 10 10)");
            var    indexedLine = new LengthIndexedLine(linearGeom);
            double projIndex   = indexedLine.Project(new Coordinate(5, 5));
            var    projPt      = indexedLine.ExtractPoint(projIndex);

            Assert.IsTrue(double.IsNaN(projPt.Z));
        }
Exemplo n.º 22
0
        /// <summary>
        /// Tries to split a branch at the given chainage. It will not create empty branches ( split at chainage 0 or chainage is length branch)
        /// All branch features are updated
        /// Chainage is interpreted as chainage in geometry, even if IsLengthCustom is true for branch
        /// </summary>
        /// <param name="branch"></param>
        /// <param name="geometryOffset">Local (or geometry-based) chainage</param>
        public static SplitResult SplitBranchAtNode(IBranch branch, double geometryOffset)
        {
            bool startedEdit = false;
            BranchSplitAction branchSplitAction = null;

            //start editaction if not editing

            if (geometryOffset == 0.0)
            {
                return(null); //no split required
            }
            if (geometryOffset == branch.Geometry.Length)
            {
                return(null); //no split required
            }
            if (!branch.Network.IsEditing)
            {
                startedEdit       = true;
                branchSplitAction = new BranchSplitAction();
                branch.Network.BeginEdit(branchSplitAction);
            }

            var lengthIndexedLine = new LengthIndexedLine(branch.Geometry);
            var splitLocation     = lengthIndexedLine.ExtractPoint(geometryOffset);

            var node = (INode)Activator.CreateInstance(branch.Source.GetType());

            node.Name     = GetUniqueName("Node{0:D3}", branch.Network.Nodes, "Node");
            node.Geometry =
                new Point(new Coordinate(splitLocation.X, splitLocation.Y,
                                         Double.IsNaN(splitLocation.Z) ? 0.0 : splitLocation.Z));

            var         newBranch = SplitBranchAtNode(branch.Network, branch, node);
            SplitResult result    = null;

            if (null != newBranch)
            {
                branch.Network.Nodes.Add(node);
                result = new SplitResult
                {
                    NewNode   = node,
                    NewBranch = newBranch
                };
            }

            if (startedEdit)
            {
                branchSplitAction.SplittedBranch = branch;
                if (result != null)
                {
                    branchSplitAction.NewBranch = result.NewBranch;
                }
                branch.Network.EndEdit();
            }

            return(result);
        }
Exemplo n.º 23
0
        public void TestComputeZ()
        {
            IGeometry         linearGeom  = Read("LINESTRING (0 0 0, 10 10 10)");
            LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom);
            double            projIndex   = indexedLine.Project(new Coordinate(5, 5));
            Coordinate        projPt      = indexedLine.ExtractPoint(projIndex);

            //    System.out.println(projPt);
            Assert.IsTrue(projPt.Equals3D(new Coordinate(5, 5, 5)));
        }
Exemplo n.º 24
0
        public void SplitStrassenabschnittGISAtXY(Guid strassenabschnittId, string x, string y)
        {
            StrassenabschnittGIS strassenabschnittToSplit = GetEntityById(strassenabschnittId);

            //check whether the strassenabschnitt (inspektionsroute) is checked out (=locked)
            if (strassenabschnittToSplit.IsLocked)
            {
                return;
            }

            //1. find achsenref. to split
            IGeometry      splitPoint             = GISService.CreateGeometryFactory().CreatePoint(new Coordinate(double.Parse(x, System.Globalization.NumberFormatInfo.InvariantInfo), double.Parse(y, System.Globalization.NumberFormatInfo.InvariantInfo), 0));
            AchsenReferenz achsenreferenceToSplit = gisService.GetNearestGeometry(splitPoint, strassenabschnittToSplit.ReferenzGruppe.AchsenReferenzen);

            //2. split achsenref
            LengthIndexedLine line   = new LengthIndexedLine(achsenreferenceToSplit.Shape);
            IGeometry         split1 = line.ExtractLine(0, line.IndexOf(splitPoint.Coordinate));
            IGeometry         split2 = line.ExtractLine(line.IndexOf(splitPoint.Coordinate), line.EndIndex);

            //create new strassenabschnitte
            StrassenabschnittGIS copiedStrassenabschnittGIS1 = PrepareNewStrassenabschnitt(strassenabschnittToSplit, achsenreferenceToSplit, split1);
            StrassenabschnittGIS copiedStrassenabschnittGIS2 = PrepareNewStrassenabschnitt(strassenabschnittToSplit, achsenreferenceToSplit, split2);

            //3. relate other achsenrefs to the new two references
            foreach (AchsenReferenz achsref in strassenabschnittToSplit.ReferenzGruppe.AchsenReferenzen.Where(ac => !ac.Equals(achsenreferenceToSplit)))
            {
                if (achsref.Shape.Distance(split1) <= achsref.Shape.Distance(split2))
                {
                    copiedStrassenabschnittGIS1.ReferenzGruppe.AddAchsenReferenz(PrepareAchsenreferenz(achsref));
                    copiedStrassenabschnittGIS1.Shape = copiedStrassenabschnittGIS1.Shape.Union(achsref.Shape);
                }
                else
                {
                    copiedStrassenabschnittGIS2.ReferenzGruppe.AddAchsenReferenz(PrepareAchsenreferenz(achsref));
                    copiedStrassenabschnittGIS2.Shape = copiedStrassenabschnittGIS2.Shape.Union(achsref.Shape);
                }
            }

            copiedStrassenabschnittGIS1.Laenge = getLength(copiedStrassenabschnittGIS1);
            copiedStrassenabschnittGIS2.Laenge = getLength(copiedStrassenabschnittGIS2);


            //update inspektionsroute
            strassenabschnittToSplit.InspektionsRtStrAbschnitte.ForEach(s => s.InspektionsRouteGIS.AddStrassenabschnittGIS(copiedStrassenabschnittGIS1));
            strassenabschnittToSplit.InspektionsRtStrAbschnitte.ForEach(s => s.InspektionsRouteGIS.AddStrassenabschnittGIS(copiedStrassenabschnittGIS2));
            strassenabschnittToSplit.InspektionsRtStrAbschnitte.ForEach(s => s.InspektionsRouteGIS.RemoveStrassenabschnittGIS(strassenabschnittToSplit));


            //5. save/delete splitted strassenabschnitte
            Delete(strassenabschnittToSplit);

            CreateEntity(copiedStrassenabschnittGIS1);
            CreateEntity(copiedStrassenabschnittGIS2);
        }
Exemplo n.º 25
0
        public void TestComputeZ()
        {
            var    linearGeom  = Read("LINESTRING (0 0 0, 10 10 10)");
            var    indexedLine = new LengthIndexedLine(linearGeom);
            double projIndex   = indexedLine.Project(new Coordinate(5, 5));
            var    projPt      = indexedLine.ExtractPoint(projIndex);

            //    System.out.println(projPt);
            Assert.That(projPt, Is.InstanceOf <CoordinateZ>());
            Assert.IsTrue(((CoordinateZ)projPt).Equals3D(new CoordinateZ(5, 5, 5)));
        }
Exemplo n.º 26
0
        /// <summary>
        /// return the coordinates along the gridProfile at stepSize intervals.
        /// </summary>
        /// <param name="gridProfile"></param>
        /// <param name="stepSize"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException">When <paramref name="stepSize"/> is 0.0 or less.</exception>
        public static IEnumerable<Coordinate> GetGridProfileCoordinates(ILineString gridProfile, double stepSize)
        {
            var lengthIndexedLine = new LengthIndexedLine(gridProfile);
            if (stepSize <= 0) throw new ArgumentException("Stepsize too small", "stepSize");

            var count = (int)((gridProfile.Length / stepSize) + 1);
            for (int i = 0; i < count; i++)
            {
                yield return (Coordinate)lengthIndexedLine.ExtractPoint(i * stepSize).Clone();
            }
        }
Exemplo n.º 27
0
        public void TestExtractPointBeyondRange()
        {
            var linearGeom  = Read("LINESTRING (0 0, 10 10)");
            var indexedLine = new LengthIndexedLine(linearGeom);
            var pt          = indexedLine.ExtractPoint(100);

            Assert.IsTrue(pt.Equals(new Coordinate(10, 10)));

            var pt2 = indexedLine.ExtractPoint(0);

            Assert.IsTrue(pt2.Equals(new Coordinate(0, 0)));
        }
Exemplo n.º 28
0
        private static void SplitBranchFeaturesWithLength(IBranch firstBranch, IBranch secondBranch)
        {
            var featuresToSplit = firstBranch.BranchFeatures.Where(f => f.Chainage + f.Length > firstBranch.Length).ToList();

            foreach (var branchFeature in featuresToSplit)
            {
                if (branchFeature.Geometry is IPoint)
                {
                    // A culvert has length, but it's geometry is a point. We're mixing Length propery meaning, but I'm not
                    // sure what the solution is. Fixing exception for now using this.
                    continue;
                }

                branchFeature.SetBeingMoved(true);

                var lengthFirstBranchFeature  = firstBranch.Length - branchFeature.Chainage;
                var lengthSecondBranchFeature = branchFeature.Length - lengthFirstBranchFeature;

                var firstBranchFeatureChainage = branchFeature.Chainage;
                var featureOnFirstBranch       = (lengthFirstBranchFeature >= lengthSecondBranchFeature);

                if (!featureOnFirstBranch)
                {
                    firstBranch.BranchFeatures.Remove(branchFeature);
                }

                var newBranchFeature = (IBranchFeature)Activator.CreateInstance(branchFeature.GetType());

                var firstBranchFeature  = featureOnFirstBranch ? branchFeature : newBranchFeature;
                var secondBranchFeature = featureOnFirstBranch ? newBranchFeature : branchFeature;

                var originalName      = branchFeature.Name;
                var lengthIndexedLine = new LengthIndexedLine(branchFeature.Geometry);
                var factor            = firstBranch.Geometry.Length / firstBranch.Length;

                firstBranchFeature.Length   = lengthFirstBranchFeature;
                firstBranchFeature.Name     = originalName + "_1";
                firstBranchFeature.Geometry = (IGeometry)lengthIndexedLine.ExtractLine(lengthIndexedLine.StartIndex, lengthFirstBranchFeature * factor).Clone();

                secondBranchFeature.Length   = lengthSecondBranchFeature;
                secondBranchFeature.Name     = originalName + "_2";
                secondBranchFeature.Geometry = (IGeometry)lengthIndexedLine.ExtractLine(lengthFirstBranchFeature * factor, lengthIndexedLine.EndIndex).Clone();

                AddBranchFeatureToBranch(secondBranchFeature, secondBranch, 0);

                if (!featureOnFirstBranch)
                {
                    AddBranchFeatureToBranch(firstBranchFeature, firstBranch, firstBranchFeatureChainage);
                }

                branchFeature.SetBeingMoved(false);
            }
        }
Exemplo n.º 29
0
        private void UpdateGeometry()
        {
            if (Branch == null || Branch.Geometry == null)
            {
                return;
            }

            var lengthIndexedLine = new LengthIndexedLine(Branch.Geometry);

            // thousand bombs and granates: ExtractPoint will give either a new coordinate or
            // a reference to an existing object
            Geometry = new Point((ICoordinate)lengthIndexedLine.ExtractPoint(Offset).Clone());
        }
Exemplo n.º 30
0
        private void UpdateGeometry()
        {
            if (Branch == null || Branch.Geometry == null)
            {
                return;
            }

            var lengthIndexedLine = new LengthIndexedLine(Branch.Geometry);

            var offset = Branch.IsLengthCustom ? (Branch.Geometry.Length / Branch.Length) * Offset : Offset;

            // always clone: ExtractPoint will give either a new coordinate or a reference to an existing object
            Geometry = new Point((ICoordinate)lengthIndexedLine.ExtractPoint(offset).Clone());
        }