美文网首页
godal shp map

godal shp map

作者: hehehehe | 来源:发表于2022-03-08 16:45 被阅读0次
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")
}


相关文章

网友评论

      本文标题:godal shp map

      本文链接:https://www.haomeiwen.com/subject/jjbarrtx.html