-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.go
35 lines (30 loc) · 825 Bytes
/
convert.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
package main
import (
"bytes"
"fmt"
"log"
"os/exec"
)
var geoformats = map[string]string{
"json": "GeoJSON",
"kml": "KML",
}
// ogr2ogr -f GeoJSON (KML) -t_srs crs:84 -s_srs crs:84 result.json (result.kml) merge.shp
func convertTo(shapefile, format string) error {
log.Println("Shapeile converting...")
result := fmt.Sprintf("result/%s/result.%s", format, format)
geoformat := geoformats[format]
args := []string{"-f", geoformat, "-t_srs", "crs:84", "-s_srs", "crs:84", result, shapefile}
cmd := exec.Command(ogr2ogr, args...)
var stderr bytes.Buffer
var stdout bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return err
}
log.Println(fmt.Sprintf("%s is generated succesfully.", result))
return nil
}