声明 使用 :
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
数据处理:
1数据 ploygon_zm 转ploygon
右键选择 打开属性表 
设置:


输出坐标选择:
拖入新的shp文件 :
2 设置坐标系投影 2000转W84
右键选择 属性 
设置:


输出坐标选择:
ArcGIS更改字段名称、类型、顺序_哔哩哔哩_bilibili
Arcgis基础编辑--属性表的基础操作3 - 知乎
博客介绍了Unity使用C#读取并解析Shapefile地图文件的方法。包括参考结构、GitHub资源,强调拿到数据后用Arcgis打开查看编码格式和坐标参照系。还提及中文解析问题及解决办法,如打包PC无法解析时添加对应dll文件。此外,介绍了数据处理和设置坐标系投影等操作。

4514

被折叠的 条评论
为什么被折叠?



