Go Down

Topic: Parse a KML file on an SD with a sketch ? (Read 2050 times) previous topic - next topic


Aug 28, 2009, 03:15 am Last Edit: Aug 28, 2009, 03:18 am by adr1an Reason: 1
I'm shortly wanting to create some 'boundary' polygons that I wish to use in a sketch along with some real-time GPS data.

Basically, my idea is, create the data with googlemaps/earth, save the kml file to an SD card, load SD card into Arduino via appropriate hardware interface and library (I have a µMicroSD drive which does FAT files via serial, but standard SDMMC Lib is ok as well)  and then within the sketch parse these co-ordinates into RAM.

Now Im guessing this involves reading the file using the appropriate commands, then looping through it line by line to build the various variables and then moving on to processing the GPS data with those now-loaded variables.

I have looked,and could find sketches that OUTPUT KML data to serial (by just building the serial.print's in the appropriate format, not really through interpretation with variables) but can't find any KML/XML (since its the same thing) processing other than this one designed for an ethernetshield:

Alternatively, is there even just a "Config File" library like there is for PERL that makes it easy to load run-time values from a 'file' 'somewhere' (i say 'file' 'somewhere' because really, it could be a dynamic value prepared elsewhere and just dumped via serial even...)

Anyone have any tips or suggestions where I could look or perhaps seek some guidance from to adapt ?

Thanks everyone!

Checkout my projects development blog @ SLiDA


Sep 02, 2009, 03:42 am Last Edit: Sep 02, 2009, 03:49 am by adr1an Reason: 1
Am I already on the right track and there is no better way ?

Or do I need to rephrase my question maybe and don't make sense (not unlikely!  ;D ) ?

Thanks everyone
Checkout my projects development blog @ SLiDA


Hi Adr1an;

I hope I can help...  While I don't have the examples you are asking about, I have some experience with lots of data in less than "a lot" of RAM.

What I have tried to do in the past is process the data into my own packed format on a Desktop machine and keep the microcontroller data as small as possible.  In your case, you could drop a binary file with the processed data on the SD card.  It sounds like you may have more than the 512 bytes that the built in the EEPROM that I was using...

For example:
{Polygon1:[NUMCOORDS][DESCRIPTION][X1][Y1][X2][Y2]} {polygon2} {polygon3} etc..

Instead of wasting space with <, >, = "" \r\n and all the formatting of XML, you have just what you need, and nothing more.  The design of the packing format for the data will be key!

On boot in the arduino, you could then walk the structure, even without loading it in RAM and do what you need.

If you are tracking the arduino or the dude with the arduino strapped to him across various GPS coordinates, you could even split the files on the SD card into geographic regions with smaller chunks of data.  The arduino then just has to load that small area based on region, parse the data - and do what it needs from there.

such as:

Get GPS Coords from GPS device
Calculate region.  For example, determined to be in region N45,W155 of the earth.
Open file N45W155.bin (if it exists)
Read through file with polygons and return the description of the one that the dude is in.
Get amount of voltage from file to determine how much juice to jolt the dude holding the arduino with.
Do it: Jolt Him!
go back and check again.  See if he ran out of the polygon fast enough to not warrant another jolt.

I find that although the intermediate step of the files may be considered a problem at design time, in the end you have something that wouldn't normally be possible.

(on-the-market GPS devices do similar things, except the map is broken into regions with a table - having a 4GB file and multiple sections...)

Damn it, now I want to try that.  Why are these arduino's so much fun?



Why do you thinks it's necessary to do that kind of work within the Arduino?

Create a script (I'd use PHP or PERL) within your own webspace that will connect to the NOAA site scrape the data you need, present it as a string in the exact format you want within the Arduino, and serve it as the web page.  

Then point your Arduino at your script instead of the NOAA page and it will receive the data as a string already in the correct format.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131