private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBox1.SelectedIndex) { case 0: _level = Framework.Data.AreaType.Country; label10.Text = string.Format("({0})", (from Framework.Data.Geocache g in _core.Geocaches where (string.IsNullOrEmpty(g.Country) || !checkBox1.Checked) select g).Count()); _gcList = (from Framework.Data.Geocache g in _core.Geocaches where (string.IsNullOrEmpty(g.Country) || !checkBox1.Checked) && (g.Selected || !checkBox2.Checked) select g).ToList(); break; case 1: _level = Framework.Data.AreaType.State; label10.Text = string.Format("({0})", (from Framework.Data.Geocache g in _core.Geocaches where (string.IsNullOrEmpty(g.State) || !checkBox1.Checked) select g).Count()); _gcList = (from Framework.Data.Geocache g in _core.Geocaches where (string.IsNullOrEmpty(g.State) || !checkBox1.Checked) && (g.Selected || !checkBox2.Checked) select g).ToList(); break; case 2: _level = Framework.Data.AreaType.Municipality; label10.Text = string.Format("({0})", (from Framework.Data.Geocache g in _core.Geocaches where (string.IsNullOrEmpty(g.Municipality) || !checkBox1.Checked) select g).Count()); _gcList = (from Framework.Data.Geocache g in _core.Geocaches where (string.IsNullOrEmpty(g.Municipality) || !checkBox1.Checked) && (g.Selected || !checkBox2.Checked) select g).ToList(); break; case 3: _level = Framework.Data.AreaType.City; label10.Text = string.Format("({0})", (from Framework.Data.Geocache g in _core.Geocaches where (string.IsNullOrEmpty(g.City) || !checkBox1.Checked) select g).Count()); _gcList = (from Framework.Data.Geocache g in _core.Geocaches where (string.IsNullOrEmpty(g.City) || !checkBox1.Checked) && (g.Selected || !checkBox2.Checked) select g).ToList(); break; default: _level = Framework.Data.AreaType.Other; break; } label11.Text = string.Format("#{0}", _gcList.Count); }
internal bool deleteArea(Framework.Data.AreaType level, string areaName) { PreLoadAreaInfo(); bool result = true; try { List <Framework.Data.AreaInfo> ail = GetAreasByName(areaName, level); if (ail.Count > 0) { foreach (Framework.Data.AreaInfo ai in ail) { using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename)) { dbcon.ExecuteNonQuery(string.Format("delete from poly where areainfoid={0}", ai.ID)); dbcon.ExecuteNonQuery(string.Format("delete from areainfo where id={0}", ai.ID)); _cachedAreaInfo.Remove(ai); } } } } catch { result = false; } return(result); }
public List <Framework.Data.AreaInfo> GetAreasByLevel(Framework.Data.AreaType level) { List <Framework.Data.AreaInfo> result = new List <Framework.Data.AreaInfo>(); foreach (var sf in _shapeFiles) { result.AddRange((from a in sf.AreaInfos where a.Level == level select a).ToList()); } return(result); }
public List <Framework.Data.AreaInfo> GetAreasByLevel(Framework.Data.AreaType level) { List <Framework.Data.AreaInfo> result = new List <Framework.Data.AreaInfo>(); foreach (Framework.Interfaces.IGeometry g in _geometryPlugins) { result.AddRange(g.GetAreasByLevel(level)); } return(result); }
private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (listView1.SelectedIndices.Count > 0) { button3.Enabled = true; ListViewItem lvi = listView1.Items[listView1.SelectedIndices[0]]; textBox1.Text = lvi.SubItems[0].Text; comboBox1.SelectedIndex = comboBox1.Items.IndexOf(lvi.SubItems[1].Text); Framework.Data.AreaType at = (Framework.Data.AreaType)Enum.Parse(typeof(Framework.Data.AreaType), lvi.SubItems[3].Text); switch (at) { case Framework.Data.AreaType.Country: comboBox3.SelectedIndex = 0; break; case Framework.Data.AreaType.State: comboBox3.SelectedIndex = 1; break; case Framework.Data.AreaType.Municipality: comboBox3.SelectedIndex = 2; break; case Framework.Data.AreaType.City: comboBox3.SelectedIndex = 3; break; case Framework.Data.AreaType.Other: comboBox3.SelectedIndex = 4; break; } ShapeFile.CoordType ct = (ShapeFile.CoordType)Enum.Parse(typeof(ShapeFile.CoordType), lvi.SubItems[2].Text); switch (ct) { case ShapeFile.CoordType.WGS84: comboBox2.SelectedIndex = 0; break; case ShapeFile.CoordType.DutchGrid: comboBox2.SelectedIndex = 1; break; } textBox2.Text = lvi.SubItems.Count > 4 ? lvi.SubItems[4].Text : ""; textBox3.Text = lvi.SubItems.Count > 5 ? lvi.SubItems[5].Text : ""; } else { button3.Enabled = false; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; } }
internal bool processGpxFile(Framework.Data.AreaType level, string f, Framework.Data.AreaInfo parent) { PreLoadAreaInfo(); bool result = false; try { } catch { } return(result); }
private void buttonAdd_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { _selectedAreaType = (Framework.Data.AreaType)Enum.Parse(typeof(Framework.Data.AreaType), comboBoxLevel.SelectedItem.ToString()); _selectedParent = comboBoxParent.SelectedItem as Framework.Data.AreaInfo; _filenames = openFileDialog1.FileNames; _actionReady = new ManualResetEvent(false); _actionReady.Reset(); Thread thrd = new Thread(new ThreadStart(this.processMethod)); thrd.Start(); while (!_actionReady.WaitOne(100)) { System.Windows.Forms.Application.DoEvents(); } thrd.Join(); _actionReady.Close(); comboBoxLevel_SelectedIndexChanged(this, EventArgs.Empty); } }
private void comboBoxLevel_SelectedIndexChanged(object sender, EventArgs e) { comboBoxAreaName.Items.Clear(); List <Framework.Data.AreaInfo> ail = _ownerPlugin.GetAreasByLevel((Framework.Data.AreaType)Enum.Parse(typeof(Framework.Data.AreaType), comboBoxLevel.SelectedItem.ToString())); comboBoxAreaName.Items.AddRange((from a in ail select a).ToArray()); comboBoxParent.Items.Clear(); Framework.Data.AreaType selType = (Framework.Data.AreaType)Enum.Parse(typeof(Framework.Data.AreaType), comboBoxLevel.SelectedItem.ToString()); List <Framework.Data.AreaInfo> ail2 = null; switch (selType) { case Framework.Data.AreaType.City: ail2 = _ownerPlugin.GetAreasByLevel(Framework.Data.AreaType.Municipality); break; case Framework.Data.AreaType.Municipality: ail2 = _ownerPlugin.GetAreasByLevel(Framework.Data.AreaType.State); break; case Framework.Data.AreaType.State: ail2 = _ownerPlugin.GetAreasByLevel(Framework.Data.AreaType.Country); break; case Framework.Data.AreaType.Other: ail2 = _ownerPlugin.GetAreasByLevel(Framework.Data.AreaType.Country); ail2.AddRange(_ownerPlugin.GetAreasByLevel(Framework.Data.AreaType.State)); ail2.AddRange(_ownerPlugin.GetAreasByLevel(Framework.Data.AreaType.Municipality)); ail2.AddRange(_ownerPlugin.GetAreasByLevel(Framework.Data.AreaType.Other)); break; } comboBoxParent.Items.Add("-- none --"); if (ail2 != null) { comboBoxParent.Items.AddRange((from a in ail2 select a).ToArray()); } }
private async void button1_Click(object sender, EventArgs e) { _inEnvelope = checkBox1.Checked; if (radioButtonNewSearch.Checked) { _gcList = (from Framework.Data.Geocache g in _core.Geocaches select g).ToList(); } else if (radioButtonAddToCurrent.Checked) { _gcList = (from Framework.Data.Geocache g in _core.Geocaches where !g.Selected select g).ToList(); } else //within current { _gcList = (from Framework.Data.Geocache g in _core.Geocaches where g.Selected select g).ToList(); } using (Utils.FrameworkDataUpdater updater = new Utils.FrameworkDataUpdater(_core)) { if (radioButtonNewSearch.Checked || radioButtonWithinSelection.Checked) { foreach (Framework.Data.Geocache g in _core.Geocaches) { g.Selected = false; } } if (comboBox2.SelectedIndex < 1) { _areaName = ""; } else { _areaName = comboBox2.Text; } switch (comboBox1.SelectedIndex) { case 0: _level = Framework.Data.AreaType.Country; break; case 1: _level = Framework.Data.AreaType.State; break; case 2: _level = Framework.Data.AreaType.Municipality; break; case 3: _level = Framework.Data.AreaType.City; break; default: _level = Framework.Data.AreaType.Other; break; } _prefix = textBox1.Text; await Task.Run(() => { this.performSelectionMethod(); }); Close(); } }
internal bool processTextFile(Framework.Data.AreaType level, string f, Framework.Data.AreaInfo parent) { PreLoadAreaInfo(); bool result = false; try { //filename = AreaName string areaName = System.IO.Path.GetFileNameWithoutExtension(f); char[] num = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; int pos = 0; while (pos < areaName.Length && !num.Contains(areaName[pos])) { pos++; } areaName = areaName.Substring(0, pos); string[] lines = System.IO.File.ReadAllLines(f); pos = 0; if (lines[0].StartsWith("# GsakName=")) { areaName = lines[0].Substring(lines[0].IndexOf('=') + 1).Trim(); pos++; } string slat = ""; string slon = ""; double lat; double lon; bool newPoly; Framework.Data.AreaInfo ai; List <Framework.Data.AreaInfo> ailist = GetAreasByName(areaName, level); bool firstPoint = true; if (ailist.Count > 0) { ai = ailist[0]; firstPoint = false; newPoly = false; } else { newPoly = true; ai = new Framework.Data.AreaInfo(); ai.ID = _maxAreaInfoId + 1; _maxAreaInfoId++; ai.Name = areaName; ai.Level = level; ai.Polygons = new List <Framework.Data.Polygon>(); } Framework.Data.Polygon poly = new Framework.Data.Polygon(); _maxPolyId++; using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename)) { dbcon.BeginTran(); while (pos < lines.Length) { string s = lines[pos].Trim(); if (!s.StartsWith("#")) { string[] parts = s.Split(new char[] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { lat = Utils.Conversion.StringToDouble(parts[0]); lon = Utils.Conversion.StringToDouble(parts[1]); if (firstPoint) { ai.MinLat = lat; ai.MaxLat = lat; ai.MinLon = lon; ai.MaxLon = lon; firstPoint = false; } else { if (lat < ai.MinLat) { ai.MinLat = lat; } if (lat > ai.MaxLat) { ai.MaxLat = lat; } if (lon < ai.MinLon) { ai.MinLon = lon; } if (lon > ai.MaxLon) { ai.MaxLon = lon; } } poly.AddLocation(new Framework.Data.Location(lat, lon)); dbcon.ExecuteNonQuery(string.Format("insert into poly (id, areainfoid, position, lat, lon) values ({0}, {1}, {2}, {3}, {4})", _maxPolyId, ai.ID, poly.Count, lat.ToString().Replace(',', '.'), lon.ToString().Replace(',', '.'))); if (poly.Count == 1) { slat = parts[0]; slon = parts[1]; ai.Polygons.Add(poly); } else if (slat == parts[0] && slon == parts[1]) { poly = new Framework.Data.Polygon(); _maxPolyId++; } } } pos++; } if (newPoly) { _cachedAreaInfo.Add(ai); dbcon.ExecuteNonQuery(string.Format("insert into areainfo (id, parentid, level, name, minlat, minlon, maxlat, maxlon) values ({0}, {1}, {2}, '{3}', {4}, {5}, {6}, {7})", ai.ID, parent == null ? "NULL" : parent.ID, (short)ai.Level, ai.Name.Replace("'", "''"), ai.MinLat.ToString().Replace(',', '.'), ai.MinLon.ToString().Replace(',', '.'), ai.MaxLat.ToString().Replace(',', '.'), ai.MaxLon.ToString().Replace(',', '.'))); } else { dbcon.ExecuteNonQuery(string.Format("update areainfo set parentid={0}, minlat={1}, minlon={2}, maxlat={3}, maxlon={4} where id={5}", parent == null ? "NULL" : parent.ID, ai.MinLat.ToString().Replace(',', '.'), ai.MinLon.ToString().Replace(',', '.'), ai.MaxLat.ToString().Replace(',', '.'), ai.MaxLon.ToString().Replace(',', '.'), ai.ID)); } dbcon.CommitTran(); result = true; } } 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 List <Framework.Data.AreaInfo> GetAreasByLevel(Framework.Data.AreaType level) { return(_shapeFilesManager.GetAreasByLevel(level)); }
private void button1_Click(object sender, EventArgs e) { _inEnvelope = checkBox1.Checked; if (radioButtonNewSearch.Checked) { _gcList = (from Framework.Data.Geocache g in _core.Geocaches select g).ToList(); } else if (radioButtonAddToCurrent.Checked) { _gcList = (from Framework.Data.Geocache g in _core.Geocaches where !g.Selected select g).ToList(); } else //within current { _gcList = (from Framework.Data.Geocache g in _core.Geocaches where g.Selected select g).ToList(); } using (Utils.FrameworkDataUpdater updater = new Utils.FrameworkDataUpdater(_core)) { if (radioButtonNewSearch.Checked || radioButtonWithinSelection.Checked) { foreach (Framework.Data.Geocache g in _core.Geocaches) { g.Selected = false; } } if (comboBox2.SelectedIndex < 1) { _areaName = ""; } else { _areaName = comboBox2.Text; } switch (comboBox1.SelectedIndex) { case 0: _level = Framework.Data.AreaType.Country; break; case 1: _level = Framework.Data.AreaType.State; break; case 2: _level = Framework.Data.AreaType.Municipality; break; case 3: _level = Framework.Data.AreaType.City; break; default: _level = Framework.Data.AreaType.Other; break; } _prefix = textBox1.Text; _actionReady = new ManualResetEvent(false); _actionReady.Reset(); Thread thrd = new Thread(new ThreadStart(this.performSelectionMethod)); thrd.Start(); while (!_actionReady.WaitOne(100)) { System.Windows.Forms.Application.DoEvents(); } thrd.Join(); _actionReady.Close(); Close(); } }
public List <Framework.Data.AreaInfo> GetAreasByName(string name, Framework.Data.AreaType level) { PreLoadAreaInfo(); return((from ai in _cachedAreaInfo where ai.Name.ToLower() == name.ToLower() && ai.Level == level select ai).ToList()); }
public List <Framework.Data.AreaInfo> GetAreasByLevel(Framework.Data.AreaType level) { PreLoadAreaInfo(); return((from ai in _cachedAreaInfo where ai.Level == level select ai).ToList()); }
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 List <Framework.Data.AreaInfo> GetAreasByName(string name, Framework.Data.AreaType level) { return(_shapeFilesManager.GetAreasByName(name, level)); }