-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshp.go
More file actions
38 lines (33 loc) · 719 Bytes
/
shp.go
File metadata and controls
38 lines (33 loc) · 719 Bytes
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
36
37
38
package main
import (
"fmt"
"github.com/jonas-p/go-shp"
"log"
)
func readShp(filename string) {
var shape, err = shp.Open(filename)
if err != nil {
log.Println("error reading shapefile : ", filename)
panic(err)
}
defer shape.Close()
// fields from the attribute table (DBF)
var fields = shape.Fields()
// loop through all features in the shapefile
for shape.Next() {
var n, p = shape.Shape()
var polygon, ok = p.(*shp.Polygon)
if !ok {
panic("Failed to type assert.")
}
for _, point := range polygon.Points {
fmt.Println(point)
}
// print attributes
for k, f := range fields {
var val = shape.ReadAttribute(n, k)
fmt.Printf("\t%v: %v\n", f, val)
}
fmt.Println()
}
}