# Get Centerline length of (multi)polygon (collection)

Hi ,
I have been challenged to calculate length of a (multi)polygon shape or collection of shapes.

The length should be the centerline of the shape(s). Like this image e.g. (red is the centerline )
image.png (56.6 KB)

This can be a complex issue , could Aspose.Gis provide something like a centerline function to display and get the length of the centerline.

Regards,
Mehmet

Hi, @mcanavar

The task is very interesting. We are extending our set of geotools. First will we build a centerline polygon. Then we will calculate length.

I have created a ticket GISNET-1412 and update you here as soon as additional information is available.

Thanks

1 Like

It is interesting, reading into this topic of calculating length of the centerline ," Voronoi " method calculation comes up a lot.

Regards,
Mehmet

The " Voronoi " method calculation is a good idea

Thank a lot.

1 Like

Perhaps a good example of an shape to test on : Look like this : image.png (24.1 KB)

GeoJson:example.7z (4.7 KB)

Thank you for sharing a good example.

Hi ,
Any update or hope that this will be available anytime soon?
Otherwise we will have to look for other means to solve this issue of ours.
Best Regards
Mehmet

Hi, @mcanavar

Yes, we have updates, we released feature âMakeVoronoiGraphâ in our GeoTools. So, now we can build âVoronoiâ diagram for collection of points.
Next step is calculate centerline length. We are going to release this in march.

Please check out our âMakeVoronoiGraphâ feature. I hope it will be useful for you.

Thanks.

Fantastic news about the âMakeVoronoiGraphâ feature in GeoTools!
Excited to explore its potential. Looking forward to the centerline length calculation release in March.

Thanks for the update!

Hi @Alexander.Matveev ,
Could you provide more details or documentation on how to use this new feature?
I couldnât find any release notes and it seems I have missed some releases ?
image.png (15.9 KB)

Best,
Mehmet

Hi, @mcanavar

Apply âVoronoiâ polygon to find lines equidistant from points. On start we have collection of points, using method we get collection of edges voronoi diagram.
Please use map.Render to see results.

These code examples for you:

``````List<Point> sites = new List<Point>();

var edges = Gis.GeoTools.GeometryOperations.MakeVoronoiGraph(sites);
var map = ProduceVoronoiMap(edges, sites);
map.Render(MakePath("square") + ".map.png", Renderers.Png);

private Map ProduceVoronoiMap(List<LineString> edges, List<Point> sites, int mapSize = 300, int startExtent = 0)
{
// sites layer
var sitesLayer = Drivers.InMemory.CreateLayer();
foreach (var site in sites)
{
Feature feature = sitesLayer.ConstructFeature();
feature.Geometry = site;
}

// edges layer
var edgesLayer = Drivers.InMemory.CreateLayer();
foreach (var edge in edges)
{
Feature feature = edgesLayer.ConstructFeature();
feature.Geometry = edge;
}

var map = new Map(mapSize - startExtent, mapSize - startExtent);
map.Extent = new Extent(startExtent, startExtent, mapSize, mapSize);
map.BackgroundColor = Color.Beige;

{
PolygonSymbolizer = new SimpleFill() { FillColor = Color.Transparent, StrokeColor = Color.DimGray },
});

{
LineSymbolizer = new SimpleLine() { Width = 2, Color = Color.Green }
});

return map;
}
``````
1 Like

Hi, @mcanavar
We made upgrade and released new functions âBuildCenterlineâ and âGetCenterlineLengthâ in our GeoTools! To build centerline you need set polygon or collection of points.

Please check it out and let me know if you need something

Thank you for the update!
It would be beneficial to have release notes or documentation containing some samples or examples demonstrating how to utilize this new feature.
At this point, I cannot find any documentation to get started with.

Hi, @mcanavar
Unfortunately there is no article yet. It will be prepare in a couple of days.

These simple code examples:
// for right triangle
List sites = new List
{
new Point(100, 100),
new Point(200, 200),
new Point(200, 100)
};
var length = Gis.GeoTools.GeometryOperations.GetCenterlineLength(sites);
or
//need to set input polygon
var length = Gis.GeoTools.GeometryOperations.GetCenterlineLength(polygon);

1 Like

I have updated to the latest version of Aspose.GIS, version 24.3.0, using NuGet. However, I am encountering conflicts in the existing codebase. For example:

*The âColorTranslatorâ class exists in both âAspose.GISâ and âSystem.Drawingâ.
*âNewtonsoft.Json.Formattingâ exists in both âAspose.GISâ and âNewtonsoft.Jsonâ.

Using the full name or aliases does not resolve the conflicts, and I am unable to compile my existing project.

Do you have any solutions to resolve these conflicts?

@mcanavar Hello, we are investigating the cause and will inform you about the results additionally. Thank you for your valuable feedback.

1 Like

I do want to add that Iâm using this with âBlazorâ server application.

And I see that this is added to the description in nuget for System.Drawing.Common :
Since .NET 7, non-Windows platforms are not supported, even with the runtime configuration switch. See Breaking change: System.Drawing.Common only supported on Windows - .NET | Microsoft Learn for more information.

``````                    var lineSymbolizer = new SimpleLine { Width = 1.5, Color = Color.DarkSlateBlue };
var polygonSymbolizer = new SimpleFill { FillColor = Color.Azure, StrokeColor = Color.Brown };
var pointSymbolizer = new SimpleMarker { FillColor = Color.Aqua, StrokeColor = Color.Red };
var symbolizer = new MixedGeometrySymbolizer();
symbolizer.LineSymbolizer = lineSymbolizer;
symbolizer.PointSymbolizer = pointSymbolizer;
symbolizer.PolygonSymbolizer = polygonSymbolizer;

Aspose.Gis.Geometries.IGeometry afield = Aspose.Gis.Geometries.Geometry.FromBinary(sqlDatabase.geom.AsBinary());

var imageStream = new MemoryStream();
AbstractPath path = AbstractPath.FromStream(imageStream);

afield.AsImage(path, Measurement.Pixels(200), Measurement.Pixels(200), Renderers.Svg, symbolizer);

var byteArray = imageStream.ToArray();
var bytes = Convert.ToBase64String(byteArray);
``````

This code works with version 23.12.0 âŚ and not with newer versions
Error on line where .AsImage is used âŚ

trace:

``````   at System.Drawing.FontFamily.get_GenericMonospace()
at Aspose.Gis.Painting.PaintEngineState..ctor()
at Aspose.Gis.Painting.Painter..ctor(PaintEngine engine)
at Aspose.Gis.Rendering.Map.( , PaintEngine )
at Aspose.Gis.Rendering.Formats.Svg.SvgRenderer.(Map , AbstractPath ,  )
at Aspose.Gis.Rendering.Formats.Svg.SvgRenderer.8sshrh6g9r3gjw6fl37hbdeajnu6wgfz(Map , AbstractPath ,  )
at Aspose.Gis.Rendering.Map.Render(AbstractPath outputPath, Renderer renderer)
at .(IGeometry , AbstractPath , Measurement , Measurement , Renderer , VectorSymbolizer )
at Aspose.Gis.Geometries.Geometry.AsImage(AbstractPath outputPath, Measurement width, Measurement height, Renderer renderer, VectorSymbolizer symbolizer)
at
``````

Hi, @mcanavar

Could you please also provide your version Newton JSON, version of nuget package âMicrosoft.NET.Test.Sdkâ and version System.Drawing.Common ?

``````Version of Newtonsoft.Json is 13.0.3
<Project Sdk="Microsoft.NET.Sdk.Web">
<TargetFramework>net7.0-windows</TargetFramework>
System.Drawing.Common : nuget version : 8.0.3
``````