public void insertTrip(IKmlFolder trip, String tripNumber, TripPool t_pool) { //This will add a trip to the dataTable addToUndoTypeTable("Insert"); undoTable.Rows.Add(tripNumber, ""); DataRow row = NewRowDataTableCustom(); row[0] = tripNumber; row[1] = databaseViewer.Rows[0][1]; //The trip count will be set with the resetTripCount row[3] = databaseViewer.Rows[0][3]; row[4] = databaseViewer.Rows[0][4]; row[5] = databaseViewer.Rows[0][5]; row[6] = databaseViewer.Rows[0][6]; IKmlObjectList points = trip.getFeatures().getChildNodes(); IKmlPlacemark startPoint = (IKmlPlacemark)points.item(0); IKmlPlacemark finishPoint = (IKmlPlacemark)points.item(points.getLength() - 1); row[12] = Module.getCoordinates(startPoint)["lon"].ToString(); row[13] = Module.getCoordinates(startPoint)["lat"].ToString(); row[14] = Module.getCoordinates(finishPoint)["lon"].ToString(); row[15] = Module.getCoordinates(finishPoint)["lat"].ToString(); databaseViewer.Rows.InsertAt(row, Convert.ToInt32(tripNumber) - 1); DataRow newRowKML = t_pool.NewRowDataTableCustom(); newRowKML = copyDataRowContents(row, newRowKML); t_pool.getTripDetails().Rows.InsertAt(newRowKML, Convert.ToInt32(tripNumber) - 1); completeMissingData(t_pool); t_pool.resetTripCount(); resetTripCountForDay(); }
/* * add a new trip to the end of trippool */ public void add(IKmlFolder trip) { IKmlFolder addTrip = trip; IKmlObjectList points = trip.getFeatures().getChildNodes(); IKmlPlacemark startPoint = (IKmlPlacemark)points.item(0); IKmlPlacemark finishPoint = (IKmlPlacemark)points.item(points.getLength() - 1); String startTime = startPoint.getName(); String finishTime = finishPoint.getName(); String startLong = Module.getCoordinates(startPoint)["lon"].ToString(); String startLat = Module.getCoordinates(startPoint)["lat"].ToString(); String time = (DateTime.Parse(finishTime) - DateTime.Parse(startTime)).ToString(); String distance = Module.calDistance(trip).ToString(); String finishLong = Module.getCoordinates(finishPoint)["lon"].ToString(); String finishLat = Module.getCoordinates(finishPoint)["lat"].ToString(); String[] timeSplit = new String[3]; timeSplit = time.ToString().Split(':'); double coEff = (3600 / (double)((Convert.ToInt32(timeSplit[0]) * 3600) + (Convert.ToInt32(timeSplit[1]) * 60) + (Convert.ToInt32(timeSplit[2])))); String speed = Math.Round((double.Parse(distance) * coEff), 3).ToString(); _core.Add(addTrip); //_attr.Add(addAtt); TripDetails.Rows.Add(tripCount, Day, "-", HouseHoldID, "-", Date, WeekDay, startTime, finishTime, time, distance, speed, startLong, startLat, finishLong, finishLat, "-"); ++tripCount; }
public String insert(String name, IKmlFolder trip, String[] att) { de_highlight(); int index = int.Parse(name.Split('_')[1]); String style = ""; String _style = ""; IKmlFolder temp1 = getByName("Trip_" + index); IKmlFolder temp2 = getByName("Trip_" + (index + 1)); IKmlObjectList points = temp1.getFeatures().getChildNodes(); for (int ii = 0; ii != points.getLength(); ii++) { IKmlPlacemark point = (IKmlPlacemark)points.item(ii); trip.getFeatures().appendChild(point); if (ii == 1) { style = point.getStyleUrl(); } } points = temp2.getFeatures().getChildNodes(); for (int ii = 0; ii != points.getLength(); ii++) { IKmlPlacemark point = (IKmlPlacemark)points.item(ii); if (ii == 1) { _style = point.getStyleUrl(); } point.setStyleUrl(style); trip.getFeatures().appendChild(point); } _core.RemoveAt(index - 1); _attr.RemoveAt(index - 1); _core.RemoveAt(index - 1); _attr.RemoveAt(index - 1); _core.Insert(index - 1, trip); _attr.Insert(index - 1, att); return(_style); }
public PointPool(IKmlFolder trip) { core = new Hashtable(); names = new ArrayList(); IKmlObjectList points = trip.getFeatures().getChildNodes(); for (int i = 0; i < points.getLength(); i++) { IKmlPlacemark pt = (IKmlPlacemark)points.item(i); core[pt.getName()] = pt; names.Add(pt.getName()); } p_highlight = ""; _style = ""; }
public IKmlPlacemark getNextPoint(IKmlFolder trip, IKmlPlacemark point) { bool flag = false; IKmlObjectList points = trip.getFeatures().getChildNodes(); for (int i = 0; i != points.getLength(); ++i) { IKmlPlacemark pt = (IKmlPlacemark)points.item(i); if (flag == true) { return(pt); } if (pt.getName() == point.getName()) { flag = true; } } return(null); }
/* * distance calculation using big-circle formula */ public static double calDistance(IKmlFolder trip) { double distance = 0; IKmlObjectList points = trip.getFeatures().getChildNodes(); IKmlPlacemark prev = null; for (int i = 0; i != (points.getLength()); i++) { IKmlPlacemark curr = (IKmlPlacemark)points.item(i); if (prev != null) { double d = DistanceAlgorithm.DistanceBetweenPlaces((double)getCoordinates(curr)["lat"], (double)getCoordinates(curr)["lon"] , (double)getCoordinates(prev)["lat"], (double)getCoordinates(prev)["lon"]); distance += d; } prev = curr; } return(Math.Round(distance, 3)); }
public String ch_col(String name, String col) { IKmlStyleMap sm = ge.createStyleMap(""); IKmlStyle normal = mkStyle(col, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.3); IKmlStyle highlight = mkStyle(col, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.4); sm.setNormalStyle(normal); sm.setHighlightStyle(highlight); IKmlFolder trip = getByName(name); IKmlObjectList points = trip.getFeatures().getChildNodes(); String temp = ((IKmlPlacemark)points.item(0)).getComputedStyle().getIconStyle().getColor().get(); for (int i = 0; i < points.getLength(); i++) { IKmlPlacemark pt = (IKmlPlacemark)points.item(i); pt.setStyleSelector(sm); } return(temp); }
public void addAtPosition(IKmlFolder trip, int tripNumber) { IKmlFolder addTrip = trip; IKmlObjectList points = trip.getFeatures().getChildNodes(); IKmlPlacemark startPoint = (IKmlPlacemark)points.item(0); IKmlPlacemark finishPoint = (IKmlPlacemark)points.item(points.getLength() - 1); String startTime = startPoint.getName(); String finishTime = finishPoint.getName(); String startLong = Module.getCoordinates(startPoint)["lon"].ToString(); String startLat = Module.getCoordinates(startPoint)["lat"].ToString(); String time = (DateTime.Parse(finishTime) - DateTime.Parse(startTime)).ToString(); String distance = Module.calDistance(trip).ToString(); String finishLong = Module.getCoordinates(finishPoint)["lon"].ToString(); String finishLat = Module.getCoordinates(finishPoint)["lat"].ToString(); String[] timeSplit = new String[3]; timeSplit = time.ToString().Split(':'); double coEff = (3600 / (double)((Convert.ToInt32(timeSplit[0]) * 3600) + (Convert.ToInt32(timeSplit[1]) * 60) + (Convert.ToInt32(timeSplit[2])))); String speed = Math.Round((double.Parse(distance) * coEff), 3).ToString(); // _core.Add(addTrip); //_attr.Add(addAtt); DataRow newRow = NewRowDataTableCustom(); newRow["KMLTrip"] = tripCount; newRow["HouseHoldID"] = HouseHoldID; newRow["Trip"] = "-"; newRow["Person"] = "-"; newRow["Day"] = Day; newRow["Date"] = Date; newRow["WeekDay"] = WeekDay; newRow["Start Time"] = startTime; newRow["Finish Time"] = finishTime; newRow["Time"] = time; newRow["Distance"] = distance; newRow["Speed"] = speed; newRow["StartLong"] = startLong; newRow["StartLat"] = startLat; newRow["Finishlong"] = finishLong; newRow["FinishLat"] = finishLat; newRow["Remain"] = "-"; TripDetails.Rows.InsertAt(newRow, tripNumber); resetTripCount(); }
public void resetTripData(String trip) { IKmlFolder tripData = getByName(trip); for (int i = 0; i != TripDetails.Rows.Count; ++i) { if (TripDetails.Rows[i]["KMLTrip"].ToString().Trim().Equals(Module.getIndex(trip).ToString())) { // MessageBox.Show("FCKING "+trip); IKmlFolder addTrip = tripData; IKmlObjectList points = tripData.getFeatures().getChildNodes(); IKmlPlacemark startPoint = (IKmlPlacemark)points.item(0); IKmlPlacemark finishPoint = (IKmlPlacemark)points.item(points.getLength() - 1); String startTime = startPoint.getName(); String finishTime = finishPoint.getName(); String startLong = Module.getCoordinates(startPoint)["lon"].ToString(); String startLat = Module.getCoordinates(startPoint)["lat"].ToString(); String time = (Convert.ToDateTime(finishTime) - Convert.ToDateTime(startTime)).ToString(); String distance = Module.calDistance(tripData).ToString(); String finishLong = Module.getCoordinates(finishPoint)["lon"].ToString(); String finishLat = Module.getCoordinates(finishPoint)["lat"].ToString(); String[] timeSplit = new String[3]; timeSplit = time.ToString().Split(':'); double coEff = (3600 / (double)((Convert.ToInt32(timeSplit[0]) * 3600) + (Convert.ToInt32(timeSplit[1]) * 60) + (Convert.ToInt32(timeSplit[2])))); String speed = Math.Round((double.Parse(distance) * coEff), 3).ToString(); TripDetails.Rows[i]["Start Time"] = startTime; TripDetails.Rows[i]["Finish Time"] = finishTime; TripDetails.Rows[i]["Time"] = time; TripDetails.Rows[i]["Distance"] = distance; TripDetails.Rows[i]["Speed"] = speed; TripDetails.Rows[i]["StartLong"] = startLong; TripDetails.Rows[i]["StartLat"] = startLat; TripDetails.Rows[i]["Finishlong"] = finishLong; TripDetails.Rows[i]["FinishLat"] = finishLat; TripDetails.Rows[i]["Remain"] = "-"; } } }
public ArrayList trimToEnd(String name, String time) { IKmlFolder trip = getByName(name); IKmlObjectList points = trip.getFeatures().getChildNodes(); ArrayList buffer = new ArrayList(); for (int i = points.getLength() - 1; i >= 0; i--) { if (Convert.ToDateTime(((IKmlPlacemark)points.item(i)).getName()) > Convert.ToDateTime(time)) { buffer.Add(points.item(i)); } else { break; } } for (int i = 0; i < buffer.Count; i++) { trip.getFeatures().removeChild(buffer[i]); } return(buffer); }
public IKmlPlacemark getFinish(IKmlFolder trip) { IKmlObjectList points = trip.getFeatures().getChildNodes(); return((IKmlPlacemark)points.item(points.getLength() - 1)); }
/* * insert a trip into trippool and remove the trip at the same index as well as the one after ( this is used by join ) */ public String insert(String name, IKmlFolder trip, String[] att, IKmlStyle sty) { de_highlight(); int index = int.Parse(name.Split('_')[1]); String style = ""; IKmlFolder temp1 = getByName("Trip_" + index); IKmlFolder temp2 = getByName("Trip_" + (index + 1)); IKmlObjectList points = temp1.getFeatures().getChildNodes(); for (int ii = 0; ii != points.getLength(); ii++) { IKmlPlacemark point = (IKmlPlacemark)points.item(ii); trip.getFeatures().appendChild(point); if (ii == 0) { style = point.getComputedStyle().getIconStyle().getColor().get(); } } points = temp2.getFeatures().getChildNodes(); IKmlStyleMap sm = ge.createStyleMap(""); IKmlStyle normal = mkStyle(style, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.3); IKmlStyle highlight = mkStyle(style, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.4); sm.setNormalStyle(normal); sm.setHighlightStyle(highlight); for (int ii = 0; ii != points.getLength(); ii++) { IKmlPlacemark point = (IKmlPlacemark)points.item(ii); if (ii == 0) { _style = point.getComputedStyle().getIconStyle().getColor().get(); } if (point.getGeometry().getType() != "KmlPoint") { point.getComputedStyle().getLineStyle().setWidth((float)4); point.getComputedStyle().getLineStyle().getColor().set(style); } else { point.setStyleSelector(sm); } trip.getFeatures().appendChild(point); } _core.RemoveAt(index - 1); // _attr.RemoveAt(index - 1); // removeKMLTrip(index.ToString()); _core.RemoveAt(index - 1); //_attr.RemoveAt(index - 1); // removeKMLTrip(index.ToString()); _core.Insert(index - 1, trip); // _attr.Insert(index - 1, att); // addAtPosition(trip, index - 1); return(_style); }
public Boolean undo(Hashtable mem) { try { if (mem["opt"] == "del") { ArrayList rev = (ArrayList)mem["data"]; IKmlFolder _trip = (IKmlFolder)rev[1]; _trip.setVisibility(1); t_pool.add((String)rev[0], _trip, (String[])rev[2]); } else if (mem["opt"] == "spl") { ArrayList rev = (ArrayList)mem["data"]; IKmlFolder trip = (IKmlFolder)rev[1]; t_pool.insert((String)rev[0], trip, (String[])rev[2], ge.createStyle("")); trip.setVisibility(1); IKmlObjectList days = ge.getFeatures().getChildNodes(); IKmlDocument day = (IKmlDocument)days.item(0); day.getFeatures().appendChild(trip); } else if (mem["opt"] == "joi") { ArrayList rev = (ArrayList)mem["data"]; IKmlFolder temp = ge.createFolder(""); String name = (String)rev[0]; IKmlFolder[] sub = split(int.Parse((name.Split('_')[1])), t_pool.getByName(name), (IKmlPlacemark)rev[1], (String)rev[4]); IKmlObjectList days = ge.getFeatures().getChildNodes(); IKmlDocument day = (IKmlDocument)days.item(0); day.getFeatures().appendChild(sub[0]); day.getFeatures().appendChild(sub[1]); t_pool.insert(int.Parse((name.Split('_')[1])), sub[0], (String[])rev[2], sub[1], (String[])rev[3]); } else if (mem["opt"] == "ins") { String rev = (String)mem["data"]; IKmlFolder trip = t_pool.getByName(rev); trip.setVisibility(0); t_pool.remove(rev); } else if (mem["opt"] == "crt") { IKmlPlacemark pt = (IKmlPlacemark)mem["data"]; ge.getFeatures().removeChild(pt); } else if (mem["opt"] == "mk_start" || mem["opt"] == "mk_finish") { ArrayList rev = (ArrayList)mem["data"]; IKmlPlacemark pt = (IKmlPlacemark)rev[1]; IKmlFolder trip = t_pool.getByName((String)rev[0]); //trip.getFeatures().removeChild(pt); //ge.getFeatures().appendChild(pt); } else if (mem["opt"] == "tm_start") { ArrayList rev = (ArrayList)mem["data"]; IKmlFolder trip = t_pool.getByName((String)rev[0]); IKmlObjectList points = trip.getFeatures().getChildNodes(); // MessageBox.Show(points.getLength().ToString()+" "+rev.Count.ToString()); for (int i = rev.Count - 1; i != 0; i--) { points = trip.getFeatures().getChildNodes(); trip.getFeatures().insertBefore(rev[i], points.item(0)); } } else if (mem["opt"] == "tm_finish") { ArrayList rev = (ArrayList)mem["data"]; IKmlFolder trip = t_pool.getByName((String)rev[0]); IKmlObjectList points = trip.getFeatures().getChildNodes(); // MessageBox.Show(points.getLength().ToString()+" "+rev.Count.ToString()); for (int i = rev.Count - 1; i != 0; i--) { points = trip.getFeatures().getChildNodes(); trip.getFeatures().insertBefore(rev[i], points.item(points.getLength() - 1)); } } else if (mem["opt"] == "ch_color") { ArrayList rev = (ArrayList)mem["data"]; t_pool.ch_col((String)rev[0], (String)rev[1]); } return(true); } catch { return(false); } }
public IKmlFolder[] split(int index, IKmlFolder raw, IKmlPlacemark _point, String style) { IKmlFolder[] output = new IKmlFolder[2]; String col = randomCol(); IKmlFolder temp1 = ge.createFolder(""); IKmlFolder temp2 = ge.createFolder(""); temp1.setName("Trip_" + (index).ToString()); temp2.setName("Trip_" + (index + 1).ToString()); int sw = 0; IKmlObjectList points = raw.getFeatures().getChildNodes(); for (int i = 0; i != points.getLength(); i++) { IKmlPlacemark point = (IKmlPlacemark)points.item(i); if (point.getName() == _point.getName()) { sw = 1; } if (sw == 0) { temp1.getFeatures().appendChild(point); } else { IKmlStyleMap sm = ge.createStyleMap(""); if (style != null) { if (point.getGeometry().getType() != "KmlPoint") { IKmlStyle sty = ge.createStyle(""); sty.getLineStyle().setWidth((float)4); sty.getLineStyle().getColor().set(style); point.setStyleSelector(sty); } else { IKmlStyle normal = mkStyle(style, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.3); IKmlStyle highlight = mkStyle(style, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.4); sm.setNormalStyle(normal); sm.setHighlightStyle(highlight); point.setStyleSelector(sm); } } else { if (point.getGeometry().getType() != "KmlPoint") { IKmlStyle sty = ge.createStyle(""); sty.getLineStyle().setWidth((float)4); sty.getLineStyle().getColor().set(col); point.setStyleSelector(sty); } else { IKmlStyle normal = mkStyle(col, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.3); IKmlStyle highlight = mkStyle(col, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.4); sm.setNormalStyle(normal); sm.setHighlightStyle(highlight); point.setStyleSelector(sm); } } temp2.getFeatures().appendChild(point); } } output[0] = temp1; output[1] = temp2; return(output); }