tar -C /usr/local -xzf go1.17.6.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
apt-get install pkg-config
apt-get install build-essential
go get github.com/airbusgeo/godal
go build road_extractor.go
package main
import (
"fmt"
"github.com/airbusgeo/godal"
"time"
)
func init() {
fmt.Println(234)
godal.RegisterAll()
}
func getR(rPath string) (map[string]string, map[string]*godal.Geometry, ) {
hDS, err := godal.Open(rPath, godal.VectorOnly())
if err != nil {
panic(err)
}
layer := hDS.Layers()[0]
layer.ResetReading()
geomMap := make(map[string]*godal.Geometry)
adminMap := make(map[string]string)
for {
feat := layer.NextFeature()
if feat == nil {
break
}
fields := feat.Fields()
geom := feat.Geometry()
ID := fields["Route_ID"].String()
adminMap[ID] = fields["Path_Name"].String()
geomMap[ID] = geom
geom.Close()
feat.Close()
break
}
hDS.Close()
return adminMap, geomMap
}
func getRouteIdLinks(rLNamePath, rNamePath string) {
mapTest := make(map[string][]int)
list := []string{"1", "2", "2", "3"}
for i, k := range list {
v, ok := mapTest[k]
if ok {
v = append(v, i)
mapTest[k] = v
} else {
mapTest[k] = []int{i}
}
}
fmt.Println(mapTest)
}
func RoadExtractor(rPath string) {
startT := time.Now()
adminMap, geomMap := getR(rPath)
fmt.Println(len(adminMap))
fmt.Println(len(geomMap))
tc := time.Since(startT)
fmt.Printf("time cost = %v\n", tc)
//getRouteIdLinks(rLNamePath, rNamePath)
}
func main() {
RoadExtractor("/tmp/sll/bj.shp")
}
网友评论