Hi,
I would like to export selected features (with column data) from my map to a KML file that can then be used by Google Earth or any similar type viewer. So the process would be roughly:
1. Select and highlight some features, e.g. by dragging a rectangle. [Can do this OK]
2. Click a button or connect menu item to start export. [Can do this OK]
3. Create a new KML file with the selected features - styled as per map and keeping column data. [Stumped on this bit]
I see that ThinkGEO Map Suite does have KMLFeatureLayer and KMLFeatureSource classes but I am unsure how to start using them. For example I can declare a new layer, but when I open it I get a file does not exist error (this wold be true but I was hoping it would make a new one) or if I create a file using File.Create(filePath) before opening I get a root element does not exist.
Regards,
Jonathan
Create a KML File
Hi Jonathan,
I am sorry, but it looks our KMLFeatureLayer and KMLFeatureSource is mainly for render KML files but not for create KML files. So they shouldn’t be helpful for your scenario.
Here we have a topic talk about this, I think it should be helpful: thinkgeo.com/forums/MapSuite/tabid/143/aft/5547/Default.aspx
Regards,
Don
Thanks for the example code. I did notice a bit earlier that KmlLayer has some static methods, such as .AddLayerToKml that looked useful and did produce files quite nicely, but not, I think, with column data?
Regards,
Jonathan
[P.S. Sorry sent this to the wrong thread a few moments ago]
Hi,
The example has been very helpful but I am stuck on how to include the individual features’ column data in the KML file. As a quick test I added this to DrawAreaCore() to show some fixed values, however DrawAreaCore doesn’t appear to have access to the actual feature or the column data so I cannot see a clear way ahead. Any suggestions?
Regards,
Jonathan
contentStringBuilder.AppendLine(@"<
ExtendedData
>");
string dataLine = string.Format(@"<
Data
name
=
""
{0}"">",“MY DATA”);
contentStringBuilder.AppendLine(dataLine);
contentStringBuilder.AppendLine(@"<
value
>1</
value
>");
contentStringBuilder.AppendLine(@"</
Data
>");
contentStringBuilder.AppendLine(@"</
ExtendedData
>");
Hi Jonathan,
Don’t worry the last post. It looks you put the same question in the mentioned post, we can reply you there.
Regards,
Don
Hi again,
I hope the post to the wrong thread a while ago hasn’t confused things too much and I wondered if you got the message dated 10-28-2015 08:24 AM OK.
Thanks,
Jonathan
Hi Jonathan,
I am sorry I hadn’t noticed you reply here again.
It looks in this solution, you cannot get the column values. I tried to help you solve that but failed on it.
If you have to implement that, maybe you need to find another solution.
In fact, you only want to convert everything to XML, so why not directly loop all features and build noods for each of them?
Regards,
Don
Don,
OK, thanks. I have switched it to looping through all features but managed to keep quite a lot of the writing to the file code from your solution - it does work well. I think the advantage of your way is that any clever styling would be automatically resolved already (such as value styles) at the point of writing the feature to the file, whereas my version can handled column values easily but would need a lot more work if I want to maintain those types of style.
Regards,
Jonathan
Hi Jonathan,
Yes you’re right, our sample version is follow our entire architecture, it draw shapes to KML just like to draw in map. But in fact it’s not designed to do this, so you will met some issue like the column values cannot be found in the override function. In fact in the base layer of it, the feature can be found in the function, but we cannot pass it to the DrawAreaCore function because in other GeoCanvas it only allow to pass shape but not feature in.
Any question please let us know.
Regards,
Don
OK, that makes sense. Is there a way to get a feature’s styling if you know the zoom level? It would be nice if there was something like:
GeoBrush brush myFeature.GetFill(currentZoomLevel) and so on?
Thanks,
Jonathan
Hi Jonathan,
I think we don’t have the API like this, and in fact the feature don’t contains style in our map.
If you have a feature, you need to know what’s the shape it is by Feature.GetShape, if it’s area, you should want to find the zoomlevel of this layer, then find custom styles at first, if custom styles don’t contains anything, you then go to area style and see whether for all 20 levels it’s the same. For point shape and line shape, it’s the same steps.
Wish that’s helpful.
Regards,
Don
Hi,
Thanks - that is a bit unfortunate as we use quite a lot of different styles such as Value and Class Break (user configurable) and also apply them at different zoom levels so there would be a great deal of decision making needed if we want to preserve the applied styling when saving to KML and naturally ThinkGEO’s MapSuite already does all that decision making when rendering the map on screen normally. What I have done so far is working quite nicely so I think a bit of a shortcut on styling - effectively using defaults - maybe the best bet at the moment.
All the best,
Jonathan
Hi Jonathan,
I am sorry we cannot help you on this, it use default should be the simplest here.
Regards,
Don
Don,
That’s OK. Despite a couple of limitations what we have done is really quite nice and should be fine for the first release.
Regards,
Jonathan
Hi Jonathan,
I am glad to hear you get a good progress on it, any further question please feel free to let us know.
Regards,
Don