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

Hi @Evgeniy.Timofeev,

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

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.

Hi @Alexander.Matveev ,

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>();
      sites.Add(new Point(100, 100));
      sites.Add(new Point(200, 200));
      sites.Add(new Point(200, 100));
      sites.Add(new Point(100, 200));

      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;
            sitesLayer.Add(feature);
        }

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

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

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

        map.Add(edgesLayer, new MixedGeometrySymbolizer()
        {
            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

Hi @Alexander.Matveev ,

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.
Could you please provide a link if it’s available?

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

Hi @Alexander.Matveev ,

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.

Additional info, reproduce error:

                    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 ?

Hi @Alexander.Matveev

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