GDAL Android 读写shp文件 中文乱码,怎么解决

GDAL Android 读写shp文件 中文乱码,怎么解决,第1张

首先读取带有中文路径的shp文件,代码如下:

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()

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/11710284.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存