Package kml provides convenince methods for creating and writing KML documents.

Overview

go-kml

PkgGoDev

Package kml provides convenience methods for creating and writing KML documents.

Key Features

  • Simple API for building arbitrarily complex KML documents.
  • Support for all KML elements, including Google Earth gx: extensions.
  • Compatibilty with the standard library encoding/xml package.
  • Pretty (neatly indented) and compact (minimum size) output formats.
  • Support for shared Style and StyleMap elements.
  • Simple mapping between functions and KML elements.
  • Convenience functions for using standard KML icons.
  • Convenience functions for spherical geometry.

Example

func ExampleKML() {
    k := kml.KML(
        kml.Placemark(
            kml.Name("Simple placemark"),
            kml.Description("Attached to the ground. Intelligently places itself at the height of the underlying terrain."),
            kml.Point(
                kml.Coordinates(kml.Coordinate{Lon: -122.0822035425683, Lat: 37.42228990140251}),
            ),
        ),
    )
    if err := k.WriteIndent(os.Stdout, "", "  "); err != nil {
        log.Fatal(err)
    }
}

Output:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Placemark>
    <name>Simple placemark</name>
    <description>Attached to the ground. Intelligently places itself at the height of the underlying terrain.</description>
    <Point>
      <coordinates>-122.0822035425683,37.42228990140251</coordinates>
    </Point>
  </Placemark>
</kml>

There are more examples in the documentation corresponding to the examples in the KML tutorial.

Subpackages

  • icon Convenience functions for using standard KML icons.
  • sphere Convenience functions for spherical geometry.

License

MIT

Comments
  • Export private fields in SimpleElement, CompoundElement and SharedElement

    Export private fields in SimpleElement, CompoundElement and SharedElement

    Export private fields to create custom elements

    customElement := &kml.CompoundElement{
        StartElement: xml.StartElement{Name: xml.Name{Local: "Folder"}, Attr: []xml.Attr{{Name: xml.Name{Local: "id"}, Value: "myCustomID"}}},
        Children: []kml.Element{
            kml.Name("My custom folder name"),
        },
    }
    
    k := kml.KML(
        customElement,
    )
    
    if err := k.WriteIndent(os.Stdout, "", "  "); err != nil {
        log.Fatal(err)
    }
    

    Output

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
      <Folder id="myCustomID">
        <name>My custom folder name</name>
      </Folder>
    </kml>
    
    opened by jonamat 7
  • nit: README.md example should use Document(…)

    nit: README.md example should use Document(…)

    Thanks for this useful library!

    I noticed that the example from README.md cannot be imported into Google Earth as-is because it nests Placemarks underneath the <kml> tag, whereas it should nest them underneath a <Document> tag.

    Other examples are correct in that regard, but it would be good to fix this one, too, I think :)

    opened by stapelberg 3
  • More Flexibility inside *Elements Structs

    More Flexibility inside *Elements Structs

    // A SimpleElement is an Element with a single value.
    type SimpleElement struct {
    	xml.StartElement
    	value string
    }
    
    // A CompoundElement is an Element with children.
    type CompoundElement struct {
    	xml.StartElement
    	children []Element
    }
    
    // A SharedElement is an element with an id.
    type SharedElement struct {
    	CompoundElement
    	id string
    }
    

    Those struct should have get/setter for custom user modifications See below an example for SimpleElement.

    func (s *SimpleElement) GetValue(value string) {
        s.value = value
    }
    

    That allow user to customize Element or create new ones.

    opened by jhonore 2
  • Neatly wrap multi-line strings

    Neatly wrap multi-line strings

    Currently strings are written on a single line, e.g.

    <description>Attached to the ground. Intelligently places itself at the height of the underlying terrain.</description>
    

    It would be nice if these strings were split to some width (e.g. 80 columns) when the output is pretty, e.g.

    <description>
      Attached to the ground. Intelligently places itself at the height of the
      underlying terrain.
    </description>
    

    This is similar to #5 in that it requires MarshalXML to know whether the indent is not empty.

    enhancement 
    opened by twpayne 1
  • Neatly indent coordinates

    Neatly indent coordinates

    Currently <coordinates> are emitted on a single line, e.g.

    <coordinates>1,2,3 4,5,6 7,8,9</coordinates>
    

    It would be nice if coordinates, when emitted with WriteIndent were neatly indented, e.g.

    <coordinates>
      1,2,3
      4,5,6
      7,8,9
    </coordinates>
    

    This would required Coordinates.MarshalXML to "know" whether it is being called in pretty or compact node. This information is currently not exported by the standard encoding/xml library.

    enhancement 
    opened by twpayne 1
  • Add support for KML 2.3

    Add support for KML 2.3

    The package currently contains all elements in KML 2.2. There is a specification for KML 2.3: http://www.opengeospatial.org/standards/kml#downloads

    The package should be extended to support KML 2.3.

    enhancement 
    opened by twpayne 1
  • Add run-time validation of KML documents

    Add run-time validation of KML documents

    As raised by @stapelberg in #1, currently the package offers no protection against generating invalid KML documents (indeed, it is an explicit non-goal of the package).

    It would be great if the package could offer run-time verification of KML documents as a sanity check in the absence of #2.

    enhancement 
    opened by twpayne 1
  • Add compile-time protection against generating invalid KML documents

    Add compile-time protection against generating invalid KML documents

    As raised by @stapelberg in #1, currently the package offers no protection against generating invalid KML documents (indeed, it is an explicit non-goal of the package).

    It would be great if the package could offer compile-time protection against generating invalid documents.

    enhancement 
    opened by twpayne 1
Owner
Tom Payne
Tom Payne
A library provides spatial data and geometric algorithms

Geoos Our organization spatial-go is officially established! The first open source project Geoos(Using Golang) provides spatial data and geometric alg

spatial-go 538 Sep 17, 2022
Go package to quick and easy create json data in geojson format.

#GEOJSON Go package to easy and quick create datastructure which can be serialized to geojson format INSTALLATION $ go get github.com/kpawlik/geojson

Kris Pawlik 50 Jun 6, 2022
Package polyline implements a Google Maps Encoding Polyline encoder and decoder.

go-polyline Package polyline implements a Google Maps Encoding Polyline encoder and decoder. Encoding example func ExampleEncodeCoords() { coords :=

Tom Payne 73 Sep 2, 2022
Package geom implements efficient geometry types for geospatial applications.

go-geom Package geom implements efficient geometry types for geospatial applications. Key features OpenGeo Consortium-style geometries. Support for 2D

Tom Payne 615 Sep 25, 2022
A pure Go package for coordinate transformations.

WGS84 A pure Go package for coordinate transformations. go get github.com/wroge/wgs84 Usage east, north, h := wgs84.LonLat().To(wgs84.ETRS89UTM(32)).R

Malte Wrogemann 90 Sep 26, 2022
yet another point in polygon package

piper Yet another point in polygon package. Piper makes use of ray casting and does account for holes in polygons. Installation go get -u github.com/i

Ben 11 Feb 24, 2022
Encoding and decoding GeoJSON <-> Go

go.geojson Go.geojson is a package for encoding and decoding GeoJSON into Go structs. Supports both the json.Marshaler and json.Unmarshaler interfaces

Paul Mach 214 Sep 10, 2022
Types and utilities for working with 2d geometry in Golang

orb Package orb defines a set of types for working with 2d geo and planar/projected geometric data in Golang. There are a set of sub-packages that use

Paul Mach 576 Sep 19, 2022
Publish Your GIS Data(Vector Data) to PostGIS and Geoserver

GISManager Publish Your GIS Data(Vector Data) to PostGIS and Geoserver How to install: go get -v github.com/hishamkaram/gismanager Usage: testdata fol

Hisham waleed karam 48 Sep 26, 2022
Real-time Geospatial and Geofencing

Tile38 is an open source (MIT licensed), in-memory geolocation data store, spatial index, and realtime geofence. It supports a variety of object types

Josh Baker 8.3k Sep 19, 2022
Pure go library for creating and processing Office Word (.docx), Excel (.xlsx) and Powerpoint (.pptx) documents

unioffice is a library for creation of Office Open XML documents (.docx, .xlsx and .pptx). Its goal is to be the most compatible and highest performan

UniDoc 3.5k Sep 24, 2022
Package iter provides generic, lazy iterators, functions for producing them from primitive types, as well as functions and methods for transforming and consuming them.

iter Package iter provides generic, lazy iterators, functions for producing them from primitive types, as well as functions and methods for transformi

Matthew Toohey 25 Aug 19, 2022
Error handling hook & helper function to simplify writing API handler methods in Go.

Error handling hook & helper function to simplify writing API handler methods in Go.

Steven Frew 0 Jan 19, 2022
Package git provides an incomplete pure Go implementation of Git core methods.

git Package git provides an incomplete pure Go implementation of Git core methods. Example Code: store := git.TempStore() defer os.RemoveAll(string(st

Daniel Skinner 27 Mar 1, 2022
Monkey programming language project from 'Writing An Interpreter In Go'and 'Writing A Compiler In Go' Books

Monkey Monkey programming language ?? project from "Writing An Interpreter In Go

Amr Hesham 1 Dec 16, 2021
Go package providing opinionated tools and methods for working with the `aws-sdk-go/service/cloudfront` package.

go-aws-cloudfront Go package providing opinionated tools and methods for working with the aws-sdk-go/service/cloudfront package. Documentation Tools $

aaronland 0 Feb 2, 2022
A Go (golang) package that enhances the standard database/sql package by providing powerful data retrieval methods as well as DB-agnostic query building capabilities.

ozzo-dbx Summary Description Requirements Installation Supported Databases Getting Started Connecting to Database Executing Queries Binding Parameters

Ozzo Framework 574 Sep 22, 2022
This package provides a framework for writing validations for Go applications.

github.com/gobuffalo/validate This package provides a framework for writing validations for Go applications. It does provide you with few validators,

Buffalo - The Go Web Eco-System 74 Sep 4, 2022
This is an experimental package for working with JSON-LD documents in Go

JSON-LD ?? Simple JSON-LD in Go This is an experimental package for working with JSON-LD documents in Go. Experimental, Pre-Alpha Quality Please do no

null 3 Jul 6, 2022
Package create provides a generic option pattern for creating new values of any type

create Package create provides a generic option pattern for creating new values

null 1 Dec 30, 2021