Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rzajac/kml
Package `kml` provides methods for constructing and exploring KML files.
https://github.com/rzajac/kml
Last synced: 3 days ago
JSON representation
Package `kml` provides methods for constructing and exploring KML files.
- Host: GitHub
- URL: https://github.com/rzajac/kml
- Owner: rzajac
- License: apache-2.0
- Created: 2021-01-07T12:34:05.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-26T08:49:02.000Z (almost 4 years ago)
- Last Synced: 2024-06-20T10:27:54.806Z (5 months ago)
- Language: Go
- Size: 67.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Go Report Card](https://goreportcard.com/badge/github.com/rzajac/kml)](https://goreportcard.com/report/github.com/rzajac/kml)
[![GoDoc](https://img.shields.io/badge/api-Godoc-blue.svg)](https://pkg.go.dev/github.com/rzajac/kml)# KML
Package `kml` provides methods for constructing and exploring KML files.
# Installation
```
go get github.com/rzajac/kml
```# Usage
## Unmarshal, explore, edit, marshal
```
data, err := os.Open("example.kml")
checkErr(err)root := KML()
err := xml.Unmarshal(data, root)
checkErr(err)// Explore. See documentation for available methods.
id := k.ChildAtIdx(0).Attribute("id").Value// Edit.
root.ChildAtIdx(0).ChildAtIdx(2).ChildAtIdx(0).SetContent("new value")// Marshal.
data, err := xml.Marshal(root)
checkErr(err)
```## In place KML construction and writing.
```
// Create KML.
k := kml.KML(
kml.Document(
kml.Name("document name"),
kml.Style(
kml.AttrID("sty_0"),
kml.LabelStyle(
kml.Color("01020304"),
kml.Scale(1),
),
kml.LineStyle(
kml.Color("05060708"),
kml.Width(3.5),
),
kml.PolyStyle(
kml.Color("090a0b0c"),
kml.Outline(true),
),
),
kml.Folder(
kml.AttrID("fld_0"),
kml.Name("folder name"),
kml.Snippet("snip", kml.AttrMaxLines(1)),
kml.Placemark(
kml.AttrID("pm_0"),
kml.Name("placemark name"),
kml.Description("placemark description"),
kml.StyleURL("#sty_0"),
kml.MultiGeometry(
kml.LineString(
kml.Tessellate(true),
kml.Coordinates("0.1,0.2,0.3 1.1,1.2,1.3"),
),
),
),
),
),
)// Encode and print created KML.
buf := &bytes.Buffer{}
enc := xml.NewEncoder(buf)
enc.Indent("", " ")
if err := enc.Encode(k); err != nil {
panic(err)
}fmt.Println(buf.String())
```will print:
```
document name
<LabelStyle>
<color>01020304</color>
<scale>1</scale>
</LabelStyle>
<LineStyle>
<color>05060708</color>
<width>3.5</width>
</LineStyle>
<PolyStyle>
<color>090a0b0c</color>
<outline>1</outline>
</PolyStyle>
folder name
snip
placemark name
placemark description]]>
#sty_0
1
0.1,0.2,0.3 1.1,1.2,1.3
```
## TODO
- Add missing methods for in place KML construction.
## License
Apache License, Version 2.0