示例#1
0
        public void TestRun()
        {
            const double Tolerance = 0.0005;
            const int    Max       = 100;

            _finishedJob = 0;

            try
            {
                var line = Helper.GetLine(Encoded);
                var res  = (LineString)TopologyPreservingSimplifier.Simplify(line, Tolerance);
                Simplify(line, Tolerance, res, 0);

                for (int i = 1; i <= Max; i++)
                {
                    int          index    = i;
                    WaitCallback callback = delegate { Simplify(line, Tolerance, res, index); };
                    ThreadPool.QueueUserWorkItem(callback);
                }

                do
                {
                    Thread.Sleep(50);
                }while (_finishedJob < Max);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
 public static IGeometry[] GetResult(String wkt, double tolerance)
 {
     IGeometry[] ioGeom = new IGeometry[2];
     ioGeom[0] = Rdr.Read(wkt);
     ioGeom[1] = TopologyPreservingSimplifier.Simplify(ioGeom[0], tolerance);
     Console.WriteLine(ioGeom[1]);
     return(ioGeom);
 }
        public async Task <IHttpActionResult> GetAll(string modelId, int projectId, int caseId, int zoom, string bbox)
        {
            var tolerance = res[zoom] * 2;

            var bboxParts = bbox.Split(',')
                            .Take(4)
                            .Select(v =>
            {
                double d = double.NaN;
                double.TryParse(v, NumberStyles.Any, CultureInfo.InvariantCulture, out d);
                return(d);
            })
                            .ToArray();

            if (bboxParts.Count(v => !double.IsNaN(v)) != 4 || bboxParts[0] >= bboxParts[2] || bboxParts[1] >= bboxParts[3])
            {
                return(BadRequest("bounding box is invalid"));
            }

            var bboxPartsAsString = bboxParts.Select(v => v.ToString(CultureInfo.InvariantCulture)).ToArray();

            var bboxGeometry = DbGeometry.FromText(System.String.Format("POLYGON (({0} {1}, {2} {1}, {2} {3}, {0} {3}, {0} {1}))", bboxPartsAsString));

            var selections = (await db.Exceptions
                              .Where(e => e.CaseId == caseId)
                              .ToArrayAsync())
                             .Select(e =>
            {
                e.area = (e.geo.Area.HasValue) ? e.geo.Area.Value : 0.0;
                e.bbox = e.geo.Envelope;
                e.geo  = e.geo.Intersects(bboxGeometry)
                                                ? zoom > 8
                                                        ? e.geo
                                                        : DbGeometry.FromBinary(TopologyPreservingSimplifier.Simplify(new WKTReader().Read(e.geo.AsText()), tolerance).AsBinary())
                                         : e.geo.Envelope;
                return(e);
            });

            return(Ok(selections));
        }
示例#4
0
        /// <summary>
        /// Simplifies a geometry using the Douglas Peucker algorithm.
        /// </summary>
        /// <param name="way">
        ///            the way </param>
        /// <param name="geometry">
        ///            the geometry </param>
        /// <param name="zoomlevel">
        ///            the zoom level </param>
        /// <param name="simplificationFactor">
        ///            the simplification factor </param>
        /// <returns> the simplified geometry </returns>
        public static Geometry simplifyGeometry(TDWay way, Geometry geometry, sbyte zoomlevel, int tileSize, double simplificationFactor)
        {
            Geometry ret = null;

            Envelope bbox = geometry.EnvelopeInternal;
            // compute maximal absolute latitude (so that we don't need to care if we
            // are on northern or southern hemisphere)
            double latMax   = Math.Max(Math.Abs(bbox.MaxY), Math.Abs(bbox.MinY));
            double deltaLat = deltaLat(simplificationFactor, latMax, zoomlevel, tileSize);

            try
            {
                ret = TopologyPreservingSimplifier.simplify(geometry, deltaLat);
            }
            catch (TopologyException e)
            {
                LOGGER.log(Level.FINE, "JTS cannot simplify way due to an error, not simplifying way with id: " + way.Id, e);
                way.Invalid = true;
                return(geometry);
            }

            return(ret);
        }
        private static IGeometry Simplify(this IGeometry geometry)
        {
            // Simplify the geometry.
            if (geometry.Area < 0.1)
            {
                // For very small regions, use a convex hull.
                return(geometry.ConvexHull());
            }

            // Simplify the polygon.
            var tolerance = 0.05;

            while (true)
            {
                var result = TopologyPreservingSimplifier.Simplify(geometry, tolerance);
                if (result is Polygon && result.IsValid && !result.IsEmpty)
                {
                    return(result);
                }

                // Reduce the tolerance incrementally until we have a valid polygon.
                tolerance -= 0.005;
            }
        }
 public static IGeometry simplifyTP(IGeometry g, double distance)
 {
     return(TopologyPreservingSimplifier.Simplify(g, distance));
 }