美文网首页
How to parse shapefile for golan

How to parse shapefile for golan

作者: baboon | 来源:发表于2016-03-24 16:16 被阅读104次

Please refer to https://github.com/jonas-p/go-shp

Examples

Reading a shapefile

// open a shapefile for reading
shape, err := shp.Open("points.shp")
if err != nil { log.Fatal(err) } 
defer shape.Close()
    
// fields from the attribute table (DBF)
fields := shape.Fields()
    
// loop through all features in the shapefile
for shape.Next() {
    n, p := shape.Shape()
    
    // print feature
    fmt.Println(reflect.TypeOf(p).Elem(), p.BBox())
    
    // print attributes
    for k, f := range fields {
        val := shape.ReadAttribute(n, k)
        fmt.Printf("\t%v: %v\n", f, val)
    }
    fmt.Println()
}

相关文章

网友评论

      本文标题:How to parse shapefile for golan

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