112 lines
4.0 KiB
C#
112 lines
4.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using GISTech.GISTerrainLoader;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class LoadShapeFileData : MonoBehaviour
|
|
{
|
|
public Text data;
|
|
|
|
private string ShapeFilePath = Application.streamingAssetsPath + "/GIS Terrains/Example_SHP/ParseSHP/Roads.shp";
|
|
|
|
private void Start()
|
|
{
|
|
StartCoroutine(LoadShapeFile(ShapeFilePath));
|
|
}
|
|
|
|
private IEnumerator LoadShapeFile(string TerrainPath)
|
|
{
|
|
yield return new WaitForSeconds(2f);
|
|
GISTerrainLoaderGeoVectorData geoFiltredData;
|
|
if (Application.platform == RuntimePlatform.WebGLPlayer || Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
|
|
{
|
|
byte[] ShpData = new byte[0];
|
|
byte[] ProjData = new byte[0];
|
|
byte[] DBFData = new byte[0];
|
|
string dbfpath = Path.ChangeExtension(ShapeFilePath, ".dbf");
|
|
string ProjPath = Path.ChangeExtension(ShapeFilePath, ".prj");
|
|
yield return StartCoroutine(GISTerrainLoaderPlatformHelper.LoadFileBytes(ShapeFilePath, delegate(byte[] data)
|
|
{
|
|
ShpData = data;
|
|
}));
|
|
yield return StartCoroutine(GISTerrainLoaderPlatformHelper.LoadFileBytes(dbfpath, delegate(byte[] data)
|
|
{
|
|
DBFData = data;
|
|
}));
|
|
yield return StartCoroutine(GISTerrainLoaderPlatformHelper.LoadFileBytes(ProjPath, delegate(byte[] data)
|
|
{
|
|
ProjData = data;
|
|
}));
|
|
geoFiltredData = new GISTerrainLoaderShapeFileLoader(GISTerrainLoaderShapeReader.LoadFile(ShpData, ShapeFilePath) as GISTerrainLoaderShpFileHeader, DBFData, ProjData).GetGeoFiltredData(ShapeFilePath);
|
|
}
|
|
else
|
|
{
|
|
geoFiltredData = new GISTerrainLoaderShapeFileLoader(GISTerrainLoaderShapeReader.LoadFile(ShapeFilePath) as GISTerrainLoaderShpFileHeader).GetGeoFiltredData();
|
|
}
|
|
Debug.Log("Polygons Counts : " + geoFiltredData.GeoPolygons.Count + " Lines Counts : " + geoFiltredData.GeoLines.Count + " Points Counts : " + geoFiltredData.GeoPoints.Count);
|
|
DebugShapeFileData(geoFiltredData);
|
|
}
|
|
|
|
private void DebugShapeFileData(GISTerrainLoaderGeoVectorData GeoData)
|
|
{
|
|
if (GeoData.GeoPoints.Count > 0)
|
|
{
|
|
foreach (GISTerrainLoaderPointGeoData geoPoint in GeoData.GeoPoints)
|
|
{
|
|
Debug.Log("GeoPoint ID: " + geoPoint.ID + " Lat-Lon: " + geoPoint.GeoPoint);
|
|
}
|
|
}
|
|
if (GeoData.GeoLines.Count > 0)
|
|
{
|
|
foreach (GISTerrainLoaderLineGeoData geoLine in GeoData.GeoLines)
|
|
{
|
|
string text = "PolyLine ID: " + geoLine.ID + " Points Count : " + geoLine.GeoPoints.Count;
|
|
Text text2 = data;
|
|
text2.text = text2.text + "\n" + text;
|
|
Debug.Log(text);
|
|
foreach (GISTerrainLoaderPointGeoData geoPoint2 in geoLine.GeoPoints)
|
|
{
|
|
text = "PolyLine ID: " + geoLine.ID + " Point N " + geoLine.GeoPoints.IndexOf(geoPoint2) + " Lat-Lon : " + geoPoint2.GeoPoint.x + " - " + geoPoint2.GeoPoint.y + " Elevation " + geoPoint2.Elevation;
|
|
Text text3 = data;
|
|
text3.text = text3.text + "\n" + text;
|
|
Debug.Log(text);
|
|
}
|
|
foreach (GISTerrainLoaderGeoDataBase item in geoLine.DataBase)
|
|
{
|
|
text = "PolyLine ID: " + geoLine.ID + " Attribute: " + item.Key + " Value: " + item.Value;
|
|
Text text4 = data;
|
|
text4.text = text4.text + "\n" + text;
|
|
Debug.Log(text);
|
|
}
|
|
}
|
|
}
|
|
if (GeoData.GeoPolygons.Count <= 0)
|
|
{
|
|
return;
|
|
}
|
|
foreach (GISTerrainLoaderPolygonGeoData geoPolygon in GeoData.GeoPolygons)
|
|
{
|
|
string text5 = "Polygon ID: " + geoPolygon.ID + " Points Count : " + geoPolygon.GeoPoints.Count;
|
|
Text text6 = data;
|
|
text6.text = text6.text + "\n" + text5;
|
|
Debug.Log(text5);
|
|
foreach (List<GISTerrainLoaderPointGeoData> geoPoint3 in geoPolygon.GeoPoints)
|
|
{
|
|
text5 = "Polygon ID: " + geoPolygon.ID + " Point N " + geoPolygon.GeoPoints.IndexOf(geoPoint3) + " Lat-Lon : " + geoPoint3;
|
|
Text text7 = data;
|
|
text7.text = text7.text + "\n" + text5;
|
|
Debug.Log(text5);
|
|
}
|
|
foreach (GISTerrainLoaderGeoDataBase item2 in geoPolygon.DataBase)
|
|
{
|
|
text5 = "Polygon ID: " + geoPolygon.ID + " Attribute: " + item2.Key + " Value: " + item2.Value;
|
|
Text text8 = data;
|
|
text8.text = text8.text + "\n" + text5;
|
|
Debug.Log(text5);
|
|
}
|
|
}
|
|
}
|
|
}
|