Example #1
0
        private void ComputeContainmentDistance(int polyGeomIndex, GeometryLocation[] locPtPoly)
        {
            var polyGeom = _geom[polyGeomIndex];

            // if no polygon then nothing to do
            if (polyGeom.Dimension < Dimension.Surface)
            {
                return;
            }

            int locationsIndex = 1 - polyGeomIndex;
            var polys          = PolygonExtracter.GetPolygons(polyGeom);

            if (polys.Count > 0)
            {
                var insideLocs = ConnectedElementLocationFilter.GetLocations(_geom[locationsIndex]);
                ComputeContainmentDistance(insideLocs, polys, locPtPoly);
                if (_minDistance <= _terminateDistance)
                {
                    // this assigment is determined by the order of the args in the computeInside call above
                    _minDistanceLocation[locationsIndex] = locPtPoly[0];
                    _minDistanceLocation[polyGeomIndex]  = locPtPoly[1];
                }
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        private void ComputeContainmentDistance()
        {
            IList polys0 = PolygonExtracter.GetPolygons(geom[0]);
            IList polys1 = PolygonExtracter.GetPolygons(geom[1]);

            GeometryLocation[] locPtPoly = new GeometryLocation[2];
            // test if either point is wholely inside the other
            if (polys1.Count > 0)
            {
                IList insideLocs0 = ConnectedElementLocationFilter.GetLocations(geom[0]);
                ComputeInside(insideLocs0, polys1, locPtPoly);
                if (minDistance <= terminateDistance)
                {
                    minDistanceLocation[0] = locPtPoly[0];
                    minDistanceLocation[1] = locPtPoly[1];
                    return;
                }
            }
            if (polys0.Count > 0)
            {
                IList insideLocs1 = ConnectedElementLocationFilter.GetLocations(geom[1]);
                ComputeInside(insideLocs1, polys0, locPtPoly);
                if (minDistance <= terminateDistance)
                {
                    // flip locations, since we are testing geom 1 VS geom 0
                    minDistanceLocation[0] = locPtPoly[1];
                    minDistanceLocation[1] = locPtPoly[0];
                    return;
                }
            }
        }
Example #3
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));
        }
        private static void InsertPolys(Geometry geom, Quadtree <Geometry> tree)
        {
            if (geom.IsEmpty)
            {
                return;
            }
            var polyList = PolygonExtracter.GetPolygons(geom);

            foreach (var poly in polyList)
            {
                tree.Insert(poly.EnvelopeInternal, poly);
            }
        }
        /// <summary> Computes a <see cref="IGeometry"/> containing only <see cref="IPolygonal"/> components.
        /// Extracts the <see cref="IPolygon"/>s from the input
        /// and returns them as an appropriate <see cref="IPolygonal"/> geometry.
        /// <para/>
        /// If the input is already <tt>Polygonal</tt>, it is returned unchanged.
        /// <para/>
        /// A particular use case is to filter out non-polygonal components
        /// returned from an overlay operation.
        /// </summary>
        /// <param name="g">The geometry to filter</param>
        /// <returns>A polygonal geometry</returns>
        private static IGeometry RestrictToPolygons(IGeometry g)
        {
            if (g is IPolygonal)
            {
                return(g);
            }

            var polygons = PolygonExtracter.GetPolygons(g);

            if (polygons.Count == 1)
            {
                return /*(IPolygon)*/ (polygons[0]);
            }
            return(g.Factory.CreateMultiPolygon(GeometryFactory.ToPolygonArray(polygons)));
        }
Example #6
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>());
        }
        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)));
             */
        }
        /// <summary> Computes a <see cref="Geometry"/> containing only <see cref="IPolygonal"/> components.
        /// Extracts the <see cref="Polygon"/>s from the input
        /// and returns them as an appropriate <see cref="IPolygonal"/> geometry.
        /// <para/>
        /// If the input is already <tt>Polygonal</tt>, it is returned unchanged.
        /// <para/>
        /// A particular use case is to filter out non-polygonal components
        /// returned from an overlay operation.
        /// </summary>
        /// <param name="g">The geometry to filter</param>
        /// <returns>A polygonal geometry</returns>
        private static Geometry RestrictToPolygons(Geometry g)
        {
            if (g is IPolygonal)
            {
                return(g);
            }

            var polygons = PolygonExtracter.GetPolygons(g);

            if (polygons.Count == 1)
            {
                return(polygons[0]);
            }
            var array = GeometryFactory.ToPolygonArray(polygons);

            return(g.Factory.CreateMultiPolygon(array));
        }
Example #9
0
        private void LoadClick(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog();

            dialog.Filter = "NTS Geometry File|*.nts";
            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.OpenFile())
                {
                    var reader = new WKTReader();
                    try
                    {
                        var geom = reader.Read(stream);
                        if (geom != null && !geom.IsEmpty)
                        {
                            var polygons = PolygonExtracter.GetPolygons(geom).OfType <Polygon>().Select(p => new DrawingPolygon(p));
                            foreach (var polygon in polygons)
                            {
                                polygon.Render(DrawingCanvas.DefaultPen);
                                canvas.AddVisual(polygon);
                            }

                            var lineStrings = LineStringExtracter.GetLines(geom).OfType <LineString>().Select(p => new DrawingLineString(p));
                            foreach (var lineString in lineStrings)
                            {
                                lineString.Render(DrawingCanvas.DefaultPen);
                                canvas.AddVisual(lineString);
                            }

                            var points = PointExtracter.GetPoints(geom).OfType <NetTopologySuite.Geometries.Point>()
                                         .Select(p => new DrawingPoint(new System.Windows.Point(p.X, p.Y)));
                            foreach (var point in points)
                            {
                                point.Render(DrawingCanvas.DefaultPen);
                                canvas.AddVisual(point);
                            }
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Read failed! The file may have been corrupted!");
                    }
                }
            }
        }
        private static List <Polygon> ExtractPolygonsNonEmpty(IEnumerable <Geometry> geoms)
        {
            var exPolys = new List <Polygon>();

            foreach (var geom in geoms)
            {
                if (!geom.IsEmpty)
                {
                    if (geom is Polygon)
                    {
                        exPolys.Add((Polygon)geom);
                    }
                    else if (geom is MultiPolygon)
                    {
                        exPolys.AddRange(PolygonExtracter.GetPolygons(geom).Cast <Polygon>());
                    }
                }
            }
            return(exPolys);
        }
        private static Geometry Overlay(Geometry coll, bool useNG, PrecisionModel pm)
        {
            var result = new List <Geometry>();

            for (int i = 0; i < coll.NumGeometries; i++)
            {
                var inGeom = coll.GetGeometryN(i);

                int size = result.Count;
                for (int j = 0; j < size; j++)
                {
                    var resGeom = result[j];
                    if (resGeom.IsEmpty)
                    {
                        continue;
                    }

                    var intGeom = ExtractPolygons(OverlayIntersection(resGeom, inGeom, useNG, pm));
                    if (!intGeom.IsEmpty)
                    {
                        result.Add(intGeom);

                        var resDiff = ExtractPolygons(OverlayDifference(resGeom, intGeom, useNG, pm));
                        result[j] = resDiff;

                        inGeom = ExtractPolygons(OverlayDifference(inGeom, intGeom, useNG, pm));
                    }
                }
                // keep remainder of input (non-overlapped part)
                if (!inGeom.IsEmpty)
                {
                    result.AddRange(PolygonExtracter.GetPolygons(inGeom));
                    //result.add( inGeom );
                }
            }
            // TODO: return only non-empty polygons
            var resultPolys = ExtractPolygonsNonEmpty(result);

            return(coll.Factory.BuildGeometry(resultPolys));
        }
        private static Geometry OverlayIndexed(Geometry coll, bool useNG, PrecisionModel pm)
        {
            var tree = new Quadtree <Geometry>();

            for (int i = 0; i < coll.NumGeometries; i++)
            {
                var inGeom  = coll.GetGeometryN(i);
                var results = tree.Query(inGeom.EnvelopeInternal);

                foreach (var resPoly in results)
                {
                    var intGeom = ExtractPolygons(OverlayIntersection(resPoly, inGeom, useNG, pm));
                    var intList = PolygonExtracter.GetPolygons(intGeom);

                    // resultant is overlapped by next input
                    if (!intGeom.IsEmpty && intList.Count > 0)
                    {
                        tree.Remove(resPoly.EnvelopeInternal, resPoly);

                        foreach (var intPoly in intList)
                        {
                            tree.Insert(intPoly.EnvelopeInternal, intPoly);
                            var resDiff = OverlayDifference(resPoly, intGeom, useNG, pm);
                            InsertPolys(resDiff, tree);

                            inGeom = ExtractPolygons(OverlayDifference(inGeom, intPoly, useNG, pm));
                        }
                    }
                }
                // keep remainder of input
                InsertPolys(inGeom, tree);
            }
            var result = tree.QueryAll();

            return(coll.Factory.BuildGeometry(result));
        }
        private static Geometry ExtractPolygons(Geometry geom)
        {
            var polys = PolygonExtracter.GetPolygons(geom);

            return(geom.Factory.BuildGeometry(polys));
        }