Esempio n. 1
0
        public static List <SqlGeometry> Simplify(
            this List <SqlGeometry> geometries
            , SimplificationType type
            , int zoomLevel
            //bool retain3Points,
            , SimplificationParamters paramters
            , bool reduceToPoint = true
            //double averageLatitude = 35,
            //double angleThreshold = .98
            )
        {
            try
            {
                Debug.WriteLine($"SIMPLIFY MEHTOD START FOR Z:{zoomLevel}, COUNT OF GEOMETRIES:{geometries?.Count}");

                if (geometries == null)
                {
                    return(null);
                }

                var threshold = IRI.Msh.Common.Mapping.WebMercatorUtility.CalculateGroundResolution(zoomLevel, paramters.AverageLatitude ?? 0); //0 seconds!

                //watch.Stop();
                //System.Diagnostics.Debug.WriteLine($"CALCULATE threshold {watch.ElapsedMilliseconds / 1000} s", "PYRAMID");
                //watch.Restart();

                var areaThreshold = threshold * threshold;

                var result = new List <SqlGeometry>(); //0 seconds!

                //watch.Stop();
                //System.Diagnostics.Debug.WriteLine($"CREATE EMPTY LIST {watch.ElapsedMilliseconds / 1000} s", "PYRAMID");
                //watch.Restart();

                Stopwatch watch = Stopwatch.StartNew();


                for (int i = 0; i < geometries.Count; i++)
                {
                    try
                    {
                        result.Add(geometries[i].Simplify(type, paramters));
                        //result.Add(FilterPoints(geometries[i], filter));
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }

                watch.Stop();
                var tSimplify = watch.ElapsedMilliseconds / 1000; // System.Diagnostics.Debug.WriteLine($"CALL PROCESS {watch.ElapsedMilliseconds / 1000} s", "PYRAMID");
                watch.Restart();

                result = result.Select(i => i.MakeValid()).Where(i => !i.IsNullOrEmpty()).ToList();   //0 seconds!

                //watch.Stop();
                //System.Diagnostics.Debug.WriteLine($"FILTERING INVALID RESULTS {watch.ElapsedMilliseconds / 1000} s", "PYRAMID");
                //watch.Restart();

                ///////////////////////////////////////////////////////////*********************************
                if (reduceToPoint)
                {
                    for (int g = 0; g < result.Count; g++)
                    {
                        try
                        {
                            var length = result[g].STLength().Value;

                            if (length < threshold)
                            {
                                result[g] = result[g].STPointOnSurface();
                            }
                        }
                        catch (Exception ex)
                        {
                            throw;
                        }
                    }
                    //*********************************** 0-1 second //////////////////////////////////////////

                    //watch.Stop();
                    //System.Diagnostics.Debug.WriteLine($"CONVERT TO POINT {watch.ElapsedMilliseconds / 1000} s", "PYRAMID");
                    //watch.Restart();

                    var tMid = watch.ElapsedMilliseconds / 100;

                    watch.Restart();

                    result = result.RemoveOverlappingPoints(threshold);

                    watch.Stop();
                    var tRemovePoints = watch.ElapsedMilliseconds / 1000;
                    Debug.WriteLine($"Total:{tSimplify + tMid + tRemovePoints}, Simplify: {tSimplify}, RemoveExteraPoints: {tRemovePoints}", "PYRAMID");
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geometry"></param>
        /// <param name="threshold"></param>
        /// <param name="type"></param>
        /// <param name="areaThreshold"></param>
        /// <returns></returns>
        public static SqlGeometry Simplify(this SqlGeometry geometry, SimplificationType type, SimplificationParamters parameters /*double threshold,  bool retain3Points, double areaThreshold = double.NaN*/)
        {
            if (geometry.IsNotValidOrEmpty())
            {
                return(geometry);
            }

            var extractedGeometry = geometry.AsGeometry();

            var filteredGeometry = extractedGeometry.Simplify(type, parameters);

            return(filteredGeometry.AsSqlGeometry().MakeValid());

            //switch (type)
            //{
            //    case SimplificationType.ByArea:
            //        return FilterPoints(geometry, pList => IRI.Msh.Common.Analysis.VisualSimplification.SimplifyByArea(pList, threshold));

            //    case SimplificationType.AdditiveByArea:
            //        return FilterPoints(geometry, pList => IRI.Msh.Common.Analysis.VisualSimplification.AdditiveSimplifyByArea(pList, threshold));

            //    case SimplificationType.AdditiveByAreaPlus:
            //        return FilterPoints(geometry, pList => IRI.Msh.Common.Analysis.VisualSimplification.AdditiveSimplifyByAreaPlus(pList, threshold));

            //    case SimplificationType.ByAngle:
            //        return FilterPoints(geometry, pList => IRI.Msh.Common.Analysis.VisualSimplification.SimplifyByAngle(pList, threshold));

            //    case SimplificationType.AdditiveByAngle:
            //        return FilterPoints(geometry, pList => IRI.Msh.Common.Analysis.VisualSimplification.AdditiveSimplifyByAngle(pList, threshold));

            //    case SimplificationType.AdditiveByDistance:
            //        return FilterPoints(geometry, pList => IRI.Msh.Common.Analysis.VisualSimplification.AdditiveSimplifyByDistance(pList, threshold));

            //    case SimplificationType.AdditiveByAreaAngle:
            //        return FilterPoints(geometry, pList => IRI.Msh.Common.Analysis.VisualSimplification.AdditiveSimplifyByAngleArea(pList, threshold, areaThreshold));

            //    default:
            //        throw new NotImplementedException();
            //}
        }