MapsUI save polygon from layer as string

105 views Asked by At

I am currently working with MapsUI in Avalonia UI. Now I have the problem that I want to save the polygons I draw in the database for each layer. But I am unable to find how I could do this correctly. First I thought to save every polygon point seperate, but later on realised that a string could also be an option. But after some trying I just can't figure out how to get the polygon string or any coordinates out of the layer.

// Get featurelist from editManager (featureList contains the geometry)
IEnumerable<IFeature>? featureList = _editManager.Layer?.GetFeatures();

// I curently have on feature so get this on
GeometryFeature firstFeature = (GeometryFeature)featureList.FirstOrDefault();

// Now get the polygon string ??
string polygon = firstFeature
1

There are 1 answers

0
pauldendulk On BEST ANSWER

The Mapsui GeometryFeature holds an NTS Geometry

NetTopologySuite.Geometries.Geometry geometry = firstFeature.Geometry

NTS is a mature library which itself has all kinds of options. So, you could also look there: https://github.com/NetTopologySuite/NetTopologySuite

In general a geometry is written as one record in a database.

Many databases have specific column types for geometry types and queries. This is called 'spatial support'. One of the best spatial databases is postgresql with the postgis extension. SQL Server and MySql also have spatial support. There are specific libraries to read and write NTS to these databases.

You could also keep things more under your own control and use NTS WKTWriter to convert it to a WKT string and save it as such.