I'm trying to create a data visualization in Unity using kml data. Without worrying too much about what's in the kml files, I'm trying to figure out the best way to:
I'm curious if anyone else has worked on this or has ideas about the best way to go around it. The biggest consideration is always speed, of course, and I'm not a programmer by background, so while I could hack something together it would be a far-from-optimal solution.
I poked around on the Unity forums for an xml parser, and I've seen the csharp System.Xml.XmlReader (XmlTextReader, etc.) mentioned. It appears that there are different ways to access XML: from a text file or URI, from an xml node, from a dictionary, etc.
What would be the best (quickest) way to store and access the xml data without maxing out memory and bogging Unity down? Save it as a local text or binary file and parse as needed? Save it in memory as a node? Parse straight from the URI? Something else entirely?
asked Aug 10 '11 at 07:22 PM
It's been a while since I asked this question, and in the meantime we've mostly solved the issue. I'd like to share our solution for anyone else that's trying to do the same thing.
We ended up using SharpKml (http://sharpkml.codeplex.com/), which is a .NET implementation of the entire KML 2.2 specification.
SharpKml is meant for .NET 4.0, so there are some issues to overcome, things like missing classes (Tuple) and methods (Enum.HasFlag). However, if you go through each of the errors with a google search, you will find ways to fake everything in .NET 3.5. I ended up adding a 2-tuple and 3-tuple implementation and some extension methods to get everything fixed. Once you do so, it works just fine in Unity.
Another issue is that you'll need the Ionic.Zip library to do kmz, and that library doesn't run nice in the webplayer - some issues with unmanaged code due to various encoding things. We were able to solve it, but that's an issue for another post :)
Once you get that all set up, then you just have to build a framework around that library that translates between the metadata within the KML (styles, etc.) to your Unity objects, and presto - you have support for KML. It's not easy, by any stretch of the imagination - it took a pro like me a few days to get it running, let alone create a framework - but it's doable and supports the entire KML specification.
answered Mar 04 at 02:37 AM