Code Monkey home page Code Monkey logo

simple-kml's Introduction

Simple KML: Cocoa parsing library for Keyhole Markup Language

Simple KML is a simple & lightweight parsing library for KML written in Objective-C for the iOS platform.

It is not meant for drawing, but rather for parsing. That is, it is up to the developer to turn the data structures returned by Simple KML into drawing code, be it for annotations in MapKit, constructs in an external mapping library, drawing paths on a UIImage, or otherwise.

Simple KML is basically an XML parser with smarts about KML. It presents a hierarchical view of KML data and can turn things like Simple KML color definitions into UIColor and text coordinates into CLLocation so that you don't have to.

Requirements

Simple KML has been designed & built for iOS 5.0 and greater. There's no particular reason it couldn't be adapted to Mac OS X; it just hasn't been done yet out of lack of necessity.

Simple KML is built for ARC.

Simple KML depends on TouchXML, an Objective-C library for DOM-based XML parsing based on libxml2, and Objective-Zip, a library for working with archive files, both of which are included in the download.

Features

  • Support for most of the base KML entities.

    Basic support for Object, Feature, Placemark, Container, Document, Folder, Geometry, Point, LineString, LinearRing, Polygon, StyleSelector, Style, SubStyle, BalloonStyle, ColorStyle, LineStyle, PolyStyle, and IconStyle.

  • Simple invocation.

    SimpleKML *myKML = [SimpleKML KMLWithContentsOfFile:@"/path/to/file.kml" error:&error]
    SimpleKML *myKML = [SimpleKML KMLWithContentsOfURL:[NSURL URLWithString:@"http://example.com/file.kml"] error:&error]

  • Support for KMZ archives.

    Currently searches for a top-level KML file in the archive and retrieves icon data for bundled IconStyle entities.

  • Cocoa-native behavior.

    Native types:

    SimpleKMLLineStyle *lineStyle = myPolygon.lineStyle; UIColor *lineColor = lineStyle.color;
    NSArray *polygonPoints = myPolygon.outerBoundary.coordinates; // CLLocation objects
    UIColor *textColor = myPlacemark.style.balloonStyle.textColor;
    UIImage *icon = myPlacemark.style.iconStyle.icon; // planned: automatically apply scale, heading, and parent style color

    Intelligent parsing:

    SimpleKMLStyle *inlineStyle = myPlacemark.inlineStyle; // within <Placemark>
    SimpleKMLStyle *sharedStyle = myPlacemark.sharedStyle; // common to <Document>; no need to reference <StyleUrl>
    SimpleKMLStyle *activeStyle = myPlacemark.style; // the inline style overrides the shared style

    SimpleKMLGeometry *geometry = myPlacemark.geometry; // <Point>, <Polygon>, <LineString>, <MultiGeometry>, etc.
    SimpleKMLPoint *point = myPlacemark.point; // shortcut if <Point> exists for <Placemark>

    Smart error handling:

    NSError *error;
    SimpleKML *myKML = [SimpleKML KMLWithContentsOfFile:@"invalid.kml" error:&error];
    if (error) { NSLog(@"%@", error); } // SimpleKMLParseError: Improperly formed KML (LinearRing has less than four coordinates)

    Debugging:

    gdb: po [mySimpleKMLObject source] // protected variable containing original XML source

    Hierarchies:

    SimpleKMLDocument *document = myPlacemark.document;
    NSArray *documentFeatures = document.features;

Usage

Be sure to clone recursively (git clone --recursive or git submodule update --init) in order to grab the dependent submodules Objective-Zip and TouchXML.

Include all of the Simple KML files in your Xcode project, as well as the files in the TouchXML and Objective-Zip subdirectories if you don't already use these in your project.

Per TouchXML's installation guide, add /usr/include/libxml2 to your "Header Search Paths" and -lxml2 to your "Other Linker Flags" since TouchXML depends on libxml2.

You'll also need to link against CoreLocation.framework and libz.dylib.

Plans, needs, bugs, etc.

If you find a bug or want to otherwise contribute, please fork the project on GitHub and contribute that way. In particular, I would like to start adding built-in testing with a library of accompanying KML test files to parse.

License

Copyright (c) 2010-2013 MapBox.

The Simple KML library should be accompanied by a LICENSE file. This file contains the license relevant to this distribution. If no license exists, please contact MapBox.

simple-kml's People

Contributors

gaving avatar incanus avatar itfrombit avatar rencire avatar veerasrinivasan avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.