public static ShapeIndex FromFile(string indexFilePath) { try { using (StreamWriter sw = new StreamWriter("debugger.txt", false, System.Text.Encoding.ASCII)) { FileInfo indexFileInfo = new FileInfo(indexFilePath); if (!indexFileInfo.Exists) { return(null); } using (FileStream stream = indexFileInfo.OpenRead()) using (BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.ASCII)) { ShapeIndex si = new ShapeIndex(); int count = reader.ReadInt32(); si.ShapeRecords = new ShapeRecord[count]; for (int i = 0; i < count; i++) { si.ShapeRecords[i] = new ShapeRecord(); si.ShapeRecords[i].ID = reader.ReadString(); si.ShapeRecords[i].Name = reader.ReadString(); si.ShapeRecords[i].West = reader.ReadDouble(); si.ShapeRecords[i].South = reader.ReadDouble(); si.ShapeRecords[i].East = reader.ReadDouble(); si.ShapeRecords[i].North = reader.ReadDouble(); si.ShapeRecords[i].PolygonFile = reader.ReadString(); si.ShapeRecords[i].BoundaryFile = reader.ReadString(); int metaDataCount = reader.ReadInt32(); //records[i].MetaData = new Hashtable(); for (int j = 0; j < metaDataCount; j++) { string key = reader.ReadString(); string data = reader.ReadString(); si.ShapeRecords[i].MetaData.Add(key, data); } int scalarDataCount = reader.ReadInt32(); //records[i].ScalarData = new Hashtable(); for (int j = 0; j < scalarDataCount; j++) { string key = reader.ReadString(); double data = reader.ReadDouble(); si.ShapeRecords[i].ScalarData.Add(key, data); } } return(si); } } } catch (Exception caught) { Log.Write(caught); } return(null); }
public override void Initialize(DrawArgs drawArgs) { try { if (File.Exists(this._masterFilePath)) { using (FileStream stream = File.OpenRead(this._masterFilePath)) using (BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.ASCII)) { this._shapeIndex = new ShapeIndex(); int count = reader.ReadInt32(); this._shapeIndex.ShapeRecords = new ShapeRecord[count]; for (int i = 0; i < count; i++) { this._shapeIndex.ShapeRecords[i] = new ShapeRecord(); this._shapeIndex.ShapeRecords[i].ID = reader.ReadString(); this._shapeIndex.ShapeRecords[i].Name = reader.ReadString(); this._shapeIndex.ShapeRecords[i].West = reader.ReadDouble(); this._shapeIndex.ShapeRecords[i].South = reader.ReadDouble(); this._shapeIndex.ShapeRecords[i].East = reader.ReadDouble(); this._shapeIndex.ShapeRecords[i].North = reader.ReadDouble(); this._shapeIndex.ShapeRecords[i].PolygonFile = reader.ReadString(); this._shapeIndex.ShapeRecords[i].BoundaryFile = reader.ReadString(); int metaDataCount = reader.ReadInt32(); //records[i].MetaData = new Hashtable(); for (int j = 0; j < metaDataCount; j++) { string key = reader.ReadString(); string data = reader.ReadString(); this._shapeIndex.ShapeRecords[i].MetaData.Add(key, data); } int scalarDataCount = reader.ReadInt32(); //records[i].ScalarData = new Hashtable(); for (int j = 0; j < scalarDataCount; j++) { string key = reader.ReadString(); double data = reader.ReadDouble(); this._shapeIndex.ShapeRecords[i].ScalarData.Add(key, data); } } } } if (this._scalarKey != null) { //using(StreamWriter sw = new StreamWriter("lookout.txt", false, System.Text.Encoding.ASCII)) //sw.WriteLine("*" + this._scalarKey + "*"); //sw.WriteLine(this._scalarKey.Length); this._scalarMin = Double.MinValue; this._scalarMax = Double.MaxValue; foreach (ShapeRecord curRecord in this._shapeIndex.ShapeRecords) { foreach (string key in curRecord.ScalarData.Keys) { if (key.IndexOf(this._scalarKey) >= 0) { this._scalarKey = key; } } if (curRecord.ScalarData.Contains(this._scalarKey)) { double curScalar = (double)curRecord.ScalarData[this._scalarKey]; if (this._scalarMin == Double.MinValue || curScalar < this._scalarMin) { this._scalarMin = curScalar; } if (this._scalarMax == Double.MaxValue || curScalar > this._scalarMax) { this._scalarMax = curScalar; } } else { this._scalarKey = null; break; } } //sw.WriteLine(this._scalarMin); //sw.WriteLine(this._scalarMax); } } catch (System.Threading.ThreadAbortException) { } catch (Exception caught) { Log.Write(caught); } this.isInitialized = true; }
public override void Initialize(DrawArgs drawArgs) { try { if (File.Exists(this._masterFilePath)) { using (FileStream stream = File.OpenRead(this._masterFilePath)) using (BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.ASCII)) { this._shapeIndex = new ShapeIndex(); int count = reader.ReadInt32(); this._shapeIndex.ShapeRecords = new ShapeRecord[count]; for (int i = 0; i < count; i++) { this._shapeIndex.ShapeRecords[i] = new ShapeRecord(); this._shapeIndex.ShapeRecords[i].ID = reader.ReadString(); this._shapeIndex.ShapeRecords[i].Name = reader.ReadString(); this._shapeIndex.ShapeRecords[i].West = reader.ReadDouble(); this._shapeIndex.ShapeRecords[i].South = reader.ReadDouble(); this._shapeIndex.ShapeRecords[i].East = reader.ReadDouble(); this._shapeIndex.ShapeRecords[i].North = reader.ReadDouble(); this._shapeIndex.ShapeRecords[i].PolygonFile = reader.ReadString(); this._shapeIndex.ShapeRecords[i].BoundaryFile = reader.ReadString(); int metaDataCount = reader.ReadInt32(); //records[i].MetaData = new Hashtable(); for (int j = 0; j < metaDataCount; j++) { string key = reader.ReadString(); string data = reader.ReadString(); this._shapeIndex.ShapeRecords[i].MetaData.Add(key, data); } int scalarDataCount = reader.ReadInt32(); //records[i].ScalarData = new Hashtable(); for (int j = 0; j < scalarDataCount; j++) { string key = reader.ReadString(); double data = reader.ReadDouble(); this._shapeIndex.ShapeRecords[i].ScalarData.Add(key, data); } } } } if(this._scalarKey != null) { //using(StreamWriter sw = new StreamWriter("lookout.txt", false, System.Text.Encoding.ASCII)) //sw.WriteLine("*" + this._scalarKey + "*"); //sw.WriteLine(this._scalarKey.Length); this._scalarMin = Double.MinValue; this._scalarMax = Double.MaxValue; foreach(ShapeRecord curRecord in this._shapeIndex.ShapeRecords) { foreach(string key in curRecord.ScalarData.Keys) { if(key.IndexOf(this._scalarKey) >= 0) this._scalarKey = key; } if(curRecord.ScalarData.Contains(this._scalarKey)) { double curScalar = (double)curRecord.ScalarData[this._scalarKey]; if(this._scalarMin == Double.MinValue || curScalar < this._scalarMin) { this._scalarMin = curScalar; } if(this._scalarMax == Double.MaxValue || curScalar > this._scalarMax) { this._scalarMax = curScalar; } } else { this._scalarKey = null; break; } } //sw.WriteLine(this._scalarMin); //sw.WriteLine(this._scalarMax); } } catch(System.Threading.ThreadAbortException) { } catch(Exception caught) { Log.Write( caught ); } this.isInitialized = true; }
public static ShapeIndex FromFile(string indexFilePath) { try { using(StreamWriter sw = new StreamWriter("debugger.txt", false, System.Text.Encoding.ASCII)) { FileInfo indexFileInfo = new FileInfo(indexFilePath); if(!indexFileInfo.Exists) return null; using( FileStream stream = indexFileInfo.OpenRead() ) using (BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.ASCII)) { ShapeIndex si = new ShapeIndex(); int count = reader.ReadInt32(); si.ShapeRecords = new ShapeRecord[count]; for (int i = 0; i < count; i++) { si.ShapeRecords[i] = new ShapeRecord(); si.ShapeRecords[i].ID = reader.ReadString(); si.ShapeRecords[i].Name = reader.ReadString(); si.ShapeRecords[i].West = reader.ReadDouble(); si.ShapeRecords[i].South = reader.ReadDouble(); si.ShapeRecords[i].East = reader.ReadDouble(); si.ShapeRecords[i].North = reader.ReadDouble(); si.ShapeRecords[i].PolygonFile = reader.ReadString(); si.ShapeRecords[i].BoundaryFile = reader.ReadString(); int metaDataCount = reader.ReadInt32(); //records[i].MetaData = new Hashtable(); for (int j = 0; j < metaDataCount; j++) { string key = reader.ReadString(); string data = reader.ReadString(); si.ShapeRecords[i].MetaData.Add(key, data); } int scalarDataCount = reader.ReadInt32(); //records[i].ScalarData = new Hashtable(); for (int j = 0; j < scalarDataCount; j++) { string key = reader.ReadString(); double data = reader.ReadDouble(); si.ShapeRecords[i].ScalarData.Add(key, data); } } return si; } } } catch(Exception caught) { Log.Write( caught ); } return null; }