unity C# 读取shp并生成mesh(ShpLoader使用)

声明 使用 :

Unity读取并解析Shapefile地图文件_SuperWiwi的博客-CSDN博客_unity读取shp

结构参考:

文件头_GIS基础工具篇01C#读写shp矢量文件_贱贱猪66的博客-CSDN博客

github:

 https://github.com/EIdeallab/ShpLoader

注意问题:拿到数据后先Arcgis打开

1 编码格式   更多情况是数据来源自其它地方需要 先在Arcgis中查看  我拿到的是GBK (GB2312)(找了好久才主要到这个问题-主要是解析中文问题 )

.cpg文件也可以看到编码格式 

2 坐标参照系  分清楚局部坐标和世界坐标

使用:

ShapeLoader-Loader-...

想代码动态加载查看 ShapeRendererUI.cs 文件 改改就行

   if (GUILayout.Button("Load Data"))
            {
                shapeFile = LoadFiles(shpFilePath) as ShpFile;
                dbfFile = LoadFiles(dbfFilePath) as DbfFile;
            }

中文解析:

 public class DBCharacter : IElementString
    {
        public DbfFieldDiscriptor discriptor { get; set; }
        public string Value { get; set; }

        public DBCharacter(DbfFieldDiscriptor fd)
        {
            discriptor = fd;
        }

        public string numberValue()
        {
            return Value;
        }
        public long GetLength()
        {
            return discriptor.FieldLength;
        }

        public void Load(ref BinaryReader br)
        {
            //char[] rawData = br.ReadChars(discriptor.FieldLength);
            Value = Encoding.GetEncoding("GB2312").GetString(br.ReadBytes(discriptor.FieldLength));
            //Value = new string(rawData);
            //Debug.Log(Value);
        }
    }

如果不行 

 class DbfFile : IFile
    {
        private bool disposed;
        private FileStream fs;
        private BinaryReader br;

。。。
 public DbfFile(string path)
        {
            fs = File.OpenRead(path);
            br = new BinaryReader(fs, Encoding.ASCII);
        }

将dbf设置为 AsCLL

unity 打包PC 发现无法解析 原因:

unity 打包后缺失对应编码解析包 需要

推荐目录:"Editor\Data\MonoBleedingEdge\lib\mono\unityjit"  找I18N.dll和I18N.CJK.dll   其他目录没有效果

两个dll文件放进原工程的Assets文件夹下

一定要是原工程!!!!!不是打包后的执行程序!!!!!    

直接拷贝进Asset文件夹下,等待Editor导入dll

猜你喜欢

转载自blog.csdn.net/WantFK/article/details/127604550