ThinkGeo.com    |     Documentation    |     Premium Support

Create KML File not working as intended

Hi ThinkGeo Forum,

I have been attempting to create a KML file with a list of MapShapes following an example I saw in a sample creating a kml file from a shapefile. I can successfully create a blank KML file with “KmlLayer.CreateKmlFile(strTempPath + “test.kml”)” but receive the error “The Layer must be opened before you can perform this method.” (as shown in the image) when I attempt to include the list of MapShapes. Any suggestions on how to fix this since executing the function this way it is impossible to open the Layer?

Thanks,

Neil

Hi Neil,

Please upgrade your dll packages into our latest 10.2.0, and I did a quickly test, it looks the CreateKmlFile function works well.

If you want to do some operation for the existing kml file, please open it by the KmlLayer again and open it before use it.

Regards,

Ethan

Hi Ethan,

We have just updated to 10.2 with all of the dlls to test out this fix and the issue is still occurring. May I reiterate that we are successful in creating a new KML file that is blank like the example you are showing above; however, we are NOT able to create one with MapShapes pertaining to this method,“public static void CreateKmlFile(string pathFilename, IEnumerable mapShapes);”. Whenever we try to create the KML file passing in MapShapes we receive an error “The Layer must be opened before you can perform this method.”. Is there anything we are missing with this process?

Thank you,

Neil

Hi Neil,

Thanks to let us know the API where is the problem.

We reproduced that today, and our developer will look into it.

Any update I will let you know.

Regards,

Ethan

Hi Neil,

Please get this package: ThinkGeo.MapSuite.Layers.Kml 11.0.0-beta009, it should get update in one or two days.

Please test that with the following code:

 Collection<MapShape> mapShapes = new Collection<MapShape>();
        var mapShape = new MapShape();
        var lineShape = new LineShape();
        lineShape.Vertices.Add(new Vertex(-0.001, 0));
        lineShape.Vertices.Add(new Vertex(0.001, 0));
        mapShape.Feature = new Feature(lineShape);
        mapShape.ZoomLevels.ZoomLevel01.DefaultLineStyle = new LineStyle(new GeoPen(new GeoSolidBrush(GeoColor.SimpleColors.Red), 2));
        mapShape.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        mapShapes.Add(mapShape);

        KmlLayer.CreateKmlFile("Test.kml", mapShapes);

And please notice for this API the map shapes should under 4326.

Regards,

Ethan

Hi Ethan,

I tested it out and was able to have everything working. I noticed that the width value passed into the GeoPen isn’t reflected in the KML file but the color is accurately passed to the file. Also is there a way to name each KML feature using MapShapes? Anyways, the issue I was having before is not occurring.

Thank you,

Neil

Hi Neil,

Thanks to let us know that, that’s a bug and we had fixed it.

Please get the https://www.nuget.org/packages/ThinkGeo.MapSuite.Layers.Kml/11.0.0-beta011, you can download it in one days after Nuget refresh the page.

Regards,

Ethan

Hi Ethan,

That update worked and now the features width is accurate. I was wondering as well, is there a way to set the MapShape value to populate the KML feature name? I noticed all the MapShapes we are passing in do not populate the name field and I don’t know if there is a property we can set that easily performs this. If you can let me know soon we would appreciate that.

Thanks,
Neil

Hi Neil,

The kml feature id should be a new GUID and the feature name should hadn’t get set if you create the KML file by our KMLFeatureLayer.

And I quickly read related code, it looks this is not easy to be implemented under currently structure.

Regards,

Ethan

Hi Ethan,

So the best way to pass data to the KML file such as name and other data is through the KMLFeatureLayer? In my effort to add features to the KMLFeatureLayer through the “FeatureSource” property yields the error message “The FeatureSource is not editable”. Is there a better way to add features to the KMLFeatureLayer? Also I noticed that the KMLFeatureSource has the capability to add columns and data associated to those columns through the add features (Picture below)?

Thank you for your help!

Neil

Hi Neil,

  1. The KMLFeatureLayer only support load existing KML file, all the tag in placemark will be saved in column values.
  2. The KMlLayer support create KML file, but the only information it can saved is the shape, the other information for example “name” cannot be saved.

I double check this with our developer today, I think we don’t have other API to implement your requirement.

Regards,

Ethan