Skip to content

matthijsbreemans/GeoJsonAndSqlGeo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GeoJsonAndSqlGeo

Library to get SqlGeography from GeoJson and back

You can use this to e.g. define zones or similar things in GoogleMaps, export the data as GeoJson, traslate it to a SqlGeography type in order to store it in a SqlServer DB e.g. with Dapper.

This library has the following dependencies:

  • Paket (for nuget things)
  • GeoJSON.Net
  • Irony

Entry point is the GeoJsonSql class. Call Translateto get back and forth from a deserialized GeoJson tree to a SqlGeography instance. Call Configure to set a few necessary things. In fact the only mandatory thing you need to set is the underlying coordinate system of the SqlGeography.

Note that this library supports handling circles. GeoJson does not "natively" support circles. It is supported by passing a Feature with a point as geometry and a property with name "radius", providing the radius as a number that fits to the Spatial representation system that you are using (e.g. Meter in World Geodetic).

In this mode, you need to set the library to output a FeatureCollection when translating fom SqlGeography to GeoJson through the config.

GeoToSql.Configure(cfg =>
{
    cfg.SetReferenceSystem(SpatialReferenceSystem.WorldGeodetic1984);
    cfg.SetSqlGeographyToGeoJsonConstructionStyle(GeoJsonConstructionStyle.AsFeatureCollection);
});

The default is GeoJsonConstructionStyle.AsGeometryCollection. If in this mode a circle-like structure is encountered, an InvalidOperationException will be thrown.

Useful Links:

About

Library to get SqlGeography from GeoJson and back

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.9%
  • Batchfile 0.1%