public static Geometry ToLines(Geometry g1, Geometry g2)
        {
            var geoms = FunctionsUtil.BuildGeometry(g1, g2);

            return(FunctionsUtil.GetFactoryOrDefault(new[] { g1, g2 })
                   .BuildGeometry(LinearComponentExtracter.GetLines(geoms)));
        }
        private static Geometry polygonize(Geometry g, bool extractOnlyPolygonal)
        {
            var lines       = LinearComponentExtracter.GetLines(g);
            var polygonizer = new Polygonizer(extractOnlyPolygonal);

            polygonizer.Add(lines);
            return(polygonizer.GetGeometry());
        }
            private void Init(IGeometry geom)
            {
                var lines = LinearComponentExtracter.GetLines(geom);

                foreach (ILineString line in lines)
                {
                    Coordinate[] pts = line.Coordinates;
                    AddLine(pts);
                }
            }
        /// <summary>
        /// Gets the computed offset points.
        /// </summary>
        public List<Coordinate> GetPoints(double offsetDistance)
        {
            var offsetPts = new List<Coordinate>();
            var lines = LinearComponentExtracter.GetLines(_g);
            foreach (ILineString line in lines)
                ExtractPoints(line, offsetDistance, offsetPts);

            //System.out.println(toMultiPoint(offsetPts));
            return offsetPts;
        }
        private static List <ISegmentString> CreateSegmentStrings(Geometry geom)
        {
            var segs  = new List <ISegmentString>();
            var lines = LinearComponentExtracter.GetLines(geom);

            foreach (LineString line in lines)
            {
                segs.Add(new BasicSegmentString(line.Coordinates, null));
            }
            return(segs);
        }
Ejemplo n.º 6
0
        private static IEnumerable <IGeometry> ExtractLines(IEnumerable <IGeometry> geoms)
        {
            var lines = new List <IGeometry>();
            var lce   = new LinearComponentExtracter(lines);

            foreach (var geom in geoms)
            {
                geom.Apply(lce);
            }
            return(lines);
        }
Ejemplo n.º 7
0
        private static IList <Segment> CreateConstraintSegments(IGeometry geom)
        {
            ICollection <IGeometry> lines          = LinearComponentExtracter.GetLines(geom);
            List <Segment>          constraintSegs = new List <Segment>();

            foreach (IGeometry line in lines)
            {
                CreateConstraintSegments((ILineString)line, constraintSegs);
            }
            return(constraintSegs);
        }
Ejemplo n.º 8
0
        ///<summary>
        /// Extracts all linear components from a given <see cref="IGeometry"/>
        /// to <see cref="ISegmentString"/>s.
        /// The <see cref="ISegmentString"/> data item is set to be the source <see cref="IGeometry"/>.
        /// </summary>
        /// <param name="geom">The <see cref="IGeometry"/> to extract from.</param>
        /// <returns>a list of <see cref="ISegmentString"/>s.</returns>
        public static IList <ISegmentString> ExtractNodedSegmentStrings(IGeometry geom)
        {
            var segStr = new List <ISegmentString>();
            var lines  = LinearComponentExtracter.GetLines(geom);

            foreach (IGeometry line in lines)
            {
                Coordinate[] pts = line.Coordinates;
                segStr.Add(new NodedSegmentString(pts, geom));
            }
            return(segStr);
        }
Ejemplo n.º 9
0
        private static Geometry GetPolygonLines(Geometry g)
        {
            var lines         = new List <Geometry>();
            var lineExtracter = new LinearComponentExtracter(lines);
            var polys         = PolygonExtracter.GetPolygons(g);

            foreach (var poly in polys)
            {
                poly.Apply(lineExtracter);
            }
            return(g.Factory.BuildGeometry(polys));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Computes simplicity for polygonal geometries.
        /// Polygonal geometries are simple if and only if
        /// all of their component rings are simple.
        /// </summary>
        /// <param name="geom">A Polygonal geometry</param>
        /// <returns><c>true</c> if the geometry is simple</returns>
        private bool IsSimplePolygonal(Geometry geom)
        {
            var rings = LinearComponentExtracter.GetLines(geom);

            foreach (LinearRing ring in rings)
            {
                if (!IsSimpleLinearGeometry(ring))
                {
                    return(false);
                }
            }
            return(true);
        }
        private static Geometry Polygonize(Geometry g, bool extractOnlyPolygonal)
        {
            var lines       = LinearComponentExtracter.GetLines(g);
            var polygonizer = new Polygonizer(extractOnlyPolygonal);

            polygonizer.Add(lines);
            return(polygonizer.GetGeometry());

            /*
             * Collection polys = polygonizer.getPolygons();
             * Polygon[] polyArray = GeometryFactory.toPolygonArray(polys);
             * return g.getFactory().createGeometryCollection(polyArray);
             */
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="geom"></param>
        private void ComputeSegmentIntersection(IGeometry geom)
        {
            // check segment intersection
            // get all lines from geom (e.g. if it's a multi-ring polygon)
            IList lines = LinearComponentExtracter.GetLines(geom);
            SegmentIntersectionTester si = new SegmentIntersectionTester();
            bool hasIntersection         = si.HasIntersectionWithLineStrings(rectSeq, lines);

            if (hasIntersection)
            {
                intersects = true;
                return;
            }
        }
Ejemplo n.º 13
0
        public static Geometry ExtractChains(Geometry g, int maxChainSize)
        {
            var lines  = LinearComponentExtracter.GetLines(g);
            var chains = new List <Geometry>();

            foreach (LineString line in lines)
            {
                for (int i = 0; i < line.NumPoints - 1; i += maxChainSize)
                {
                    var chain = ExtractChain(line, i, maxChainSize);
                    chains.Add(chain);
                }
            }
            return(g.Factory.BuildGeometry(chains));
        }
Ejemplo n.º 14
0
        private static Geometry BuildBufferLineSimplifiedSet(Geometry g, double distance)
        {
            var simpLines = new List <Geometry>();

            var lines = LinearComponentExtracter.GetLines(g);

            foreach (var line in lines)
            {
                var pts = line.Coordinates;
                simpLines.Add(g.Factory.CreateLineString(BufferInputLineSimplifier.Simplify(pts, distance)));
            }
            var simpGeom = g.Factory.BuildGeometry(simpLines);

            return(simpGeom);
        }
Ejemplo n.º 15
0
        private void Extract(IGeometry geom)
        {
            if (_geomFact == null)
            {
                _geomFact = geom.Factory;
            }

            /*
             * PolygonExtracter.getPolygons(geom, polygons);
             * LineStringExtracter.getLines(geom, lines);
             * PointExtracter.getPoints(geom, points);
             */
            _polygons.AddRange(PolygonExtracter.GetPolygons(geom).Cast <IPolygon>());
            _lines.AddRange(LinearComponentExtracter.GetLines(geom).Cast <ILineString>());
            _points.AddRange(PointExtracter.GetPoints(geom).Cast <IPoint>());
        }
Ejemplo n.º 16
0
        private static IGeometry GetPolygonLines(IGeometry g)
        {
            var lines         = new List <IGeometry>();
            var lineExtracter = new LinearComponentExtracter(lines);
            var polys         = PolygonExtracter.GetPolygons(g);

            foreach (var poly in polys)
            {
                poly.Apply(lineExtracter);
            }
            return(g.Factory.BuildGeometry(polys));

            /*
             * return g.Factory.BuildGeometry(new List<IGeometry>(
             *  Gisoft.GeoAPI.DataStructures.Caster.Cast<IGeometry>(polys)));
             */
        }
Ejemplo n.º 17
0
        public static Geometry ExtractSegments(Geometry g)
        {
            var lines    = LinearComponentExtracter.GetLines(g);
            var segments = new List <Geometry>();

            foreach (LineString line in lines)
            {
                for (int i = 1; i < line.NumPoints; i++)
                {
                    var seg = g.Factory.CreateLineString(
                        new[] { line.GetCoordinateN(i - 1), line.GetCoordinateN(i) }
                        );
                    segments.Add(seg);
                }
            }
            return(g.Factory.BuildGeometry(segments));
        }
Ejemplo n.º 18
0
        /*
         * /// <summary>
         * ///
         * /// </summary>
         * /// <param name="locs"></param>
         * /// <param name="polys"></param>
         * /// <param name="locPtPoly"></param>
         * private void ComputeInside(IEnumerable<GeometryLocation> locs, IEnumerable<IPolygon> polys, GeometryLocation[] locPtPoly)
         * {
         *  foreach (GeometryLocation loc in locs)
         *  {
         *      foreach (IPolygon poly in polys)
         *      {
         *          ComputeInside(loc, poly, locPtPoly);
         *          if (_minDistance <= _terminateDistance)
         *              return;
         *      }
         *  }
         * }
         *
         * /// <summary>
         * ///
         * /// </summary>
         * /// <param name="ptLoc"></param>
         * /// <param name="poly"></param>
         * /// <param name="locPtPoly"></param>
         * private void ComputeInside(GeometryLocation ptLoc, IPolygon poly, GeometryLocation[] locPtPoly)
         * {
         *  Coordinate pt = ptLoc.Coordinate;
         *  // if pt is not in exterior, distance to geom is 0
         *  if (Location.Exterior != _ptLocator.Locate(pt, poly))
         *  {
         *      _minDistance = 0.0;
         *      locPtPoly[0] = ptLoc;
         *      GeometryLocation locPoly = new GeometryLocation(poly, pt);
         *      locPtPoly[1] = locPoly;
         *      return;
         *  }
         * }
         *
         */

        /// <summary>
        /// Computes distance between facets (lines and points) of input geometries.
        /// </summary>
        private void ComputeFacetDistance()
        {
            var locGeom = new GeometryLocation[2];

            /*
             * Geometries are not wholely inside, so compute distance from lines and points
             * of one to lines and points of the other
             */
            var lines0 = LinearComponentExtracter.GetLines(_geom[0]);
            var lines1 = LinearComponentExtracter.GetLines(_geom[1]);

            var pts0 = PointExtracter.GetPoints(_geom[0]);
            var pts1 = PointExtracter.GetPoints(_geom[1]);

            // exit whenever minDistance goes LE than terminateDistance
            ComputeMinDistanceLines(lines0, lines1, locGeom);
            UpdateMinDistance(locGeom, false);
            if (_minDistance <= _terminateDistance)
            {
                return;
            }

            locGeom[0] = null;
            locGeom[1] = null;
            ComputeMinDistanceLinesPoints(lines0, pts1, locGeom);
            UpdateMinDistance(locGeom, false);
            if (_minDistance <= _terminateDistance)
            {
                return;
            }

            locGeom[0] = null;
            locGeom[1] = null;
            ComputeMinDistanceLinesPoints(lines1, pts0, locGeom);
            UpdateMinDistance(locGeom, true);
            if (_minDistance <= _terminateDistance)
            {
                return;
            }

            locGeom[0] = null;
            locGeom[1] = null;
            ComputeMinDistancePoints(pts0, pts1, locGeom);
            UpdateMinDistance(locGeom, false);
        }
Ejemplo n.º 19
0
        /// <summary>
        ///
        /// </summary>
        private void ComputeLineDistance()
        {
            GeometryLocation[] locGeom = new GeometryLocation[2];

            /*
             * Geometries are not wholely inside, so compute distance from lines and points
             * of one to lines and points of the other
             */
            IList lines0 = LinearComponentExtracter.GetLines(geom[0]);
            IList lines1 = LinearComponentExtracter.GetLines(geom[1]);

            IList pts0 = PointExtracter.GetPoints(geom[0]);
            IList pts1 = PointExtracter.GetPoints(geom[1]);

            // bail whenever minDistance goes to zero, since it can't get any less
            ComputeMinDistanceLines(lines0, lines1, locGeom);
            UpdateMinDistance(locGeom, false);
            if (minDistance <= terminateDistance)
            {
                return;
            }

            locGeom[0] = null;
            locGeom[1] = null;
            ComputeMinDistanceLinesPoints(lines0, pts1, locGeom);
            UpdateMinDistance(locGeom, false);
            if (minDistance <= terminateDistance)
            {
                return;
            }

            locGeom[0] = null;
            locGeom[1] = null;
            ComputeMinDistanceLinesPoints(lines1, pts0, locGeom);
            UpdateMinDistance(locGeom, true);
            if (minDistance <= terminateDistance)
            {
                return;
            }

            locGeom[0] = null;
            locGeom[1] = null;
            ComputeMinDistancePoints(pts0, pts1, locGeom);
            UpdateMinDistance(locGeom, false);
        }
        private static List <LineSegment> ExtractSegmentsNorm(Geometry geom)
        {
            var segs  = new List <LineSegment>();
            var lines = LinearComponentExtracter.GetLines(geom);

            foreach (var line in lines)
            {
                var pts = line.Coordinates;
                for (int i = 0; i < pts.Length - 1; i++)
                {
                    var seg = new LineSegment(pts[i], pts[i + 1]);
                    seg.Normalize();
                    segs.Add(seg);
                }
            }

            return(segs);
        }
        private static IGeometry ExtractLines(ICollection <IGeometry> geoms)
        {
            IGeometryFactory factory = null;
            var lines = new List <IGeometry>();

            foreach (var g in geoms)
            {
                if (factory == null)
                {
                    factory = g.Factory;
                }
                var coll = LinearComponentExtracter.GetLines(g);
                lines.AddRange(coll);
            }

            if (factory == null)
            {
                return(null);
            }
            return(factory.BuildGeometry(geoms));
        }
Ejemplo n.º 22
0
        protected override void Visit(IGeometry geom)
        {
            /**
             * It may be the case that the rectangle and the
             * envelope of the geometry component are disjoint,
             * so it is worth checking this simple condition.
             */
            var elementEnv = geom.EnvelopeInternal;

            if (!_rectEnv.Intersects(elementEnv))
            {
                return;
            }

            // check segment intersections
            // get all lines from geometry component
            // (there may be more than one if it's a multi-ring polygon)
            var lines = LinearComponentExtracter.GetLines(geom);

            CheckIntersectionWithLineStrings(lines);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Nodes the linework of a set of Geometrys using SnapRounding.
        /// </summary>
        /// <param name="geoms">A collection of Geometrys of any type</param>
        /// <returns>A list of LineStrings representing the noded linework of the input</returns>
        public ReadOnlyCollection <LineString> Node(IEnumerable <Geometry> geoms)
        {
            // get geometry factory
            // DEVIATION: JTS uses an "ExtractLines" helper, but by inlining it,
            // we can make the parameter any ol' IEnumerable<Geometry> without
            // iterating over it multiple times.
            var  lines = new List <Geometry>();
            var  lce   = new LinearComponentExtracter(lines);
            bool first = true;

            foreach (var g in geoms)
            {
                if (first)
                {
                    _geomFact = g.Factory;
                    first     = false;
                }

                g.Apply(lce);
            }

            var segStrings = ToSegmentStrings(lines);
            //Noder sr = new SimpleSnapRounder(pm);
            var sr = new MCIndexSnapRounder(_pm);

            sr.ComputeNodes(segStrings);
            var nodedLines = sr.GetNodedSubstrings();

            //TODO: improve this to check for full snap-rounded correctness
            if (IsValidityChecked)
            {
                var nv = new NodingValidator(nodedLines);
                nv.CheckValid();
            }

            return(ToLineStrings(nodedLines));
        }
Ejemplo n.º 24
0
 public static IGeometry toLines(IGeometry g)
 {
     return(g.Factory.BuildGeometry(LinearComponentExtracter.GetLines(g)));
 }
Ejemplo n.º 25
0
        public static IGeometry ExtractLines(IGeometry g)
        {
            ICollection <IGeometry> lines = LinearComponentExtracter.GetLines(g);

            return(g.Factory.BuildGeometry(lines));
        }
Ejemplo n.º 26
0
        public static Geometry ExtractLines(Geometry g)
        {
            var lines = LinearComponentExtracter.GetLines(g);

            return(g.Factory.BuildGeometry(lines));
        }
        public static IGeometry extractLines(IGeometry g)
        {
            var lines = LinearComponentExtracter.GetLines(g);

            return(g.Factory.BuildGeometry(NetTopologySuite.Utilities.CollectionUtil.Cast <IGeometry>((ICollection)lines)));
        }