Skip to content

Commit d1b8ec3

Browse files
committed
Merge branch 'master' of https://github.com/autodotua/MapBoard
2 parents a6d5928 + a8c1be0 commit d1b8ec3

File tree

13 files changed

+294
-138
lines changed

13 files changed

+294
-138
lines changed

MapBoard.Core/Mapping/Model/FeatureExtension.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public static long GetID(this Feature feature)
3939
/// <param name="feature"></param>
4040
/// <param name="layer"></param>
4141
/// <returns></returns>
42-
public static Feature Clone(this Feature feature, EditableLayerInfo layer)
42+
public static Feature Clone(this Feature feature, IEditableLayerInfo layer)
4343
{
4444
IEnumerable<FieldInfo> fields = layer.Fields;
45-
return feature.Clone(layer, fields.ToDictionary(p => p.Name));
45+
return feature.Clone(layer.Layer.FeatureTable, fields.ToDictionary(p => p.Name));
4646
}
4747

4848
/// <summary>
@@ -52,7 +52,7 @@ public static Feature Clone(this Feature feature, EditableLayerInfo layer)
5252
/// <param name="layer"></param>
5353
/// <param name="key2Field"></param>
5454
/// <returns></returns>
55-
public static Feature Clone(this Feature feature, EditableLayerInfo layer, Dictionary<string, FieldInfo> key2Field)
55+
public static Feature Clone(this Feature feature, FeatureTable table, Dictionary<string, FieldInfo> key2Field)
5656
{
5757
var dic = new Dictionary<string, object>();
5858
foreach (var attr in feature.Attributes)
@@ -88,7 +88,7 @@ public static Feature Clone(this Feature feature, EditableLayerInfo layer, Dicti
8888
{
8989
dic.AddOrSetValue(Parameters.CreateTimeFieldName, DateTime.Now.ToString(Parameters.TimeFormat));
9090
}
91-
var newFeature = layer.CreateFeature(dic, feature.Geometry);
91+
var newFeature = table.CreateFeature(dic, feature.Geometry);
9292
return newFeature;
9393
}
9494
}

MapBoard.Core/Mapping/Model/LayerInfo/EditableLayerInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public async Task<IEnumerable<Feature>> AddFeaturesAsync(IEnumerable<Feature> fe
107107
List<Feature> newFeatures = new List<Feature>();
108108
foreach (var feature in features)
109109
{
110-
Feature newFeature = feature.Clone(this, key2Field);
110+
Feature newFeature = feature.Clone(table, key2Field);
111111
newFeatures.Add(newFeature);
112112
}
113113
await table.AddFeaturesAsync(newFeatures);

MapBoard.Core/Mapping/XYZTiledLayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static XYZTiledLayer()
5555
}
5656
File.WriteAllBytes(cacheFile, data);
5757
cacheQueueFiles.TryRemove(cacheFile, out _);
58-
Debug.WriteLine($"写入Tile缓存,queue={cacheWriterQuque.Count}, hashset={cacheQueueFiles.Count}");
58+
//Debug.WriteLine($"写入Tile缓存,queue={cacheWriterQuque.Count}, hashset={cacheQueueFiles.Count}");
5959
}
6060
else
6161
{

MapBoard.Core/Util/FeatureUtility.cs

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using MapBoard.Model;
1515
using System.Collections.Concurrent;
1616
using FzLib.Collection;
17+
using static MapBoard.Util.GeometryUtility.CentripetalCatmullRom;
1718

1819
namespace MapBoard.Util
1920
{
@@ -397,7 +398,7 @@ private static double GetVerticleDistance(MapPoint p1, MapPoint p2, MapPoint pc)
397398
private static double GetVerticleDistance(Polyline line, MapPoint pc)
398399
{
399400
var nearestPoint = GeometryEngine.NearestCoordinate(line, pc);
400-
var dist = GeometryEngine.DistanceGeodetic(pc, nearestPoint.Coordinate, LinearUnits.Meters, AngularUnits.Degrees, GeodeticCurveType.NormalSection);
401+
var dist = GeometryEngine.DistanceGeodetic(pc, nearestPoint.Coordinate, LinearUnits.Meters, AngularUnits.Degrees, GeodeticCurveType.Geodesic);
401402
return dist.Distance;
402403
}
403404

@@ -702,8 +703,9 @@ await Task.Run(() =>
702703
/// <param name="features"></param>
703704
/// <param name="pointsPerSegment">两个节点之间生成多少新点</param>
704705
/// <param name="level">平滑等级,0最拟合,1一般,2最平滑</param>
706+
/// <param name="minSmoothAngle">最小需要平滑的角度。若某三个节点组成的角小于该角度,那么会对中间点左右两侧分别进行平滑然后拼接</param>
705707
/// <returns></returns>
706-
public static async Task Smooth(IEditableLayerInfo layer, Feature[] features, int pointsPerSegment, int level)
708+
public static async Task<IEnumerable<Feature>> Smooth(IEditableLayerInfo layer, Feature[] features, int pointsPerSegment, int level, bool deleteOldFeature = false, double minSmoothAngle = 45)
707709
{
708710
if (level < 0 || level > 2)
709711
{
@@ -713,56 +715,45 @@ public static async Task Smooth(IEditableLayerInfo layer, Feature[] features, in
713715
{
714716
throw new ArgumentOutOfRangeException(nameof(pointsPerSegment));
715717
}
716-
//CentripetalCatmullRom中数量是算上头尾的
717-
pointsPerSegment += 2;
718-
ConcurrentBag<UpdatedFeature> updatedFeatures = new ConcurrentBag<UpdatedFeature>();
718+
ConcurrentBag<UpdatedFeature> updatedFeatures = null;
719+
ConcurrentBag<Feature> addedFeatures = null;
720+
if (deleteOldFeature)
721+
{
722+
updatedFeatures = new ConcurrentBag<UpdatedFeature>();
723+
}
724+
else
725+
{
726+
addedFeatures = new ConcurrentBag<Feature>();
727+
}
719728
await Task.Run(() =>
720729
{
721730
Parallel.ForEach(features, feature =>
722731
{
723-
Geometry oldGeometry = feature.Geometry;
724-
Geometry newGeometry = null;
725-
if (feature.Geometry is Multipart m)
732+
var oldGeometry = feature.Geometry;
733+
var newGeometry = GeometryUtility.Smooth(oldGeometry, pointsPerSegment, level, minSmoothAngle); ;
734+
if (deleteOldFeature)
726735
{
727-
List<IEnumerable<MapPoint>> newParts = new List<IEnumerable<MapPoint>>();
728-
foreach (var part in m.Parts)
729-
{
730-
if (part.PointCount <= 2)
731-
{
732-
newParts.Add(part.Points);
733-
}
734-
else
735-
{
736-
newParts.Add(CentripetalCatmullRom.Interpolate(part.Points.ToList(), pointsPerSegment, (CentripetalCatmullRom.CatmullRomType)level));
737-
}
738-
}
739-
switch (feature.Geometry)
740-
{
741-
case Polyline line:
742-
newGeometry = new Polyline(newParts);
743-
break;
744-
745-
case Polygon polygon:
746-
newGeometry = new Polygon(newParts);
747-
break;
748-
}
749-
}
750-
else if (feature.Geometry is Multipoint mp)
751-
{
752-
if (mp.Points.Count > 2)
753-
{
754-
newGeometry = new Multipoint(CentripetalCatmullRom.Interpolate(mp.Points.ToList(), pointsPerSegment, (CentripetalCatmullRom.CatmullRomType)level));
755-
}
736+
feature.Geometry = newGeometry;
737+
updatedFeatures.Add(new UpdatedFeature(feature, oldGeometry, feature.Attributes));
756738
}
757739
else
758740
{
759-
throw new NotSupportedException("仅支持多点、折线和多边形");
741+
var newFeature = feature.Clone(layer);
742+
newFeature.Geometry = newGeometry;
743+
addedFeatures.Add(newFeature);
760744
}
761-
feature.Geometry = newGeometry;
762-
updatedFeatures.Add(new UpdatedFeature(feature, oldGeometry, feature.Attributes));
763745
});
764746
});
765-
await layer.UpdateFeaturesAsync(updatedFeatures, FeatureOperation);
747+
748+
if (deleteOldFeature)
749+
{
750+
await layer.UpdateFeaturesAsync(updatedFeatures, FeatureOperation);
751+
return updatedFeatures.Select(p => p.Feature);
752+
}
753+
else
754+
{
755+
return await layer.AddFeaturesAsync(addedFeatures, FeatureOperation);
756+
}
766757
}
767758

768759
/// <summary>

0 commit comments

Comments
 (0)