-
Notifications
You must be signed in to change notification settings - Fork 13
/
kmz_test.go
53 lines (47 loc) · 1.01 KB
/
kmz_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package kml_test
import (
"archive/zip"
"bytes"
"fmt"
"io"
"os"
"github.com/twpayne/go-kml/v3"
)
func ExampleWriteKMZ() {
doc := kml.KML(
kml.Placemark(
kml.Name("Zürich"),
kml.Point(
kml.Coordinates(
kml.Coordinate{Lat: 47.374444, Lon: 8.541111},
),
),
),
)
var buffer bytes.Buffer
buffer.Grow(512)
if err := kml.WriteKMZ(&buffer, map[string]any{
"doc.kml": doc,
}); err != nil {
panic(err)
}
zipReader, err := zip.NewReader(bytes.NewReader(buffer.Bytes()), int64(buffer.Len()))
if err != nil {
panic(err)
}
for _, zipFile := range zipReader.File {
fmt.Println(zipFile.Name + ":")
file, err := zipFile.Open()
if err != nil {
panic(err)
}
if _, err := io.Copy(os.Stdout, file); err != nil { //nolint:gosec
panic(err)
}
file.Close()
}
// Output:
// doc.kml:
// <?xml version="1.0" encoding="UTF-8"?>
// <kml xmlns="http://www.opengis.net/kml/2.2"><Placemark><name>Zürich</name><Point><coordinates>8.541111,47.374444</coordinates></Point></Placemark></kml>
}