public string[] GetFields() { string[] result = null; try { using (DotNetDBF.DBFReader dbf = new DotNetDBF.DBFReader(string.Format("{0}dbf", _shpFilename.Substring(0, _shpFilename.Length - 3)), _dbfEncoding)) { var fields = dbf.Fields; result = (from s in fields select s.Name).ToArray(); } } catch { } return(result); }
public string[] GetFields() { string[] result = null; try { using (DotNetDBF.DBFReader dbf = new DotNetDBF.DBFReader(string.Format("{0}dbf", _shpFilename.Substring(0, _shpFilename.Length - 3)), _dbfEncoding)) { var fields = dbf.Fields; result = (from s in fields select s.Name).ToArray(); } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } return(result); }
public bool Initialize(string dbfNameFieldName, CoordType coordType, Framework.Data.AreaType areaType, string namePrefix, string dbfEncoding) { bool result = false; try { _coordType = coordType; _shpFileStream = File.OpenRead(_shpFilename); _areaType = areaType; _dbfEncoding = dbfEncoding; int FileCode = GetInt32(_shpFileStream, false); if (FileCode == 9994) { _shpFileStream.Position = 24; _shpFileSize = GetInt32(_shpFileStream, false); _shpVersion = GetInt32(_shpFileStream, true); _shpShapeType = (ShapeType)GetInt32(_shpFileStream, true); _shpXMin = GetDouble(_shpFileStream, true); _shpYMin = GetDouble(_shpFileStream, true); _shpXMax = GetDouble(_shpFileStream, true); _shpYMax = GetDouble(_shpFileStream, true); using (FileStream fs = File.OpenRead(string.Format("{0}shx", _shpFilename.Substring(0, _shpFilename.Length - 3)))) { FileCode = GetInt32(fs, false); if (FileCode == 9994) { fs.Position = 24; int shxFileSize = GetInt32(fs, false); int shxVersion = GetInt32(fs, true); int intRecordCount = ((shxFileSize * 2) - 100) / 8; fs.Position = 100; _indexRecords = new IndexRecord[intRecordCount]; for (int i = 0; i < intRecordCount; i++) { _indexRecords[i] = new IndexRecord() { Offset = GetInt32(fs, false) * 2, ContentLength = GetInt32(fs, false) * 2 }; } for (int i = 0; i < intRecordCount; i++) { IndexRecord ir = _indexRecords[i]; _shpFileStream.Position = ir.Offset + 8; ir.ShapeType = (ShapeType)GetInt32(_shpFileStream, true); if (ir.ShapeType == ShapeType.NullShape) { ir.ShapeType = _shpShapeType; } switch (ir.ShapeType) { case ShapeType.Polygon: case ShapeType.PolygonZ: case ShapeType.PolygonM: case ShapeType.MultiPatch: ir.XMin = GetDouble(_shpFileStream, true); ir.YMin = GetDouble(_shpFileStream, true); ir.XMax = GetDouble(_shpFileStream, true); ir.YMax = GetDouble(_shpFileStream, true); ir.Ignore = false; break; default: ir.Ignore = true; break; } } using (DotNetDBF.DBFReader dbf = new DotNetDBF.DBFReader(string.Format("{0}dbf", _shpFilename.Substring(0, _shpFilename.Length - 3)), _dbfEncoding)) { var fields = dbf.Fields; dbf.SetSelectFields(new string[] { dbfNameFieldName }); var rec = dbf.NextRecord(); int index = 0; while (rec != null) { if (!_indexRecords[index].Ignore) { _indexRecords[index].Name = string.Format("{0}{1}", namePrefix, rec[0]); } else { _indexRecords[index].Name = null; } index++; if (index < _indexRecords.Length) { rec = dbf.NextRecord(); } else { rec = null; } } } // all ok, check if we need to convert the coords to WGS84, the internal coord system if (_coordType == CoordType.DutchGrid) { Utils.Calculus.LatLonFromRD(_shpXMin, _shpYMin, out _shpYMin, out _shpXMin); Utils.Calculus.LatLonFromRD(_shpXMax, _shpYMax, out _shpYMax, out _shpXMax); double lat; double lon; for (int i = 0; i < intRecordCount; i++) { IndexRecord ir = _indexRecords[i]; Utils.Calculus.LatLonFromRD(ir.XMin, ir.YMin, out lat, out lon); ir.YMin = lat; ir.XMin = lon; Utils.Calculus.LatLonFromRD(ir.XMax, ir.YMax, out lat, out lon); ir.YMax = lat; ir.XMax = lon; } } var areaNames = (from a in _indexRecords select a.Name).Distinct(); foreach (var name in areaNames) { var records = from r in _indexRecords where r.Name == name select r; Framework.Data.AreaInfo ai = new Framework.Data.AreaInfo(); ai.ID = ai; ai.Level = areaType; ai.MaxLat = records.Max(x => x.YMax); ai.MaxLon = records.Max(x => x.XMax); ai.MinLat = records.Min(x => x.YMin); ai.MinLon = records.Min(x => x.XMin); ai.Name = name; ai.ParentID = null; //not supported _areaInfos.Add(ai); } result = true; } } } } catch { } return(result); }
public string[] GetFields() { string[] result = null; try { using (DotNetDBF.DBFReader dbf = new DotNetDBF.DBFReader(string.Format("{0}dbf", _shpFilename.Substring(0, _shpFilename.Length - 3)))) { var fields = dbf.Fields; result = (from s in fields select s.Name).ToArray(); } } catch { } return result; }
public bool Initialize(string dbfNameFieldName, CoordType coordType, Framework.Data.AreaType areaType, string namePrefix) { bool result = false; try { _coordType = coordType; _shpFileStream = File.OpenRead(_shpFilename); _areaType = areaType; int FileCode = GetInt32(_shpFileStream, false); if (FileCode==9994) { _shpFileStream.Position = 24; _shpFileSize = GetInt32(_shpFileStream, false); _shpVersion = GetInt32(_shpFileStream, true); _shpShapeType = (ShapeType)GetInt32(_shpFileStream, true); _shpXMin = GetDouble(_shpFileStream, true); _shpYMin = GetDouble(_shpFileStream, true); _shpXMax = GetDouble(_shpFileStream, true); _shpYMax = GetDouble(_shpFileStream, true); using (FileStream fs = File.OpenRead(string.Format("{0}shx", _shpFilename.Substring(0, _shpFilename.Length - 3)))) { FileCode = GetInt32(fs, false); if (FileCode == 9994) { fs.Position = 24; int shxFileSize = GetInt32(fs, false); int shxVersion = GetInt32(fs, true); int intRecordCount = ((shxFileSize * 2) - 100) / 8; fs.Position = 100; _indexRecords = new IndexRecord[intRecordCount]; for (int i = 0; i < intRecordCount; i++) { _indexRecords[i] = new IndexRecord() { Offset = GetInt32(fs, false) * 2, ContentLength = GetInt32(fs, false) * 2 }; } for (int i = 0; i < intRecordCount; i++) { IndexRecord ir = _indexRecords[i]; _shpFileStream.Position = ir.Offset + 8; ir.ShapeType = (ShapeType)GetInt32(_shpFileStream, true); if (ir.ShapeType == ShapeType.NullShape) { ir.ShapeType = _shpShapeType; } switch (ir.ShapeType) { case ShapeType.Polygon: case ShapeType.PolygonZ: case ShapeType.PolygonM: case ShapeType.MultiPatch: ir.XMin = GetDouble(_shpFileStream, true); ir.YMin = GetDouble(_shpFileStream, true); ir.XMax = GetDouble(_shpFileStream, true); ir.YMax = GetDouble(_shpFileStream, true); ir.Ignore = false; break; default: ir.Ignore = true; break; } } using (DotNetDBF.DBFReader dbf = new DotNetDBF.DBFReader(string.Format("{0}dbf", _shpFilename.Substring(0, _shpFilename.Length - 3)))) { var fields = dbf.Fields; dbf.SetSelectFields(new string[]{dbfNameFieldName}); var rec = dbf.NextRecord(); int index = 0; while (rec != null) { if (!_indexRecords[index].Ignore) { _indexRecords[index].Name = string.Format("{0}{1}",namePrefix,rec[0]); if (_indexRecords[index].Name == "Fryslân" || _indexRecords[index].Name == "Frysl�n") { _indexRecords[index].Name = "Friesland"; } else { _indexRecords[index].Name = _indexRecords[index].Name.Replace("�", "â"); } } else { _indexRecords[index].Name = null; } index++; if (index < _indexRecords.Length) { rec = dbf.NextRecord(); } else { rec = null; } } } // all ok, check if we need to convert the coords to WGS84, the internal coord system if (_coordType == CoordType.DutchGrid) { Utils.Calculus.LatLonFromRD(_shpXMin, _shpYMin, out _shpYMin, out _shpXMin); Utils.Calculus.LatLonFromRD(_shpXMax, _shpYMax, out _shpYMax, out _shpXMax); double lat; double lon; for (int i = 0; i < intRecordCount; i++) { IndexRecord ir = _indexRecords[i]; Utils.Calculus.LatLonFromRD(ir.XMin, ir.YMin, out lat, out lon); ir.YMin = lat; ir.XMin = lon; Utils.Calculus.LatLonFromRD(ir.XMax, ir.YMax, out lat, out lon); ir.YMax = lat; ir.XMax = lon; } } var areaNames = (from a in _indexRecords select a.Name).Distinct(); foreach (var name in areaNames) { var records = from r in _indexRecords where r.Name == name select r; Framework.Data.AreaInfo ai = new Framework.Data.AreaInfo(); ai.ID = ai; ai.Level = areaType; ai.MaxLat = records.Max(x => x.YMax); ai.MaxLon = records.Max(x => x.XMax); ai.MinLat = records.Min(x => x.YMin); ai.MinLon = records.Min(x => x.XMin); ai.Name = name; ai.ParentID = null; //not supported _areaInfos.Add(ai); } result = true; } } } } catch { } return result; }
public string[] GetFields() { string[] result = null; try { using (DotNetDBF.DBFReader dbf = new DotNetDBF.DBFReader(string.Format("{0}dbf", _shpFilename.Substring(0, _shpFilename.Length - 3)), _dbfEncoding)) { var fields = dbf.Fields; result = (from s in fields select s.Name).ToArray(); } } catch(Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } return result; }