public void SimplifyClick(Map map, GeoCollection <object> args) { if (null == areaBaseShape) { areaBaseShape = ((InMemoryFeatureLayer)map.StaticOverlay.Layers["SimplificationLayer"]).InternalFeatures[0].GetShape() as AreaBaseShape; } string toleranceString = args[0] as string; string simplificationTypeString = args[1] as string; InMemoryFeatureLayer simplificationLayer = (InMemoryFeatureLayer)map.StaticOverlay.Layers["SimplificationLayer"]; double tolerance = Convert.ToDouble(toleranceString, CultureInfo.InvariantCulture); SimplificationType simplificationType = SimplificationType.DouglasPeucker; switch (simplificationTypeString) { case "TopologyPreserving": simplificationType = SimplificationType.TopologyPreserving; break; case "DouglasPeucker": simplificationType = SimplificationType.DouglasPeucker; break; } MultipolygonShape multipolygonShape = areaBaseShape.Simplify(tolerance, simplificationType); simplificationLayer.InternalFeatures.Clear(); simplificationLayer.InternalFeatures.Add(new Feature(multipolygonShape)); }
/// <summary> /// Recalculates the painted dimensions of this token, using the dimensions of the child tokens and expressions contained within it and the expression cursor to use. /// </summary> /// <param name="expressionCursor">The expression cursor to use, for calculating sizes depending on the location of the cursor. /// <para/> /// For example, moving the cursor into the base of a <c>log</c> token with current base <c>e</c> will expand the token from <c>ln(...)</c> to <c>log_e(...)</c>.</param> public override void RecalculateDimensions(ExpressionCursor expressionCursor) { Simplification = GetSimplificationType(expressionCursor); string text = Simplification == SimplificationType.LogE ? "ln" : "log"; Operand.Size = Size; Operand.RecalculateDimensions(expressionCursor); Base.Size = DisplaySize.Small; Base.RecalculateDimensions(expressionCursor); Width = Operand.Width + 6 * text.Length + (Size == DisplaySize.Large ? 12 : 9) + (Simplification == SimplificationType.None ? 1 + Base.Width : 0); int fnSize = (Size == DisplaySize.Large ? 5 : 4) + Base.Height + Operand.BaselineOffset; Height = Simplification != SimplificationType.None ? Operand.Height : Math.Max(Operand.Height, fnSize); }
private void btnSimplify_Click(object sender, RoutedEventArgs e) { InMemoryFeatureLayer simplificationLayer = (InMemoryFeatureLayer)mapView.FindFeatureLayer("SimplificationLayer"); double tolerance = Convert.ToDouble(cmbTolerance.SelectedItem.ToString().Split(':')[1], CultureInfo.InvariantCulture); SimplificationType simplificationType = (SimplificationType)cmbSimplificationType.SelectedIndex; MultipolygonShape multipolygonShape = areaBaseShape.Simplify(tolerance, simplificationType); simplificationLayer.InternalFeatures.Clear(); simplificationLayer.InternalFeatures.Add(new Feature(multipolygonShape)); mapView.Overlays["SimplificationOverlay"].Refresh(); }
private void btnSimplify_Click(object sender, EventArgs e) { InMemoryFeatureLayer simplificationLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("SimplificationLayer"); double tolerance = Convert.ToDouble(cmbTolerance.Text, CultureInfo.InvariantCulture); SimplificationType simplificationType = (SimplificationType)cmbSimplificationType.SelectedIndex; MultipolygonShape multipolygonShape = areaBaseShape.Simplify(tolerance, simplificationType); simplificationLayer.InternalFeatures.Clear(); simplificationLayer.InternalFeatures.Add(new Feature(multipolygonShape)); winformsMap1.Refresh(winformsMap1.Overlays["SimplificationOverlay"]); }
/// <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(); //} }
private void SimplifyAllFeatures() { UpdatingTaskProgressEventArgs args = null; var features = GetFeaturesFromTempFile().ToArray(); int index = 1; int count = features.Count(); SimplificationType simType = SimplificationType.DouglasPeucker; if (preserveTopology) { simType = SimplificationType.TopologyPreserving; } Collection <Feature> simplifiedFeatures = new Collection <Feature>(); foreach (Feature feature in features) { try { var shape = feature.GetShape(); var areaShape = shape as AreaBaseShape; var lineShape = shape as LineBaseShape; BaseShape simplifiedShape = null; if (areaShape != null) { if (selectedDistanceUnit == "Decimal Degrees") { simplifiedShape = areaShape.Simplify(simplificationTolerance, simType); } else { simplifiedShape = areaShape.Simplify(mapUnit, simplificationTolerance, (DistanceUnit)converter.ConvertBack(selectedDistanceUnit, null, null, null), simType); } } else if (lineShape != null) { if (selectedDistanceUnit == "Decimal Degrees") { simplifiedShape = lineShape.Simplify(simplificationTolerance, simType); } else { simplifiedShape = lineShape.Simplify(mapUnit, simplificationTolerance, (DistanceUnit)converter.ConvertBack(selectedDistanceUnit, null, null, null), simType); } } if (simplifiedShape != null) { Feature newFeature = new Feature(simplifiedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues); newFeature.Tag = feature.Tag; simplifiedFeatures.Add(newFeature); } } catch (Exception ex) { args = new UpdatingTaskProgressEventArgs(TaskState.Error); args.Message = feature.Id; args.Error = new ExceptionInfo(ex.Message, ex.StackTrace, ex.Source); GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); OnUpdatingProgress(args); continue; } var progressPercentage = index * 100 / count; args = new UpdatingTaskProgressEventArgs(TaskState.Updating, progressPercentage); args.Current = index; args.UpperBound = count; OnUpdatingProgress(args); isCanceled = args.TaskState == TaskState.Canceled; if (isCanceled) { break; } index++; } if (!isCanceled) { args = new UpdatingTaskProgressEventArgs(TaskState.Updating); args.Message = "Creating File"; OnUpdatingProgress(args); FileExportInfo info = new FileExportInfo(simplifiedFeatures, GetColumns(), outputPathFileName, displayProjectionParameters); Export(info); } //args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Completed); //args.Message = "Finished"; //OnUpdatingProgress(args); }
private void SimplifyShapeFile() { var args = new UpdatingTaskProgressEventArgs(TaskState.Updating); var currentSource = (ShapeFileFeatureSource)FeatureSource; if (!currentSource.IsOpen) { currentSource.Open(); } var canceled = false; var shapeFileType = currentSource.GetShapeFileType(); var projectionWkt = Proj4Projection.ConvertProj4ToPrj(DisplayProjectionParameters); var helper = new ShapeFileHelper(shapeFileType, outputPathFileName, currentSource.GetColumns(), projectionWkt); try { helper.ForEachFeatures(currentSource, (f, currentProgress, upperBound, percentage) => { try { if (f.GetWellKnownBinary() != null) { SimplificationType simType = SimplificationType.DouglasPeucker; if (preserveTopology) { simType = SimplificationType.TopologyPreserving; } var shape = f.GetShape(); var areaShape = shape as AreaBaseShape; var lineShape = shape as LineBaseShape; BaseShape simplifiedShape = null; if (areaShape != null) { if (selectedDistanceUnit == "Decimal Degrees") { simplifiedShape = areaShape.Simplify(simplificationTolerance, simType); } else { simplifiedShape = areaShape.Simplify(mapUnit, simplificationTolerance, (DistanceUnit)converter.ConvertBack(selectedDistanceUnit, null, null, null), simType); } } else if (lineShape != null) { if (selectedDistanceUnit == "Decimal Degrees") { simplifiedShape = lineShape.Simplify(simplificationTolerance, simType); } else { simplifiedShape = lineShape.Simplify(mapUnit, simplificationTolerance, (DistanceUnit)converter.ConvertBack(selectedDistanceUnit, null, null, null), simType); } } if (simplifiedShape != null) { Feature feature = new Feature(simplifiedShape); foreach (var item in f.ColumnValues) { feature.ColumnValues[item.Key] = item.Value; } helper.Add(feature); } } args = new UpdatingTaskProgressEventArgs(TaskState.Updating, percentage); args.Current = currentProgress; args.UpperBound = upperBound; OnUpdatingProgress(args); canceled = args.TaskState == TaskState.Canceled; return(canceled); } catch (Exception e) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, e.Message, new ExceptionInfo(e)); return(false); } }); } finally { helper.Commit(); } }
protected override void RunCore(Dictionary <string, string> parameters) { bool allParametersValid = ParseParameters(parameters); if (allParametersValid) { UpdatingProgressLongRunningTaskPluginEventArgs args = null; var features = GetFeaturesFromTempFile().ToArray(); int index = 1; int count = features.Count(); SimplificationType simType = SimplificationType.DouglasPeucker; if (preserveTopology) { simType = SimplificationType.TopologyPreserving; } Collection <Feature> simplifiedFeatures = new Collection <Feature>(); foreach (Feature feature in features) { try { var shape = feature.GetShape(); var areaShape = shape as AreaBaseShape; var lineShape = shape as LineBaseShape; BaseShape simplifiedShape = null; if (areaShape != null) { if (selectedDistanceUnit == "Decimal Degrees") { simplifiedShape = areaShape.Simplify(simplificationTolerance, simType); } else { simplifiedShape = areaShape.Simplify(mapUnit, simplificationTolerance, (DistanceUnit)converter.ConvertBack(selectedDistanceUnit, null, null, null), simType); } } else if (lineShape != null) { if (selectedDistanceUnit == "Decimal Degrees") { simplifiedShape = lineShape.Simplify(simplificationTolerance, simType); } else { simplifiedShape = lineShape.Simplify(mapUnit, simplificationTolerance, (DistanceUnit)converter.ConvertBack(selectedDistanceUnit, null, null, null), simType); } } if (simplifiedShape != null) { Feature newFeature = new Feature(simplifiedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues); newFeature.Tag = feature.Tag; simplifiedFeatures.Add(newFeature); } } catch (Exception ex) { args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Error); args.Message = feature.Id; args.ExceptionInfo = new LongRunningTaskExceptionInfo(ex.Message, ex.StackTrace); OnUpdatingProgress(args); } args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Updating); args.Current = index * 100 / count; OnUpdatingProgress(args); index++; } args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Updating); args.Message = "Creating File"; OnUpdatingProgress(args); Output(simplifiedFeatures); args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Updating); args.Message = "Finished"; OnUpdatingProgress(args); } else { //report error and return. } }
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; } }
public static List <SqlGeometry> Simplify(this List <SqlGeometry> geometries, SimplificationType type, int zoomLevel, 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.Ham.SpatialBase.Mapping.WebMercatorUtility.CalculateGroundResolution(zoomLevel, averageLatitude); //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(); switch (type) { case SimplificationType.ByArea: result = Process(geometries, pList => IRI.Ham.SpatialBase.Analysis.VisualSimplification.SimplifyByArea(pList, areaThreshold)); break; case SimplificationType.AdditiveByArea: result = Process(geometries, pList => IRI.Ham.SpatialBase.Analysis.VisualSimplification.AdditiveSimplifyByArea(pList, areaThreshold)); break; case SimplificationType.AdditiveByAreaPlus: result = Process(geometries, pList => IRI.Ham.SpatialBase.Analysis.VisualSimplification.AdditiveSimplifyByAreaPlus(pList, areaThreshold)); break; case SimplificationType.ByAngle: result = Process(geometries, pList => IRI.Ham.SpatialBase.Analysis.VisualSimplification.SimplifyByAngle(pList, angleThreshold)); break; case SimplificationType.AdditiveByAngle: result = Process(geometries, pList => IRI.Ham.SpatialBase.Analysis.VisualSimplification.AdditiveSimplifyByAngle(pList, angleThreshold)); break; case SimplificationType.AdditiveByDistance: result = Process(geometries, pList => IRI.Ham.SpatialBase.Analysis.VisualSimplification.AdditiveSimplifyByDistance(pList, threshold)); break; case SimplificationType.AdditiveByAreaAngle: result = Process(geometries, pList => IRI.Ham.SpatialBase.Analysis.VisualSimplification.AdditiveSimplifyByAngleArea(pList, angleThreshold, areaThreshold)); break; default: throw new NotImplementedException(); } 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; } }
/// <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, double threshold, SimplificationType type, double areaThreshold = double.NaN) { switch (type) { case SimplificationType.ByArea: return(Process(geometry, pList => IRI.Ham.SpatialBase.Analysis.VisualSimplification.SimplifyByArea(pList, threshold))); case SimplificationType.AdditiveByArea: return(Process(geometry, pList => IRI.Ham.SpatialBase.Analysis.VisualSimplification.AdditiveSimplifyByArea(pList, threshold))); case SimplificationType.AdditiveByAreaPlus: return(Process(geometry, pList => IRI.Ham.SpatialBase.Analysis.VisualSimplification.AdditiveSimplifyByAreaPlus(pList, threshold))); case SimplificationType.ByAngle: return(Process(geometry, pList => IRI.Ham.SpatialBase.Analysis.VisualSimplification.SimplifyByAngle(pList, threshold))); case SimplificationType.AdditiveByAngle: return(Process(geometry, pList => IRI.Ham.SpatialBase.Analysis.VisualSimplification.AdditiveSimplifyByAngle(pList, threshold))); case SimplificationType.AdditiveByDistance: return(Process(geometry, pList => IRI.Ham.SpatialBase.Analysis.VisualSimplification.AdditiveSimplifyByDistance(pList, threshold))); case SimplificationType.AdditiveByAreaAngle: return(Process(geometry, pList => IRI.Ham.SpatialBase.Analysis.VisualSimplification.AdditiveSimplifyByAngleArea(pList, threshold, areaThreshold))); default: throw new NotImplementedException(); } }