ThinkGeo.com    |     Documentation    |     Premium Support

CloseLineAsPolygon Takes too long

We want to show the user the contour instead of the isoline, according to my search in this forum we should call
var feature = GridIsoLineLayer.GetIsoFeatures(gridCellMatrix, isoLineLevels, “ContourValue” , IsoLineType.ClosedLinesAsPolygons)

but It takes too long, you know if we change CloseLinesAsPolygons to LinesOnly, It takes 5 seconds but for polygon one, it takes more than 2 minutes.

So, Do we have any option to speed up the contour process?

Thanks Mahdi,
Could you provide us a sample for this one. This would be very helpful for us to look into the details.

Thanks

Frank

I just update the DispalyIsoLine from v10 to v12.

I have attached my project, if you select ClosedLinesAsPolygons, you can see it takes too long, while it was created very quickly in version 10.DisplayIsoLinesSample.zip (789.0 KB)

Hey @Mahdi_Rastegari,

Thank you for the sample project. I do see the slowdown for the ClosedLinesAsPolygons option. Using it in version 10 is indeed faster. Our developers are currently investigating, and I’ll provide you with an update as soon as we identify the cause and can reach a resolution.

Thanks,
Kyle

I will appreciate that if you can help me how to get the inside polygon of IsoLines.
we should prepare a quick fix for ClosedLinesAsPolygons issue.

Hey @Mahdi_Rastegari,

Unfortunately, there isn’t a quick fix for this issue. With ThinkGeo v12, we moved over to support using .NET Core 3.x and above. Due to this, we no longer have support for Microsoft’s SqlTypes geometry functions that were integral to the speed of IsoLines. It will take some time in order for us to develop an enhancement comparable speed for v12.

In the meantime, if you just want to just get the polygons in an IsoLineLayer, you can extract them with the following code:

Collection<Feature> features = isoLineLayer.GetIsoLineFeatures();
foreach (var feature in features)
{
    LineShape line = feature.GetShape() as LineShape;
    if (line.IsClosed())
    {
        PolygonShape polygon = line.ToPolygonShape();
        Feature polyFeature = new Feature(polygon, feature.ColumnValues);
        // Do work on polygons, or save them to a layer
    }
}

This will check to see if any of the lines generated by LinesOnly can be converted into polygons and creates a new Feature with the same column value as the line. Of course, this won’t be 100% like ClosedLinesAsPolygons and might not show properly on the map with opaque fill styles, but it will have a similar outcome.

I will update this thread and tag you once we have a proper fix released.

Thanks,
Kyle

I had worked with the code you suggest to me. but this is completely different with ClosedLineAsPolygon.

I think we should use Intersection, some post processing to get to near results of ClosedLineAsPolygon.
if you can give me the better code or article about How can I convert IsoLine to isochrone(ClosedLineAsPolygon)

Something like this:

Hey @Mahdi_Rastegari,

Is your application being written in .NET Framework or .NET Core?

Thanks,
Kyle

.Net Framework 4.7.2

Hey @Mahdi_Rastegari,

Okay, our developers are working on implementing a performance improvement patch for IsoLines right now. It should be in our beta package release in a couple of days.

Thanks,
Kyle

Hey @Mahdi_Rastegari,

We have a DLL for ThinkGeo.SqlTypesIsoLine available for you to use. Attached is the DLL and accompanying demo project that is using it:

SqlTypesIsoLine.zip (1.7 MB)

The DLL is located under the ThinkGeo.SqlTypesIsoLine folder and requires your project to also reference the latest stable version of Microsoft.SqlServer.Types, in addition to this DLL. The only thing you’ll need to change in your code is to change the type of the InMemoryGridIsoLineLayerSqlTypesIsoLineLayer.

You can also open the demo and see it working with the new layer. It is based on the sample code that you sent us earlier.

We will be publishing this as a NuGet package in the future once we incorporate it into our build pipeline. But for now, we just wanted to send this off to you to use in the meantime.

Thanks,
Kyle

I have tested this package, 35s to get polygon feature whereas this was 13s in ThinkGeo v10.

Have you checked and compare this package with v10?
(Of course, this time was 10 minutes for version 12.)

Hey @Mahdi_Rastegari,

The code was ported directly from v10 with minimal changes. But we are looking into the performance differences between the two versions. At the very least it doesn’t take 10+ minutes now. We’ll also have a NuGet package out in a day or two with some minor additional improvements.

Thanks,
Kyle

Yes, I appreciate that. I hope you can improve this performance for future releases. I appreciate it if you can share your code with me(just to check the performance bottleneck)

@Kyle_Day
When I used the new package, in some case I faced with new exception with following stacktrace:

   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at Microsoft.SqlServer.Types.GLNativeMethods.ThrowExceptionForHr(GL_HResult errorCode)
   at Microsoft.SqlServer.Types.GLNativeMethods.Combine(CombineMode combineMode, GeoData g1, GeoData g2)
   at Microsoft.SqlServer.Types.SqlGeometry.STDifference(SqlGeometry other)
   at ThinkGeo.Core.SqlTypesIsoLineGeometry.DifferenceCore(IsoLineGeometry target)
   at ThinkGeo.Core.IsoLineGeometry.Difference(IsoLineGeometry target)
   at ThinkGeo.Core.SqlTypesIsoLineLayer.GetFeaturesWithPolygon(List`1 levelLineList, GridCell[,] grid, IsoLineGeometry gridGeometry, String dataValueColumnName)
   at ThinkGeo.Core.SqlTypesIsoLineLayer.GetIsoFeatures(GridCell[,] gridMatrix, IEnumerable`1 isoLineLevels, String dataValueColumnName, IsoLineType isoLineType, Double noDataValue)
   at ThinkGeo.Core.SqlTypesIsoLineLayer.GetIsoLineFeatures()
   at Core.Helper.Spitfire.ContourHelper.CreateContourSourceCore(ResultVisualArgs args, Dictionary`2 ptalPoints, String name, RectangleShape extend, ProjectionArgs projection) in D:\Source\repos\TRACC\Core\Helper\Spitfire\ContourHelper.cs:line 60

If I change the noDataValue, it works. any idea?

@Kyle_Day

Any thught?

Hey @Mahdi_Rastegari,

I’ve tried recreating your exception, but I’m not seeing it on my end. What exactly is the exception and frequency? What was the noDataValue before and after?

Thanks,
Kyle

@Kyle_Day
Sorry for the delay,
So, I have created a project for you, you can see my issue inside this project.
Apart from this, when I was trying to create this project for you, I did realize that when I reduce the decimal length of DataPoints, this issue will be resolved (please see my comments inside the project)…SqlTypesIsoLine.zip (1.6 MB)

@Kyle_Day
Can you regenerate the issue?