string strShpFullName = @"G:\学习资料\ArcGIS空间数据\ATShp\Boundary\China_Boundary.shp"
//注册Ogr
Ogr.RegisterAll()
OSGeo.GDAL.Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "NO")
//读取字段属性值时设置,否则有中文乱码
OSGeo.GDAL.Gdal.SetConfigOption("SHAPE_ENCODING", "NO")
DataSource ds = Ogr.Open(strShpFullName, 0)
if (ds == null)
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()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)