ThinkGeo.com    |     Documentation    |     Premium Support

KML Feature Layer v12

Hi,

I can’t find KmlFeatureLayer in v12 core and don’t see it as a separate layer in NuGet. Please advice.

Thanks,
Damian

Thanks Damian,
Right now V12 doesn’t support KmlFeatureLayer. We are still working on this one. It will be available in future release. We will let you know once it available.

Thanks

Frank

Hi Frank,

Thanks for the update.

Regards,
Damian

Looking forward to this. Also, GeoPDF and MIF.

Thanks Mikko,
We are keep working on the KML layer and the GeoPDF layer. We will add the MIF to our todo list. But we don’t have the clear map for the MIF right now.

Thanks

Frank

1 Like

Mikko,
We got some progress for the geopdf and kml.

We still need more polish, test and packing etc. We will update you once we get more progress.

Thanks

Frank

Mikko,
The GeoPdf and the Kml layer are available for the Beta release. Here are the sample code.
private void MapView_Loaded(object sender, RoutedEventArgs e)
{
// mapView.MapUnit = GeographyUnit.DecimalDegree;

        //GeoPdfFeatureLayer layer = new GeoPdfFeatureLayer(@"E:\Tickets\HelloWorldSample_PDF\bangalore.pdf");
        //layer.EnableEmbeddedStyle = false;
        //layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyle.CreateSimpleLineStyle(GeoColor.FromArgb(255, 169, 195, 221), 2F, GeoColors.Black, 4F, false);
        //layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyle.CreateSimplePointStyle(PointSymbolType.Circle, GeoColors.Black, 5);
        //layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        //layer.Open();
        //mapView.CurrentExtent = layer.GetBoundingBox();
        //LayerOverlay layerOverlay = new LayerOverlay();
        //layerOverlay.Layers.Add(layer);
        //mapView.Overlays.Add(layerOverlay);
        //mapView.Refresh();




        mapView.MapUnit = GeographyUnit.DecimalDegree;

        KmlFeatureLayer layer = new KmlFeatureLayer(@"D:\Kml\KML_Samples.kml");
        layer.EnableEmbeddedStyle = false;
        layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyle.CreateSimpleLineStyle(GeoColor.FromArgb(255, 169, 195, 221), 2F, GeoColors.Red, 4F, false);
        layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyle.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 233, 232, 214), GeoColor.FromArgb(255, 156, 155, 154), 1);
        layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyle.CreateSimplePointStyle(PointSymbolType.Circle, GeoColors.Red, 5);
        layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        layer.Open();
        mapView.CurrentExtent = layer.GetBoundingBox();
        LayerOverlay layerOverlay = new LayerOverlay();
        layerOverlay.Layers.Add(layer);
        mapView.Overlays.Add(layerOverlay);
        mapView.Refresh();
    }

I attached you the sampleKml file KML_Samples.zip (7.9 KB)

The sample pdf file is the one you sent to us before.

You need use the latest mapsuite V12 and. also find the ThinkGeo.Kml and ThinkGeo.GeoPdf NuGet library.

Thanks

Frank

Hi Frank,

I tested the KML feature layer and it basically works, but with some shapes there are some problems. I have attached a zip file containing example project that has a simple rectangular shape in KML file over the city of Tampere.

ThinkGeoKmlTest.zip (12.2 KB)

When the application lauches, it looks like this:

If you zoom in, it will look even worse and more of the blue shape is missing.

If you zoom out, then the whole rectangle is visible:

Do we need to change some settings for the KmlFeatureLayer to fix this?

Thanks, Rasmus

And just to add that this doesn’t seem to be only concerning KML layer. I had similar results with a .SHP file that contains polygon shapes.

Br,
Rasmus

Hey @Rasmus_Rahunen,

I was able to recreate the issue with the sample you gave. We are investigating the issue now.

Could you attach a .SHP file that has the same issue? None of our shapefiles are showing that behavior.

Thanks,
Kyle

Hi Kyle,

After some testing, I can’t be anymore sure that is this the same problem. It could be that the rendering of the tiles can be so slow that you think that it is not working. The attached map of Finland is very very slow, when you zoom in: AppData.zip (663.7 KB)
It was downloaded from here: http://www.vdsgeo.com/osm-data.aspx (FIN_adm.zip)

I’m using this code to load it:

    private void mapView_Loaded(object sender, RoutedEventArgs e)
    {
        // Set the Map Unit.
        mapView.MapUnit = GeographyUnit.Meter;

        // Add a base map overlay.
        var cloudVectorBaseMapOverlay = new ThinkGeoCloudRasterMapsOverlay("USlbIyO5uIMja2y0qoM21RRM6NBXUad4hjK3NBD6pD0~", "f6OJsvCDDzmccnevX55nL7nXpPDXXKANe5cN6czVjCH0s8jhpCH-2A~~", ThinkGeoCloudRasterMapsMapType.Light);
        mapView.Overlays.Add(cloudVectorBaseMapOverlay);

        ShapeFileFeatureLayer.BuildIndexFile(@"AppData/FIN_adm0.shp", BuildIndexMode.Rebuild);
        var layer = new ShapeFileFeatureLayer(@"AppData/FIN_adm0.shp");
        layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyle.CreateSimpleAreaStyle(GeoColors.Blue);
        layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        layer.FeatureSource.ProjectionConverter = new ProjectionConverter(4326, 3857);

        layer.Open();
        mapView.CurrentExtent = layer.GetBoundingBox();

        LayerOverlay layerOverlay = new LayerOverlay();
        layerOverlay.Layers.Add(layer);
        mapView.Overlays.Add(layerOverlay);

        mapView.Refresh();
    }

Sometimes it can take tens of seconds to get the view updated after zooming in. But on higher zooming levels it works faster.

Is there something that can be done to speed up the rendering?

Thanks,
Rasmus

Hey @Rasmus_Rahunen,

Yeah, those are two seperate issues. Obviously, neither of them should be happening. I’m still doing some research on your issues. I’ll get back to you soon.

Thanks,
Kyle

Hi Kyle,

Thanks, looking forward to getting these solved.

BR, Rasmus

Hey @Rasmus_Rahunen,

Regarding your issue about the slow rendering of the Finland Shapefile, single large multipolygons can be really tricky to render because in order to calculate the drawing, we need to read the entire feature. And when in tile mode, that’s further needed on a per tile basis. There’s two things you can do to increase performance:

  1. Set your LayerOverlay’s TileType = TileType.SingleTile
  2. You can split the multipolygon into multiple features using a utility that I have attached to this post. Just point the directory to where your shapefiles are and it will split based on the area. You may want to lower the area values to suit the size of Finland to be split in more ways.

SplitPolygonsBasedOnDynamicGrid.zip (1.5 MB)

Thanks,
Kyle

Thanks Kyle,

We will study these possibilities. The provided example file is not a file that we want to use, but in some cases our customers may be loading big shape files, so it’s still a realistic use case.

But let’s concentrate on the KML file problem in this thread from now on.

Thanks, Rasmus

Thanks, Rasmus, I took over the KML issue from Kyle, just determined where the problem is in the code, still working on it. I will try giving some updates tomorrow.

Regards.
Johnny

Hi Rasmus,

It’s proved to an issue of the clipping the polygon which is invalid (Here should be the polygon is not closed to the starting point). To speed the performance, the ThinkGeo SDK thinks all features from the datasources, such as Shapefile, Kml etc. as the valid geometry, for example, the outring of the polygon should be the closed ring - the starting vertex should be same to the ending vertex. Take the attached KML as example:

It doesn’t work as expected with following coordinates array:

          23.751181,61.500110,0.000000
          23.770572,61.501645,0.000000
          23.771179,61.492102,0.000000
          23.754337,61.491247,0.000000

If we add another vertex (whose X/Y is equal to the starting vertex - 23.751181,61.500110,0.000000), all works as expected:

          23.751181,61.500110,0.000000
          23.770572,61.501645,0.000000
          23.771179,61.492102,0.000000
          23.754337,61.491247,0.000000
          23.751181,61.500110,0.000000

The same issue with the ShapeFile, I tired the solution by adding the “MakeValid” after reading the feature from datasources, however, it will slow down the performance, could you please try the workaround by making sure the the polygon is always closed?

Regards,
Johnny

Hi Johnny,

Thanks for the suggestion. I tried adding the following code:

if (layer is FeatureLayer featureLayer)
{
    featureLayer.Open();
    foreach (var feature in featureLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.NoColumns))
    {
        if (feature.GetShape() is PolygonShape polygonShape)
        {
            var rings = new List<RingShape> {polygonShape.OuterRing};
            rings.AddRange(polygonShape.InnerRings);
            foreach (var ringShape in rings)
            {
                if (ringShape.Vertices == null || ringShape.Vertices.Count < 1)
                    continue;

                Vertex first = ringShape.Vertices[0];
                Vertex last = ringShape.Vertices[ringShape.Vertices.Count - 1];
                if (first != last)
                    ringShape.Vertices.Add(first);
            }
        }
    }

}

However, it looks like the RingShape already contains 5 vertices, the first and last are equal… So we never end up in the innermost if statement, where the shape is supposed to get fixed, as it seems to be fixed already.

Is ThinkGeo already closing the RingShape internally, because the file contains only 4 vertices?

BR, Rasmus

Hi @Rasmus_Rahunen,

Thanks for digging into the detail and let me know. We didn’t do any changes. The reason is that the read and drawing system of KML is different from others, the GDAL is used to read the features from the KML file, here we take the WellknownBinary read from GDAL to create the Feature instance, we did the enhancements in feature creation method (Checking if the start vertex is different from the end vertex, if not, we will add the extra). That’s the reason why we can see all rings are correct checking by the codes you pasted.

The wellknownBinary(WKB) read from GDAL doesn’t have this enhancements, in other words, we only have 4 vertices in KML file, the WKB from GDAL only have 4 vertices. The problem is here. The drawing system read the coordinates for drawing from WKB, thus only 4 vertices there, and runs into problem when doing polygon clip.

Thanks for your information again. I guess maybe we can do some improvements in drawing system according to your discovery. We will take a try and let you know if it can be fixed.

Thanks,
Johnny

Hi @Rasmus_Rahunen,

We took some hours to dig into the detail, but sorry that it’s unable to do the change. I guess I made a mistake before, the exception comes from “GDAL”, when reading features with a specific boundingbox. As we know, the Wpf map is working with multi-tile mode, in other words, just like the picture below, we don’t have Geometry from a~b, thus, it’s blank inside the “BLACK” square, so no polygon can be drawn there.

image

Besides, if the rings of the polygon is not closed, sometimes we maybe get the following exception from GDAL as well:

So I suggest that the workaround is creating a tool to run all the KML files and make sure all rings are closed, if not, we can add the extra vertex.

Regards,
Johnny