예제 #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);
 }
예제 #3
0
        public static Geometry[] GetResult(string wkt, double tolerance)
        {
            var ioGeom = new Geometry[2];

            ioGeom[0] = Rdr.Read(wkt);
            ioGeom[1] = TopologyPreservingSimplifier.Simplify(ioGeom[0], tolerance);
            //System.Console.WriteLine(Console.WriteLine(ioGeom[1]);
            return(ioGeom);
        }
예제 #4
0
 /// <summary>
 /// Simplifies the line with the given tolerance.
 /// Writes the result in file.
 /// </summary>
 /// <param name="line">Line to simplify</param>
 /// <param name="tolerance">Tolerance to use by simplify function</param>
 /// <param name="supposedResult">The supposed result</param>
 /// <param name="index"></param>
 public void Simplify(LineString line, double tolerance, LineString supposedResult, int index)
 {
     try
     {
         Console.WriteLine("Job {0} started", index);
         var geometry = TopologyPreservingSimplifier.Simplify((LineString)line.Copy(), tolerance);
         Assert.IsTrue(geometry.Equals(supposedResult));
         Console.WriteLine("Job {0} terminated", index);
     }
     finally
     {
         Interlocked.Increment(ref _finishedJob);
     }
 }
        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));
        }
예제 #6
0
        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));
 }