package main
import (
"fmt"
"github.com/jonas-p/go-shp"
"log"
"reflect"
)
func main() {
// open a shapefile for reading
reader, err := shp.Open("E:/example.shp")
if err != nil {
log.Fatal(err)
}
defer reader.Close()
// fields from the attribute table (DBF)
fields := reader.Fields()
//fmt.Println(reader.AttributeCount())
//for k, f := range fields {
// fmt.Println(k,f)
//}
////fmt.Println(reader.Attribute(0))
//loop through all features in the shapefile
for reader.Next() {
n, p := reader.Shape()
point := p.(*shp.Point)
x := point.X
y := point.Y
fmt.Println(x, y)
// print feature
fmt.Println(reflect.TypeOf(p).Elem(), p.BBox())
// print attributes
for k, f :=range fields {
val := reader.ReadAttribute(n, k)
fmt.Printf("\t%v: %v\n", f, val)
}
fmt.Println()
}
}
有疑问加站长微信联系(非本文作者)