https://github.com/tbbuck/sqlspatial.simplify
SqlGeography Simplification: implementation of Visvalingam's algorithm for SQLGeography Simplification - SQL Server SqlCLR
https://github.com/tbbuck/sqlspatial.simplify
Last synced: over 1 year ago
JSON representation
SqlGeography Simplification: implementation of Visvalingam's algorithm for SQLGeography Simplification - SQL Server SqlCLR
- Host: GitHub
- URL: https://github.com/tbbuck/sqlspatial.simplify
- Owner: tbbuck
- License: apache-2.0
- Created: 2024-06-28T01:11:58.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-28T01:15:43.000Z (almost 2 years ago)
- Last Synced: 2025-01-22T08:17:22.259Z (over 1 year ago)
- Language: C#
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Polygon + LineString Simplification SqlClr for SQL Server Spatial Geographies
## Install
```sql
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.
```sql
ALTER ASSEMBLY SqlSpatialClr FROM '/where/uploaded/to/mssql/server/SqlSpatial.Simplify.dll';
````
## Uninnstall
```sql
DROP FUNCTION IF EXISTS dbo.SimplifyByArea; GO
DROP FUNCTION IF EXISTS dbo.SimplifyByPercentage; GO
DROP ASSEMBLY IF EXISTS SqlSpatialClr;
````
## Example usage
```sql
-- 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;
```