You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
189 lines
6.1 KiB
189 lines
6.1 KiB
using System; |
|
using System.Collections.Generic; |
|
using System.Data; |
|
using System.IO; |
|
using ArcShapeFileDLL; |
|
using Kingo.Mobile.Shape2KOTool.XSDClass; |
|
|
|
namespace Kingo.Mobile.Shape2KOTool.KoDataBase |
|
{ |
|
// Token: 0x0200004E RID: 78 |
|
public class SHPDataSource : ISpatialDataSource |
|
{ |
|
// Token: 0x0600029B RID: 667 RVA: 0x00010287 File Offset: 0x0000E487 |
|
public SHPDataSource() |
|
{ |
|
this.GeometryType = esriGeometryType.esriGeometryPolygon; |
|
this.SpatialReference = new SpatialRefrenceStruct(); |
|
} |
|
|
|
// Token: 0x170000E1 RID: 225 |
|
// (get) Token: 0x0600029C RID: 668 RVA: 0x000102A8 File Offset: 0x0000E4A8 |
|
// (set) Token: 0x0600029D RID: 669 RVA: 0x000102BF File Offset: 0x0000E4BF |
|
public string DataSourcePath { get; set; } |
|
|
|
// Token: 0x170000E2 RID: 226 |
|
// (get) Token: 0x0600029E RID: 670 RVA: 0x000102C8 File Offset: 0x0000E4C8 |
|
// (set) Token: 0x0600029F RID: 671 RVA: 0x000102DF File Offset: 0x0000E4DF |
|
public DataTable DataTable { get; private set; } |
|
|
|
// Token: 0x170000E3 RID: 227 |
|
// (get) Token: 0x060002A0 RID: 672 RVA: 0x000102E8 File Offset: 0x0000E4E8 |
|
// (set) Token: 0x060002A1 RID: 673 RVA: 0x000102FF File Offset: 0x0000E4FF |
|
public List<ShapeFieldInfo> Fields { get; private set; } |
|
|
|
// Token: 0x170000E4 RID: 228 |
|
// (get) Token: 0x060002A2 RID: 674 RVA: 0x00010308 File Offset: 0x0000E508 |
|
// (set) Token: 0x060002A3 RID: 675 RVA: 0x0001031F File Offset: 0x0000E51F |
|
public EnvelopeN Extent { get; private set; } |
|
|
|
// Token: 0x170000E5 RID: 229 |
|
// (get) Token: 0x060002A4 RID: 676 RVA: 0x00010328 File Offset: 0x0000E528 |
|
// (set) Token: 0x060002A5 RID: 677 RVA: 0x0001033F File Offset: 0x0000E53F |
|
public esriGeometryType GeometryType { get; private set; } |
|
|
|
// Token: 0x170000E6 RID: 230 |
|
// (get) Token: 0x060002A6 RID: 678 RVA: 0x00010348 File Offset: 0x0000E548 |
|
// (set) Token: 0x060002A7 RID: 679 RVA: 0x0001035F File Offset: 0x0000E55F |
|
public SpatialRefrenceStruct SpatialReference { get; private set; } |
|
|
|
// Token: 0x170000E7 RID: 231 |
|
// (get) Token: 0x060002A8 RID: 680 RVA: 0x00010368 File Offset: 0x0000E568 |
|
// (set) Token: 0x060002A9 RID: 681 RVA: 0x0001037F File Offset: 0x0000E57F |
|
public int RecordCount { get; private set; } |
|
|
|
// Token: 0x060002AA RID: 682 RVA: 0x000103BC File Offset: 0x0000E5BC |
|
public void Open() |
|
{ |
|
if (string.IsNullOrEmpty(this.DataSourcePath)) |
|
{ |
|
throw new ArgumentNullException(); |
|
} |
|
if (!File.Exists(this.DataSourcePath)) |
|
{ |
|
throw new FileNotFoundException("SHP文件不存在"); |
|
} |
|
string text = this.DataSourcePath.Replace(".shp", ".dbf"); |
|
if (!File.Exists(text)) |
|
{ |
|
throw new FileNotFoundException("DBF文件不存在"); |
|
} |
|
this.shapeFile = new ShapeFiles(); |
|
this.shapeFile.OpenShape(this.DataSourcePath, 0, false); |
|
this.Extent = new EnvelopeN |
|
{ |
|
XMax = this.shapeFile.xMax, |
|
XMin = this.shapeFile.xMin, |
|
YMax = this.shapeFile.yMax, |
|
YMin = this.shapeFile.yMin |
|
}; |
|
this.RecordCount = this.shapeFile.RecordCount; |
|
string path = this.DataSourcePath.Replace(".shp", ".prj"); |
|
if (File.Exists(path)) |
|
{ |
|
string wkt = File.ReadAllText(path); |
|
SpatialRefrenceStruct spatialRefrenceStruct = SpatialRefrenceStruct.GetAllData().Find((SpatialRefrenceStruct p) => p.WKT.ToLower() == wkt.ToLower()); |
|
if (spatialRefrenceStruct != null) |
|
{ |
|
this.SpatialReference = spatialRefrenceStruct; |
|
} |
|
} |
|
if (this.shapeFile.ShapeType != ShapeFiles.eShapeType.shpPolygon || this.shapeFile.ShapeType != ShapeFiles.eShapeType.shpPolygonM || this.shapeFile.ShapeType != ShapeFiles.eShapeType.shpPolygonZ) |
|
{ |
|
this.GeometryType = esriGeometryType.esriGeometryPolygon; |
|
this.Fields = new List<ShapeFieldInfo>(); |
|
foreach (object obj in this.shapeFile.ShapeFields) |
|
{ |
|
ShapeField shapeField = (ShapeField)obj; |
|
if (shapeField.FieldName.ToLower() == "objectid") |
|
{ |
|
shapeField.FieldName = "OBJECTID_1"; |
|
} |
|
this.Fields.Add(new ShapeFieldInfo(shapeField)); |
|
} |
|
this.dbfReader = new DBFReader(); |
|
this.dbfReader.Open(text); |
|
this.DataTable = this.dbfReader.DataTable.Clone(); |
|
this.DataTable.Columns.Add("OBJECTID", typeof(int)); |
|
this.DataTable.Columns.Add("SHAPE", typeof(string)); |
|
this.EOF = false; |
|
return; |
|
} |
|
throw new Exception("目前只支持多边形类型的数据!"); |
|
} |
|
|
|
// Token: 0x060002AB RID: 683 RVA: 0x00010694 File Offset: 0x0000E894 |
|
public void Close() |
|
{ |
|
if (this.shapeFile != null) |
|
{ |
|
this.shapeFile.CloseShape(); |
|
this.shapeFile = null; |
|
} |
|
if (this.dbfReader != null) |
|
{ |
|
this.dbfReader.Close(); |
|
this.dbfReader = null; |
|
} |
|
} |
|
|
|
// Token: 0x060002AC RID: 684 RVA: 0x000106E8 File Offset: 0x0000E8E8 |
|
public Dictionary<string, int> Distinct(string fieldName) |
|
{ |
|
return this.dbfReader.Distinct(fieldName); |
|
} |
|
|
|
// Token: 0x060002AD RID: 685 RVA: 0x00010708 File Offset: 0x0000E908 |
|
public DataTable GetAllRecord() |
|
{ |
|
this.Reset(); |
|
while (!this.EOF) |
|
{ |
|
DataRow nextRecord = this.GetNextRecord(); |
|
this.DataTable.Rows.Add(nextRecord); |
|
} |
|
this.Reset(); |
|
return this.DataTable; |
|
} |
|
|
|
// Token: 0x060002AE RID: 686 RVA: 0x00010758 File Offset: 0x0000E958 |
|
public DataRow GetNextRecord() |
|
{ |
|
DataRow dataRow = this.DataTable.NewRow(); |
|
DataRow nextRecord = this.dbfReader.GetNextRecord(); |
|
List<object> list = new List<object>(); |
|
list.AddRange(nextRecord.ItemArray); |
|
list.Add(this.shapeFile.CurrentRecord); |
|
list.Add(CommonMethod.GetShapeMultiPolygonString(this.shapeFile)); |
|
dataRow.ItemArray = list.ToArray(); |
|
if (this.shapeFile.EOF || this.dbfReader.EOF) |
|
{ |
|
this.EOF = true; |
|
} |
|
else |
|
{ |
|
this.shapeFile.MoveNext(); |
|
} |
|
return dataRow; |
|
} |
|
|
|
// Token: 0x170000E8 RID: 232 |
|
// (get) Token: 0x060002AF RID: 687 RVA: 0x0001080C File Offset: 0x0000EA0C |
|
// (set) Token: 0x060002B0 RID: 688 RVA: 0x00010823 File Offset: 0x0000EA23 |
|
public bool EOF { get; private set; } |
|
|
|
// Token: 0x060002B1 RID: 689 RVA: 0x0001082C File Offset: 0x0000EA2C |
|
public void Reset() |
|
{ |
|
this.shapeFile.MoveFirst(); |
|
this.dbfReader.Reset(); |
|
this.EOF = false; |
|
} |
|
|
|
// Token: 0x040001C1 RID: 449 |
|
private ShapeFiles shapeFile; |
|
|
|
// Token: 0x040001C2 RID: 450 |
|
private DBFReader dbfReader; |
|
} |
|
}
|
|
|