public void GetPolygonOfArea(Framework.Data.AreaInfo area) { PreLoadAreaInfo(); if (area.Polygons == null) { Framework.Data.AreaInfo ainf = (from ai in _cachedAreaInfo where ai.ID == area.ID select ai).FirstOrDefault(); if (ainf != null) { try { area.Polygons = new List <Framework.Data.Polygon>(); using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename)) { int actPolyId = -1; Framework.Data.Polygon polg = null; DbDataReader dr = dbcon.ExecuteReader(string.Format("select * from poly where areainfoid={0} order by id, position", area.ID)); while (dr.Read()) { int polyId = (int)dr["id"]; if (actPolyId != polyId) { polg = new Framework.Data.Polygon(); area.Polygons.Add(polg); actPolyId = polyId; } polg.AddLocation(new Framework.Data.Location((double)dr["lat"], (double)dr["lon"])); } } } catch { } } } }
private void GetPolygonOfArea_MultiPatch(List <Framework.Data.Polygon> polygons, IndexRecord rec) { //NOTE: at this point we ignore the type (outer ring, inner ring //this is not correct and should be implemented correctly //suggestion: Add a property Exclude to Framework.Data.Polygon _shpFileStream.Position = rec.Offset + 8 + 36; //skip bounding box and shapetype int numberOfPolygons = GetInt32(_shpFileStream, true); int numberOfPoints = GetInt32(_shpFileStream, true); int[] pointIndexFirstPointPerPolygon = new int[numberOfPolygons]; int[] partsTypePerPolygon = new int[numberOfPolygons]; for (int i = 0; i < numberOfPolygons; i++) { pointIndexFirstPointPerPolygon[i] = GetInt32(_shpFileStream, true); } for (int i = 0; i < numberOfPolygons; i++) { partsTypePerPolygon[i] = GetInt32(_shpFileStream, true); } for (int i = 0; i < numberOfPolygons; i++) { Framework.Data.Polygon pg = new Framework.Data.Polygon(); int pointCount; if (i < numberOfPolygons - 1) { pointCount = pointIndexFirstPointPerPolygon[i + 1] - pointIndexFirstPointPerPolygon[i]; } else { pointCount = numberOfPoints - pointIndexFirstPointPerPolygon[i]; } for (int p = 0; p < pointCount; p++) { double x = GetDouble(_shpFileStream, true); double y = GetDouble(_shpFileStream, true); if (_coordType == CoordType.DutchGrid) { pg.AddLocation(Utils.Calculus.LocationFromRD(x, y)); } else { pg.AddLocation(new Framework.Data.Location(y, x)); } } polygons.Add(pg); } }
private void GetPolygonOfArea_Polygon(List <Framework.Data.Polygon> polygons, IndexRecord rec) { _shpFileStream.Position = rec.Offset + 8 + 36; //skip bounding box and shapetype int numberOfPolygons = GetInt32(_shpFileStream, true); int numberOfPoints = GetInt32(_shpFileStream, true); int[] pointIndexFirstPointPerPolygon = new int[numberOfPolygons]; for (int i = 0; i < numberOfPolygons; i++) { pointIndexFirstPointPerPolygon[i] = GetInt32(_shpFileStream, true); } for (int i = 0; i < numberOfPolygons; i++) { Framework.Data.Polygon pg = new Framework.Data.Polygon(); int pointCount; if (i < numberOfPolygons - 1) { pointCount = pointIndexFirstPointPerPolygon[i + 1] - pointIndexFirstPointPerPolygon[i]; } else { pointCount = numberOfPoints - pointIndexFirstPointPerPolygon[i]; } for (int p = 0; p < pointCount; p++) { double x = GetDouble(_shpFileStream, true); double y = GetDouble(_shpFileStream, true); if (_coordType == CoordType.DutchGrid) { pg.AddLocation(Utils.Calculus.LocationFromRD(x, y)); } else { pg.AddLocation(new Framework.Data.Location(y, x)); } } polygons.Add(pg); } }
private void GetPolygonOfArea_MultiPatch(List<Framework.Data.Polygon> polygons, IndexRecord rec) { //NOTE: at this point we ignore the type (outer ring, inner ring //this is not correct and should be implemented correctly //suggestion: Add a property Exclude to Framework.Data.Polygon _shpFileStream.Position = rec.Offset + 8 + 36; //skip bounding box and shapetype int numberOfPolygons = GetInt32(_shpFileStream, true); int numberOfPoints = GetInt32(_shpFileStream, true); int[] pointIndexFirstPointPerPolygon = new int[numberOfPolygons]; int[] partsTypePerPolygon = new int[numberOfPolygons]; for (int i = 0; i < numberOfPolygons; i++) { pointIndexFirstPointPerPolygon[i] = GetInt32(_shpFileStream, true); } for (int i = 0; i < numberOfPolygons; i++) { partsTypePerPolygon[i] = GetInt32(_shpFileStream, true); } for (int i = 0; i < numberOfPolygons; i++) { Framework.Data.Polygon pg = new Framework.Data.Polygon(); int pointCount; if (i < numberOfPolygons - 1) { pointCount = pointIndexFirstPointPerPolygon[i + 1] - pointIndexFirstPointPerPolygon[i]; } else { pointCount = numberOfPoints - pointIndexFirstPointPerPolygon[i]; } for (int p = 0; p < pointCount; p++) { double x = GetDouble(_shpFileStream, true); double y = GetDouble(_shpFileStream, true); if (_coordType == CoordType.DutchGrid) { pg.AddLocation(Utils.Calculus.LocationFromRD(x, y)); } else { pg.AddLocation(new Framework.Data.Location(y, x)); } } polygons.Add(pg); } }
private void GetPolygonOfArea_Polygon(List<Framework.Data.Polygon> polygons, IndexRecord rec) { _shpFileStream.Position = rec.Offset + 8 + 36; //skip bounding box and shapetype int numberOfPolygons = GetInt32(_shpFileStream, true); int numberOfPoints = GetInt32(_shpFileStream, true); int[] pointIndexFirstPointPerPolygon = new int[numberOfPolygons]; for (int i = 0; i < numberOfPolygons; i++) { pointIndexFirstPointPerPolygon[i] = GetInt32(_shpFileStream, true); } for (int i = 0; i < numberOfPolygons; i++) { Framework.Data.Polygon pg = new Framework.Data.Polygon(); int pointCount; if (i < numberOfPolygons - 1) { pointCount = pointIndexFirstPointPerPolygon[i + 1] - pointIndexFirstPointPerPolygon[i]; } else { pointCount = numberOfPoints - pointIndexFirstPointPerPolygon[i]; } for (int p = 0; p < pointCount; p++) { double x = GetDouble(_shpFileStream, true); double y = GetDouble(_shpFileStream, true); if (_coordType == CoordType.DutchGrid) { pg.AddLocation(Utils.Calculus.LocationFromRD(x,y)); } else { pg.AddLocation(new Framework.Data.Location(y, x)); } } polygons.Add(pg); } }
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 void GetPolygonOfArea(Framework.Data.AreaInfo area) { PreLoadAreaInfo(); if (area.Polygons == null) { Framework.Data.AreaInfo ainf = (from ai in _cachedAreaInfo where ai.ID == area.ID select ai).FirstOrDefault(); if (ainf!=null) { try { area.Polygons = new List<Framework.Data.Polygon>(); using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename)) { int actPolyId = -1; Framework.Data.Polygon polg = null; DbDataReader dr = dbcon.ExecuteReader(string.Format("select * from poly where areainfoid={0} order by id, position", area.ID)); while (dr.Read()) { int polyId = (int)dr["id"]; if (actPolyId != polyId) { polg = new Framework.Data.Polygon(); area.Polygons.Add(polg); actPolyId = polyId; } polg.AddLocation(new Framework.Data.Location((double)dr["lat"], (double)dr["lon"])); } } } catch { } } } }
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); }