-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimplifier.cs
More file actions
49 lines (42 loc) · 1.77 KB
/
Simplifier.cs
File metadata and controls
49 lines (42 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Data.SqlClient;
using Microsoft.SqlServer.Types;
using SqlSpatial.Simplify.Algorithms;
namespace SqlSpatial.Simplify;
public static class Simplifier
{
// Handles MultiPolygon and LineString types by recursively iterating through them
// and calling the same code as for individual Polygon and LineString types
// That's the theory, at least.
public static SqlGeography Simplify(SqlGeography sourceGeography, SimplifyMode mode, double tolerance)
{
var builder = new SqlGeographyBuilder();
builder.SetSrid(4326);
SimplifyGeography(builder, sourceGeography, mode, tolerance);
return builder.ConstructedGeography;
}
private static void SimplifyGeography(SqlGeographyBuilder builder, SqlGeography innerGeography, SimplifyMode mode, double tolerance)
{
var geogType = innerGeography.STGeometryType().Value;
if (geogType == "LineString" || geogType == "Polygon")
{
var visvalingam = new Visvalingam(builder, innerGeography, mode, tolerance);
visvalingam.Simplify();
}
else if (geogType == "MultiPolygon" || geogType == "MultiLineString")
{
builder.BeginGeography(geogType == "MultiPolygon" ? OpenGisGeographyType.MultiPolygon : OpenGisGeographyType.MultiLineString);
var nGeographies = innerGeography.STNumGeometries().Value;
var limit = nGeographies + 1;
for (var i = 1; i < limit; i++)
{
SimplifyGeography(builder, innerGeography.STGeometryN(i), mode, tolerance);
}
builder.EndGeography();
}
else
{
throw new NotImplementedException("Simplify() not implemented for SqlGeography type " + geogType);
}
}
}