public bool ImportTt(List<string> polys, bool useNmea) { if (!_MetaOpen) return false; _Points = new List<TtPoint>(); _Polygons = new Dictionary<string, TtPolygon>(); _IdToCN = new Dictionary<string, string>(); pidToCN = new Dictionary<int, string>(); _PolyIndexes = new Dictionary<string, int>(); Dictionary<string, TtMetaData> metaData = new Dictionary<string, TtMetaData>(); Dictionary<string, string> metaLinkToId = new Dictionary<string, string>(); Dictionary<string, int> qndLinks = new Dictionary<string, int>(); List<int> pointWNMEA = new List<int>(); Dictionary<int, List<TwoTrails.GpsAccess.NmeaBurst>> nmeas = new Dictionary<int, List<TwoTrails.GpsAccess.NmeaBurst>>(); int viewId = metaKitViews[polydata]; int rowCount; int polyCount = (int)dal.GetPolyCount(); polyCount++; string tmpStr, tmpStr2; int tmpInt; double tmpDouble; try { #region Polygons rowCount = metaKit.GetRowCount(viewId); for (int i = 0; i < rowCount; i++) { _Poly = new TtPolygon(); tmpStr = metaKit.GetString(viewId, i, 0); if (!tmpStr.IsEmpty()) { tmpStr2 = null; _Poly.Name = tmpStr; } else { tmpStr2 = tmpStr; _Poly.Name = String.Format("Poly {0}", polyCount); } _Poly.PointStartIndex = 1000 * polyCount + 10; if (!polys.Contains(tmpStr)) continue; polyCount++; tmpStr = metaKit.GetString(viewId, i, 1); if (!tmpStr.IsEmpty()) _Poly.Description = tmpStr; tmpStr = metaKit.GetString(viewId, i, 10); if (!tmpStr.IsEmpty()) { if(_Poly.Description.IsEmpty()) _Poly.Description = tmpStr; else String.Format("{0}, Comment: {1}", _Poly.Description, tmpStr); } tmpDouble = metaKit.GetDouble(viewId, i, 11); if(tmpDouble > 0) _Poly.PolyAccu = tmpDouble; _Polygons.Add(_Poly.CN, _Poly); _IdToCN.Add(_Poly.Name, _Poly.CN); _PolyIndexes.Add(_Poly.CN, 0); if (tmpStr2 != null) { _IdToCN.Add(tmpStr2, _Poly.CN); } } #endregion #region Metadata viewId = metaKitViews[metadata]; TtMetaData newMeta; for (int i = 0; i < metaKit.GetRowCount(viewId); i++) { newMeta = new TtMetaData(); newMeta.CN = Guid.NewGuid().ToString(); tmpInt = metaKit.GetInt(viewId, i, 2); if (tmpInt > -1) newMeta.Zone = tmpInt; newMeta.Receiver = metaKit.GetString(viewId, i, 3); newMeta.Laser = metaKit.GetString(viewId, i, 4); newMeta.Compass = metaKit.GetString(viewId, i, 5); newMeta.Crew = metaKit.GetString(viewId, i, 9); newMeta.Comment = metaKit.GetString(viewId, i, 17); tmpStr = metaKit.GetString(viewId, i, 10); if(tmpStr.IsEmpty()) { newMeta.Name = String.Format("Metadata {0}", metaData.Count + 1); metaLinkToId.Add(newMeta.Name, newMeta.CN); if (!metaLinkToId.ContainsKey(tmpStr)) metaLinkToId.Add(tmpStr, newMeta.CN); } else { newMeta.Name = tmpStr; metaLinkToId.Add(tmpStr, newMeta.CN); } tmpStr = metaKit.GetString(viewId, i, 11); tmpStr = tmpStr.ToLower(); if (tmpStr.Contains("meter")) newMeta.uomDistance = UomDistance.Meters; else if (tmpStr.Contains("chain")) newMeta.uomDistance = UomDistance.Chains; else if (tmpStr.Contains("tenth")) newMeta.uomDistance = UomDistance.FeetTenths; else if (tmpStr.Contains("inch")) newMeta.uomDistance = UomDistance.FeetInches; else if (tmpStr.Contains("yard")) newMeta.uomDistance = UomDistance.Yards; tmpStr = metaKit.GetString(viewId, i, 15); tmpStr = tmpStr.ToLower(); if (tmpStr.Contains("feet")) newMeta.uomElevation = UomElevation.Feet; else if (tmpStr.Contains("meter")) newMeta.uomElevation = UomElevation.Meters; tmpStr = metaKit.GetString(viewId, i, 16); tmpStr = tmpStr.ToLower(); if (tmpStr.Contains("deg")) newMeta.uomSlope = UomSlope.Degrees; else if (tmpStr.Contains("per")) newMeta.uomSlope = UomSlope.Percent; metaData.Add(newMeta.CN, newMeta); } #endregion #region Points TtPoint point; GpsPoint gps; SideShotPoint ssp; viewId = metaKitViews[ptdata]; rowCount = metaKit.GetRowCount(viewId); for (int i = 0; i < rowCount; i++) { tmpStr = metaKit.GetString(viewId, i, 0); if (tmpStr.IsEmpty() || !polys.Contains(tmpStr)) continue; point = new TtPoint(); _Poly = _Polygons[_IdToCN[tmpStr]]; point.PolyCN = _Poly.CN; point.PolyName = _Poly.Name; point.GroupCN = Values.MainGroup.CN; point.GroupName = Values.MainGroup.Name; tmpInt = metaKit.GetInt(viewId, i, 1); if (tmpInt > 0) point.PID = tmpInt; else { if (_Points.Count > 1) PointNaming.NamePoint(_Points[_Points.Count - 1], _Poly); else PointNaming.NameFirstPoint(_Poly); } pidToCN.Add(point.PID, point.CN); tmpStr = metaKit.GetString(viewId, i, 2); if (tmpStr.IsEmpty() || !tmpStr.IsBool()) point.OnBnd = false; else point.OnBnd = tmpStr.ToBool(); OpType op; tmpStr = metaKit.GetString(viewId, i, 3); if (tmpStr.IsEmpty()) continue; else { try { op = (OpType)Enum.Parse(typeof(OpType), tmpStr, true); } catch { continue; } } switch (op) { case OpType.GPS: case OpType.Walk: case OpType.WayPoint: { gps = new GpsPoint(point); gps.UnAdjX = metaKit.GetDouble(viewId, i, 4); gps.UnAdjY = metaKit.GetDouble(viewId, i, 5); gps.UnAdjZ = metaKit.GetDouble(viewId, i, 6); //gps.UnAdjX = gps.X; //gps.UnAdjY = gps.Y; //gps.UnAdjZ = gps.Z; tmpDouble = metaKit.GetDouble(viewId, i, 32); if (tmpDouble != 0) gps.ManualAccuracy = tmpDouble; tmpDouble = metaKit.GetDouble(viewId, i, 33); if (tmpDouble != 0) gps.RMSEr = tmpDouble; if(metaKit.GetInt(viewId, i, 55) > 0) pointWNMEA.Add(point.PID); if (op == OpType.Walk) point = new WalkPoint(gps); else if (op == OpType.WayPoint) point = new WayPoint(gps); else point = gps; } break; case OpType.SideShot: case OpType.Traverse: { ssp = new SideShotPoint(point); tmpDouble = metaKit.GetDouble(viewId, i, 22); if (tmpDouble != -1) ssp.ForwardAz = tmpDouble; tmpDouble = metaKit.GetDouble(viewId, i, 23); if (tmpDouble != -1) ssp.BackwardAz = tmpDouble; ssp.SlopeDistance = metaKit.GetDouble(viewId, i, 24); ssp.SlopeAngle = metaKit.GetDouble(viewId, i, 25); if (op == OpType.Traverse) point = new TravPoint(ssp); else point = ssp; } break; case OpType.Quondam: { point = new QuondamPoint(point); tmpStr = metaKit.GetString(viewId, i, 29); try { if (!tmpStr.IsEmpty()) { tmpStr2 = tmpStr.Split(',')[1].Trim(); qndLinks.Add(point.CN, tmpStr2.ToInteger()); } } catch { //bad quondam } } break; default: continue; } tmpStr = metaKit.GetString(viewId, i, 56); if (tmpStr.IsEmpty() || !metadata.Contains(tmpStr)) point.MetaDefCN = _Meta.CN; else { point.MetaDefCN = metaData[tmpStr].CN; } tmpStr = metaKit.GetString(viewId, i, 38); if (!tmpStr.IsEmpty()) point.Comment = tmpStr; point.Index = _PolyIndexes[point.PolyCN]; _PolyIndexes[point.PolyCN]++; point.Time = DateTime.Now; _Points.Add(point); } for (int i = 0; i < _Points.Count; i++) { if (_Points[i].op == OpType.Quondam) { if(qndLinks.ContainsKey(_Points[i].CN)) { QuondamPoint qp = ((QuondamPoint)_Points[i]); qp.ParentPoint = _Points.Where(p => p.PID == qndLinks[qp.CN]).First(); _Points[i] = qp; } } } #endregion #region NMEA if (useNmea) { TwoTrails.GpsAccess.NmeaBurst burst; viewId = metaKitViews[nmeadata]; tmpInt = metaKit.GetRowCount(viewId); for (int i = 0; i < tmpInt; i++) { tmpStr = metaKit.GetString(viewId, i, 1); if (tmpStr.IsInteger()) { int pid = tmpStr.ToInteger(); if (pointWNMEA.Contains(pid)) { if (!nmeas.ContainsKey(pid)) nmeas.Add(pid, new List<TwoTrails.GpsAccess.NmeaBurst>()); burst = new TwoTrails.GpsAccess.NmeaBurst(); burst._CN = Guid.NewGuid().ToString(); burst._Used = metaKit.GetInt(viewId, i, 2) > 0; tmpStr = metaKit.GetString(viewId, i, 3); if (!tmpStr.IsEmpty()) burst._date = DateTime.ParseExact(tmpStr, "MMddyy", null); tmpStr2 = metaKit.GetString(viewId, i, 4); if (!tmpStr2.IsEmpty()) burst._date = DateTime.ParseExact(tmpStr + tmpStr2, "MMddyyHHmmss", null); burst._GGA_longitude = metaKit.GetDouble(viewId, i, 5); burst._RMC_longitude = burst._GGA_longitude; burst._GGA_latitude = metaKit.GetDouble(viewId, i, 6); burst._RMC_latitude = burst._GGA_latitude; burst._alt_unit = Unit.METERS; burst._altitude = metaKit.GetFloat(viewId, i, 11); burst._horiz_dilution_position = metaKit.GetDouble(viewId, i, 12); burst._fix_quality = metaKit.GetInt(viewId, i, 13); burst._fix = metaKit.GetInt(viewId, i, 15); burst._PDOP = metaKit.GetFloat(viewId, i, 16); burst._HDOP = metaKit.GetFloat(viewId, i, 17); burst._VDOP = metaKit.GetFloat(viewId, i, 18); burst._magVar = metaKit.GetFloat(viewId, i, 19); burst._num_of_sat = metaKit.GetInt(viewId, i, 20); burst._fixed_PRNs = metaKit.GetString(viewId, i, 21); burst._GGA_latDir = TwoTrails.GpsAccess.NorthSouth.North; burst._GGA_longDir = TwoTrails.GpsAccess.EastWest.West; burst._magVarDir = TwoTrails.GpsAccess.EastWest.East; burst._RMC_latDir = TwoTrails.GpsAccess.NorthSouth.North; burst._RMC_longDir = TwoTrails.GpsAccess.EastWest.West; for (int j = 22; j < 70; j += 4) { GpsAccess.Satellite s = new TwoTrails.GpsAccess.Satellite(); s.ID = metaKit.GetString(viewId, i, j); s.Elevation = metaKit.GetInt(viewId, i, j + 1); s.Azimuth = metaKit.GetInt(viewId, i, j + 2); s.SNR = metaKit.GetInt(viewId, i, j + 3); burst.AddSatalite(s); } burst.Complete(); nmeas[pid].Add(burst); } } } } #endregion dal.InsertPoints(_Points); foreach (TtMetaData m in metaData.Values) dal.InsertMetaData(m); foreach (TtPolygon poly in _Polygons.Values) dal.InsertPolygon(poly); foreach (KeyValuePair<int, List<GpsAccess.NmeaBurst>> bl in nmeas) dal.SaveNmeaBursts(bl.Value, pidToCN[bl.Key]); } catch (Exception ex) { TtUtils.WriteError(ex.Message, "DataImport:ImportTt", ex.StackTrace); return false; } return true; }
private void btnOk_Click2(object sender, EventArgs e) { if (_data) { try { using (CalcGpsPointForm form = new CalcGpsPointForm(NmeaData, pointName, pointCN, DAL, currentZone, false)) { form.ShowDialog(); if (form.IsCalaculated && !form.Canceled) { calculated = true; _Point = (GpsPoint)TtUtils.CopyPoint(form._GpsPoint); this.Close(); } else { calculated = false; //do nothing } } } catch { MessageBox.Show("Calculate Point Form Error."); } } else { MessageBox.Show("No Gps points logged."); } }
public bool ImportShapes(List<string> files, bool latlon, bool useShapeProps, bool useElev, bool elevFeet) { GeometryFactory factory; ShapefileDataReader shapeFileDataReader; ArrayList features; Feature feature; AttributesTable attributesTable; string[] keys; Geometry geometry; DbaseFieldDescriptor fldDescriptor; int polyCount = (int)dal.GetPolyCount(); GpsPoint gps; int index = 0; _Polygons = new Dictionary<string, TtPolygon>(); _Points = new List<TtPoint>(); List<TtPoint> tmpPoints = new List<TtPoint>(); try { foreach (string file in files) { //polyCount = 1; factory = new GeometryFactory(); shapeFileDataReader = new ShapefileDataReader(file, factory); DbaseFileHeader header = shapeFileDataReader.DbaseHeader; features = new ArrayList(); while (shapeFileDataReader.Read()) { feature = new Feature(); attributesTable = new AttributesTable(); keys = new string[header.NumFields]; geometry = (Geometry)shapeFileDataReader.Geometry; for (int i = 0; i < header.NumFields; i++) { fldDescriptor = header.Fields[i]; keys[i] = fldDescriptor.Name; attributesTable.AddAttribute(fldDescriptor.Name, shapeFileDataReader.GetValue(i)); } feature.Geometry = geometry; feature.Attributes = attributesTable; features.Add(feature); } bool areAllPoints = true; foreach (Feature feat in features) { if (feat.Geometry.GeometryType.ToLower() != "point") { areAllPoints = false; break; } } //if all features are points if (areAllPoints) { tmpPoints.Clear(); _Poly = new TtPolygon(1000 * polyCount + 10); _Poly.Name = Path.GetFileNameWithoutExtension(file); index = 0; foreach (Feature feat in features) { //if features is only a point there should only be 1 coord foreach (Coordinate coord in feat.Geometry.Coordinates) { gps = new GpsPoint(); gps.OnBnd = true; gps.Index = index; index++; gps.MetaDefCN = _Meta.CN; if (tmpPoints.Count > 0) gps.PID = PointNaming.NamePoint(tmpPoints.Last(), _Poly); else gps.PID = PointNaming.NameFirstPoint(_Poly); if (latlon) { double x,y; TtUtils.LatLontoUTM(coord.Y, coord.X, _Meta.Zone, out y, out x); gps.UnAdjX = x; gps.UnAdjY = y; } else { gps.UnAdjX = coord.X; gps.UnAdjY = coord.Y; } if (useElev) { if (coord.Z != double.NaN) { if (elevFeet) gps.UnAdjZ = TtUtils.ConvertToMeters(coord.Z, Unit.FEET_TENTH); else gps.UnAdjZ = coord.Z; } else gps.UnAdjZ = 0; } else gps.UnAdjZ = 0; gps.PolyCN = _Poly.CN; gps.PolyName = _Poly.Name; gps.GroupCN = Values.MainGroup.CN; gps.GroupName = Values.MainGroup.Name; tmpPoints.Add(gps); } _Points.AddRange(tmpPoints); } _Polygons.Add(_Poly.CN, _Poly); polyCount++; } else //else get points out of each features { int fidInc = 0; foreach (Feature feat in features) { tmpPoints.Clear(); _Poly = new TtPolygon(1000 * polyCount + 10); if (features.Count < 2) _Poly.Name = Path.GetFileNameWithoutExtension(file); else _Poly.Name = String.Format("{0}-{1}", fidInc++, Path.GetFileNameWithoutExtension(file)); #region Shape Desc Properties if (useShapeProps) { object[] objs = feat.Attributes.GetValues(); string[] names = feat.Attributes.GetNames(); string objv; for (int i = 0; i < feat.Attributes.Count; i++) { if (objs[i] is string) { objv = (string)objs[i]; if (objv.IsEmpty()) continue; switch (names[i].ToLower()) { case "description": case "comment": case "poly": if (_Poly.Description.IsEmpty()) _Poly.Description = objv; else _Poly.Description = String.Format("{0} | {1}", _Poly.Description, objv); break; case "name": case "unit": _Poly.Name = objv; break; } } } } #endregion index = 0; foreach (Coordinate coord in feat.Geometry.Coordinates) { gps = new GpsPoint(); gps.OnBnd = true; gps.Index = index; index++; gps.MetaDefCN = _Meta.CN; if (tmpPoints.Count > 0) gps.PID = PointNaming.NamePoint(tmpPoints.Last(), _Poly); else gps.PID = PointNaming.NameFirstPoint(_Poly); if (latlon) { double x, y; TtUtils.LatLontoUTM(coord.Y, coord.X, _Meta.Zone, out y, out x); gps.UnAdjX = x; gps.UnAdjY = y; } else { gps.UnAdjX = coord.X; gps.UnAdjY = coord.Y; } if (useElev) { if (coord.Z == double.NaN) { if (elevFeet) gps.UnAdjZ = TtUtils.ConvertToMeters(coord.Z, Unit.FEET_TENTH); else gps.UnAdjZ = coord.Z; } else gps.UnAdjZ = 0; } else gps.UnAdjZ = 0; gps.PolyCN = _Poly.CN; gps.PolyName = _Poly.Name; gps.GroupCN = Values.MainGroup.CN; gps.GroupName = Values.MainGroup.Name; tmpPoints.Add(gps); } _Points.AddRange(tmpPoints); _Polygons.Add(_Poly.CN, _Poly); polyCount++; } } //Close and free up any resources shapeFileDataReader.Close(); shapeFileDataReader.Dispose(); } foreach (TtPolygon poly in _Polygons.Values) dal.InsertPolygon(poly); dal.InsertPoints(_Points); PolygonAdjuster.Adjust(dal); } catch (Exception ex) { TtUtils.WriteError(ex.Message, "DataImport:ImportShapes", ex.StackTrace); return false; } return true; }
public bool ImportText(bool latLng, bool multiPoly, bool usePID, bool useIndex, bool useElev, bool elevFeet, bool useComment, bool useBound) { try { string line, tmp; int pidIndex = -1, xIndex = -1, yIndex = -1, zIndex = -1, cmtIndex = -1, polyIndex = -1, bndIndex = -1, iIndex = -1; int mX = 0, mY = 0, mZ = 0; _Polygons = new Dictionary<string, TtPolygon>(); _PolyIndexes = new Dictionary<string, int>(); _IdToCN = new Dictionary<string, string>(); _Points = new List<TtPoint>(); int requiredFields = 2 + (multiPoly ? 1 : 0) + (usePID ? 1 : 0) + (useIndex ? 1 : 0) + (useElev ? 1 : 0); if (!multiPoly) { int polyCount = (int)dal.GetPolyCount(); polyCount++; _Poly = new TtPolygon(1000 * polyCount + 10); _Poly.Name = String.Format("Poly {0}", polyCount); _Polygons.Add(_Poly.CN, _Poly); } using (StreamReader sr = new StreamReader(_FileName)) { if (sr.EndOfStream) { MessageBox.Show("Empty File"); return false; } line = sr.ReadLine(); #region Get Fields List<string> strOrder = line.Split(',').ToList(); if (strOrder.Count < 2) { MessageBox.Show("Invalid File Info"); return false; } else { for (int i = 0; i < strOrder.Count; i++) { #region Parse Fields switch (strOrder[i].ToLower()) { #if !(PocketPC || WindowsCE || Mobile) //pc only case "x": case "adjx": case "xadj": if (!latLng) { xIndex = i; mX++; } break; case "lon": case "lng": case "long": case "longitude": if (latLng) { xIndex = i; mX++; } break; case "y": case "adjy": case "yadj": if (!latLng) { yIndex = i; mY++; } break; case "lat": case "latitude": if (latLng) { yIndex = i; mY++; } break; case "z": case "adjz": case "zadj": case "elev": case "elevation": case "altitide": zIndex = i; mZ++; break; //pc only #endif case "pid": case "id": case "point id": pidIndex = i; break; case "cmt": case "comment": case "note": case "notes": cmtIndex = i; break; case "poly": case "polygon": case "poly name": case "polygon name": case "poly index": case "polygon index": polyIndex = i; break; case "bnd": case "bound": case "onbnd": case "onbound": case "boundary": case "onboundary": bndIndex = i; break; case "idx": case "indx": case "index": iIndex = i; break; default: //unknown field break; } #endregion } #if !(PocketPC || WindowsCE || Mobile) using (TextImportFieldSelectionForm form = new TextImportFieldSelectionForm( pidIndex, xIndex, yIndex, zIndex, cmtIndex, polyIndex, bndIndex, iIndex, strOrder.ToArray())) { if (form.ShowDialog() == DialogResult.OK) { pidIndex = form.iPID; xIndex = form.iX; yIndex = form.iY; zIndex = form.iZ; cmtIndex = form.iComment; polyIndex = form.iPoly; bndIndex = form.iBound; iIndex = form.iIndex; elevFeet = form.bFeet; latLng = form.bLatLon; } else { return false; } } #else #region Unknown / Dup Fields if (xIndex < 0 || mX > 1) { using (Selection form = new Selection("Select X value field", strOrder, 0)) { if (form.ShowDialog() == DialogResult.OK) { form.Width = form.Width + 100; if (form.selection > -1) xIndex = form.selection; } else return false; } } if (yIndex < 0 || mY > 1) { using (Selection form = new Selection("Select Y value field", strOrder, 0)) { if (form.ShowDialog() == DialogResult.OK) { if (form.selection > -1) yIndex = form.selection; } else return false; } } if (useElev && (zIndex < 0 || mZ > 1)) { using (Selection form = new Selection("Select Elevation field", strOrder, 0)) { if (form.ShowDialog() == DialogResult.OK) { if (form.selection > -1) zIndex = form.selection; } else return false; } } if (usePID && pidIndex < 0) { using (Selection form = new Selection("Select Point ID field", strOrder, 0)) { if (form.ShowDialog() == DialogResult.OK) { if (form.selection > -1) pidIndex = form.selection; } else return false; } } if (multiPoly && polyIndex < 0) { using (Selection form = new Selection("Select Poly ID field", strOrder, 0)) { if (form.ShowDialog() == DialogResult.OK) { if (form.selection > -1) polyIndex = form.selection; } else return false; } } if (useIndex && iIndex < 0) { using (Selection form = new Selection("Select Point Index field", strOrder, 0)) { if (form.ShowDialog() == DialogResult.OK) { if (form.selection > -1) iIndex = form.selection; } else return false; } } #endregion #endif } #endregion int index = 0; #region Parse Data while (!sr.EndOfStream) { line = sr.ReadLine(); List<string> details = line.Split(',').ToList(); if (details.Count < requiredFields) continue; GpsPoint p = new GpsPoint(); if (multiPoly || polyIndex > -1) { tmp = details[polyIndex]; if (tmp.Length > 0) { if(_IdToCN.ContainsKey(tmp)) { _Poly = _Polygons[_IdToCN[tmp]]; } else { _Poly = new TtPolygon(1000 * (_Polygons.Count + 1) + 10); _Poly.Name = details[polyIndex]; _Polygons.Add(_Poly.CN, _Poly); _IdToCN.Add(_Poly.Name, _Poly.CN); _PolyIndexes.Add(_Poly.CN, 0); } } else continue; } p.PolyCN = _Poly.CN; p.PolyName = _Poly.Name; p.MetaDefCN = _Meta.CN; if (!usePID || polyIndex < 0) { if (_Points.Count > 0) { p.PID = PointNaming.NamePoint(_Points.Last(), _Poly); } else { p.PID = PointNaming.NameFirstPoint(_Poly); } } else { tmp = details[pidIndex]; if (tmp.Length > 0 && tmp.IsInteger()) { p.PID = Convert.ToInt32(tmp); } else { PointNaming.NamePoint(_Points.Last(), _Poly); } } try { tmp = details[xIndex]; if (tmp.Length > 0 && tmp.IsDouble()) { p.UnAdjX = Convert.ToDouble(tmp); } else p.UnAdjX = 0; tmp = details[yIndex]; if (tmp.Length > 0) p.UnAdjY = Convert.ToDouble(tmp); else p.UnAdjY = 0; if (useElev) { tmp = details[zIndex]; if (tmp.Length > 0 && tmp.IsDouble()) { if (elevFeet) p.UnAdjZ = TtUtils.ConvertToMeters(tmp.ToDouble(), Unit.FEET_TENTH); else p.UnAdjZ = tmp.ToDouble(); } else { p.UnAdjZ = 0; } } if (latLng) { double x, y; TtUtils.LatLontoUTM(p.UnAdjY, p.UnAdjX, _Meta.Zone, out y, out x); p.UnAdjX = x; p.UnAdjY = y; } } catch { continue; } if (cmtIndex > -1) { p.Comment = details[cmtIndex]; } if (useIndex && iIndex > -1) { tmp = details[iIndex]; if (tmp.IsInteger()) { p.Index = tmp.ToInteger(); index = (int)(p.Index + 1); } else continue; } else { if (multiPoly || polyIndex > -1) { p.Index = _PolyIndexes[p.PolyCN]; _PolyIndexes[p.PolyCN]++; } else { p.Index = index; index++; } } if (bndIndex > -1) { tmp = details[bndIndex]; if (tmp.IsBool()) { p.OnBnd = tmp.ToBool(); } } else { p.OnBnd = true; } p.GroupCN = Values.MainGroup.CN; p.GroupName = Values.MainGroup.Name; _Points.Add(p); } #endregion foreach (TtPolygon p in _Polygons.Values) { dal.InsertPolygon(p); } dal.InsertPoints(_Points); PolygonAdjuster.Adjust(dal); return true; } } catch (Exception ex) { TtUtils.WriteError(ex.Message, "ImportFormnLogic:ParseTxt", ex.StackTrace); MessageBox.Show(@"An Error has occured while importing data. Make sure other applications are not using the file which is being imported. Check the error log for complete details.", "Import Error"); } return false; }
public GpsPoint(GpsPoint p) : base(p) { GpsCopy(p); }
public bool ImportGpx(bool useElev, bool elevFeet) { _Points = new List<TtPoint>(); List<TtPolygon> polys = new List<TtPolygon>(); using(XmlTextReader r = new XmlTextReader(new StreamReader(_FileName))) { bool inObject, inPoly, inPoint, inElev, fpoint; inObject = inPoly = inPoint = inElev = fpoint = false; double lat, lon, elev, utmX, utmY; lat = lon = elev = utmX = utmY = 0; GpsPoint point = new GpsPoint(); TtPolygon poly = new TtPolygon(); int polyCount = (int)dal.GetPolyCount() + 1, index = 0; string tmp; try { try { r.Namespaces = false; while (r.Read()) { switch (r.NodeType) { case XmlNodeType.Element: { if (r.Name == "rte" || r.Name == "trk") inObject = true; else if (!inPoly && (r.Name == "rtept" || r.Name == "trkseg")) { inPoly = true; poly = new TtPolygon(); poly.Name = String.Format("Poly {0}", polyCount); poly.PointStartIndex = polyCount * 1000 + 10; polyCount++; poly.IncrementBy = 10; fpoint = true; index = 0; } else if (inPoly && (r.Name == "rtept" || r.Name == "trkpt")) { inPoint = true; point = new GpsPoint(); tmp = r.GetAttribute("lat"); if (tmp.IsDouble()) lat = tmp.ToDouble(); tmp = r.GetAttribute("lon"); if (tmp.IsDouble()) lon = tmp.ToDouble(); } else if (r.Name == "ele") inElev = true; } break; case XmlNodeType.EndElement: { if (r.Name == "rte" || r.Name == "trk") inObject = false; else if (!inPoint && (r.Name == "rtept" || r.Name == "trkseg")) { inPoly = false; polys.Add(poly); } else if (inPoint && (r.Name == "rtept" && inPoint || r.Name == "trkpt")) { inPoint = false; if (lat != 0 && lon != 0) { if (fpoint) point.PID = PointNaming.NameFirstPoint(poly); else point.PID = PointNaming.NamePoint(_Points[_Points.Count - 1], poly); point.PolyCN = poly.CN; point.PolyName = poly.Name; point.MetaDefCN = _Meta.CN; point.Index = index; index++; point.OnBnd = true; point.GroupCN = Values.MainGroup.CN; point.GroupName = Values.MainGroup.Name; TtUtils.LatLontoUTM(lat, lon, _Meta.Zone, out utmY, out utmX); point.UnAdjX = utmX; point.UnAdjY = utmY; if (useElev) { if (elevFeet) point.UnAdjZ = TtUtils.ConvertToMeters(elev, Unit.FEET_TENTH); else point.UnAdjZ = elev; } _Points.Add(point); fpoint = false; } } else if (r.Name == "ele") inElev = false; } break; case XmlNodeType.Text: { if (inElev) { if (r.Value.IsDouble()) elev = r.Value.ToDouble(); } } break; default: break; } } } catch (XmlException ex) { if (!ex.Message.ToLower().Contains("undeclared")) { return false; } } foreach (TtPolygon p in polys) dal.InsertPolygon(p); dal.InsertPoints(_Points); } catch (Exception ex) { TtUtils.WriteError(ex.Message, "DataImport:ImportGpx", ex.StackTrace); return false; } } return true; }
protected void GpsCopy(GpsPoint p) { this.ManualAccuracy = p.ManualAccuracy; this.RMSEr = p.RMSEr; //this.X = p.X; //this.Y = p.Y; //this.Z = p.Z; this.AdjX = p.AdjX; this.AdjY = p.AdjY; this.AdjZ = p.AdjZ; this.UnAdjX = p.UnAdjX; this.UnAdjY = p.UnAdjY; this.UnAdjZ = p.UnAdjZ; }
public Take5Point(GpsPoint p) { _op = TwoTrails.Engine.OpType.Take5; }
private void ChangeToPoly(int index) { if (index < 0 || index > _Polygons.Count - 1) return; if (_ToPolygon != _Polygons[index]) { _ToPolygon = _Polygons[index]; #if (PocketPC || WindowsCE || Mobile) btnToPoly.Text = _ToPolygon.Name; #endif cboToPoint.Items.Clear(); _ToPointNames.Clear(); _ToPoints = DAL.GetPointsInPolygon(_ToPolygon.CN); if (_ToPoints.Count == 0) { _ToPoint = new GpsPoint(0, 0, 0); txtToX.Text = String.Empty; txtToY.Text = String.Empty; cboToPoint.Text = String.Empty; } else { foreach (TtPoint p in _ToPoints) { cboToPoint.Items.Add(p.PID); _ToPointNames.Add(p.PID.ToString()); } cboToPoint.SelectedIndex = 0; } } }
private void InsertGPS(GpsPoint gpsPoint, SQLiteTransaction trans) { StringBuilder queryBeginning = new StringBuilder(); StringBuilder queryEnd = new StringBuilder(); queryBeginning.AppendFormat("INSERT INTO {0} (", TwoTrailsSchema.GpsPointSchema.TableName); queryEnd.Append("("); //CN queryBeginning.AppendFormat("{0},", TwoTrailsSchema.SharedSchema.CN); queryEnd.AppendFormat("'{0}',", gpsPoint.CN); //User accuracy queryBeginning.AppendFormat("{0},", TwoTrailsSchema.GpsPointSchema.UserAccuracy); queryEnd.AppendFormat("{0},", (gpsPoint.ManualAccuracy == null) ? ("null") : (String.Format("'{0}'", gpsPoint.ManualAccuracy.ToString()))); //RMSEr queryBeginning.AppendFormat("{0},", TwoTrailsSchema.GpsPointSchema.RMSEr); queryEnd.AppendFormat("{0},", (gpsPoint.RMSEr == null) ? ("null") : (String.Format("'{0}'", gpsPoint.RMSEr.ToString()))); //X queryBeginning.AppendFormat("{0},", TwoTrailsSchema.GpsPointSchema.X); queryEnd.AppendFormat("'{0}',", gpsPoint.UnAdjX); //Y queryBeginning.AppendFormat("{0},", TwoTrailsSchema.GpsPointSchema.Y); queryEnd.AppendFormat("'{0}',", gpsPoint.UnAdjY); //Z queryBeginning.AppendFormat("{0}", TwoTrailsSchema.GpsPointSchema.Z); queryEnd.AppendFormat("'{0}'", gpsPoint.UnAdjZ); queryBeginning.Append(") values "); queryEnd.Append(");"); queryBeginning.AppendFormat(" {0}", queryEnd.ToString()); SQLiteCommand update = _dbConnection.CreateCommand(); try { if (trans != null) update.Transaction = trans; update.CommandText = queryBeginning.ToString(); update.ExecuteNonQuery(); } catch (Exception ex) { TtUtils.WriteError(ex.Message, "DataAccessLayer:InsertGPS"); } finally { update.Dispose(); } }
protected void SavePoint(TtPoint currentPoint, GpsPoint updatedPoint, SQLiteTransaction trans) { StringBuilder query = new StringBuilder(); query.AppendFormat("Update {0} set ", TwoTrailsSchema.GpsPointSchema.TableName); UpdateBasePoint(currentPoint, updatedPoint, trans); query.AppendFormat("{0} = {1}, ", TwoTrailsSchema.GpsPointSchema.UserAccuracy, (updatedPoint.ManualAccuracy == null) ? ("null") : (String.Format("'{0}'", updatedPoint.ManualAccuracy.ToString()))); query.AppendFormat("{0} = {1}, ", TwoTrailsSchema.GpsPointSchema.RMSEr, (updatedPoint.RMSEr == null) ? ("null") : (String.Format("'{0}'", ((updatedPoint.RMSEr).ToString())))); query.AppendFormat("{0} = {1}, ", TwoTrailsSchema.GpsPointSchema.X, updatedPoint.UnAdjX); query.AppendFormat("{0} = {1}, ", TwoTrailsSchema.GpsPointSchema.Y, updatedPoint.UnAdjY); query.AppendFormat("{0} = {1} ", TwoTrailsSchema.GpsPointSchema.Z, updatedPoint.UnAdjZ); query.AppendFormat("where {0} = '{1}'", TwoTrailsSchema.SharedSchema.CN, updatedPoint.CN); ExecuteUpdate(query.ToString(), trans); }
private void DisplayGPS(GpsPoint gpsPoint) { walkInfoCtrl1.Visible = false; take5InfoCtrl1.Visible = false; gpsInfoControl1.Visible = true; gpsInfoControl1.CurrentPoint = gpsPoint; gpsInfoControl1.MiscButtonText = "ReCalc"; gpsInfoControl1.ShowMiscButton = true; gpsInfoControl1.Meta = CurrMeta; travInfoControl1.Visible = false; quondamInfoControl1.Visible = false; actionsControl.MiscButtonText = "Aquire"; actionsControl.MiscButtonEnabled = true; }
private void gpsInfoControl1_MiscClick2() { if (pointInfoCtrl.Op == OpType.Take5) { take5InfoCtrl1.Visible = true; gpsInfoControl1.Visible = false; } else if(pointInfoCtrl.Op == OpType.Walk) { walkInfoCtrl1.Visible = true; gpsInfoControl1.Visible = false; } else if (pointInfoCtrl.Op == OpType.GPS) { if (UpdatedPoint != null && TtUtils.PointHasValue(UpdatedPoint)) { List<GpsAccess.NmeaBurst> bursts = DAL.GetNmeaBurstsByPointCN(UpdatedPoint.CN); if (bursts.Count > 0) { using (CalcGpsPointForm form = new CalcGpsPointForm(bursts, UpdatedPoint.PID, UpdatedPoint.CN, DAL, CurrMeta.Zone, true)) { form.ShowDialog(); if (form.IsCalaculated && !form.Canceled) { GpsPoint gpsPoint = form._GpsPoint; GpsPoint currGps = new GpsPoint(UpdatedPoint); currGps.Time = DateTime.Now; currGps.UnAdjX = gpsPoint.UnAdjX; currGps.UnAdjY = gpsPoint.UnAdjY; currGps.UnAdjZ = gpsPoint.UnAdjZ; ////currGps.X = gpsPoint.X; ////currGps.Y = gpsPoint.Y; ////currGps.Z = gpsPoint.Z; currGps.RMSEr = gpsPoint.RMSEr; _UpdatedPoint = currGps; GetConversion(ref _UpdatedPoint); gpsInfoControl1.CurrentPoint = (GpsPoint)UpdatedPoint; _dirty = true; LockControls(true); } } } else { AutoClosingMessageBox.Show("No NMEA data associated with point.", "No NMEA", 1000); } } } }