Skip to content

SqlGeography Simplification: implementation of Visvalingam's algorithm for SQLGeography Simplification - SQL Server SqlCLR

License

Notifications You must be signed in to change notification settings

tbbuck/SqlSpatial.Simplify

Repository files navigation

Polygon + LineString Simplification SqlClr for SQL Server Spatial Geographies

Install

DROP ASSEMBLY IF EXISTS SqlSpatialClr; 

CREATE ASSEMBLY SqlSpatialClr FROM '/where/uploaded/to/mssql/server/SqlSpatial.Simplify.dll' WITH PERMISSION_SET = SAFE; 

CREATE FUNCTION dbo.SimplifyByArea(@polygon GEOGRAPHY, @tolerance FLOAT) RETURNS GEOGRAPHY AS EXTERNAL NAME SqlSpatialClr.[SqlSpatial.Simplify.SqlClrWrapper].SimplifyByMinimumArea; GO
CREATE FUNCTION dbo.SimplifyByPercentage(@polygon GEOGRAPHY, @perentage FLOAT) RETURNS GEOGRAPHY AS EXTERNAL NAME SqlSpatialClr.[SqlSpatial.Simplify.SqlClrWrapper].SimplifyByPercentagePointsRetained; GO
 
GO

Update

You may need to DROP the functions first if the code's C# signatures have changed.

ALTER ASSEMBLY SqlSpatialClr FROM '/where/uploaded/to/mssql/server/SqlSpatial.Simplify.dll'; 

Uninnstall

DROP FUNCTION IF EXISTS dbo.SimplifyByArea; GO
DROP FUNCTION IF EXISTS dbo.SimplifyByPercentage; GO

DROP ASSEMBLY IF EXISTS SqlSpatialClr; 

Example usage

-- simplify by retaining 5% of the largest-area points
DECLARE @percentage FLOAT = 5.0;
DECLARE @geography GEOGRAPHY = (SELECT SomeHugeBoundary FROM lovely_big_city_table WHERE id = 31415);
SELECT dbo.SimplifyByPercentage(@geography, @percentage) AS simplified; 

-- simplify by dropping points with a triangular area under 200m
DECLARE @tolerance FLOAT = 200.0;
DECLARE @geography GEOGRAPHY = (SELECT SomeHugeBoundary FROM lovely_big_city_table WHERE id = 31415);
SELECT dbo.SimplifyByArea(@geography, @tolerance) AS simplified;

About

SqlGeography Simplification: implementation of Visvalingam's algorithm for SQLGeography Simplification - SQL Server SqlCLR

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages