//public void getSubLineFromDKCode(string dkcode, double mileage, double dis, out double[] x, out double[] y, out double[] z, out double[] dir) //{ // x = y = z = dir = null; // double m = getPathMileageByDKCode(dkcode, mileage) ; // double m1, m2; // if (dis > 0) // { // m1 = m; // m2 = m + dis; // }else // { // m1 = m + dis; // m2 = m; // } // int fromIdx = getMileageIndex(m1); // int toIdx = getMileageIndex(m2); //} //int getMileageIndex(double mileage) //{ // if (mileage < 0 || mileage > mLength) // return -1; // int l = 0, r = mm.Length - 1; // int mid = (l + r) / 2; // while (l < r) // { // if (mileage < mm[mid]) // r = mid - 1; // else if (mileage > mm[mid]) // l = mid + 1; // else // return mid; // mid = (l + r) / 2; // } // r = Math.Max(r, 0); // l = Math.Min(l, mm.Length-1); // return Math.Abs(mm[r] - mileage) < Math.Abs(mm[l] - mileage) ? r :l ; //} ///// <summary> ///// 计算偏移一定角度和距离之后的经纬度 ///// </summary> ///// <param name="startDKM"></param> ///// <param name="endDKM"></param> ///// <param name="stepm"></param> ///// <param name="angleOff"></param> ///// <param name="disOff"></param> ///// <param name="latout"></param> ///// <param name="lonout"></param> ///// <param name="z"></param> ///// <returns></returns> //public int getOffsetLine(double angleOff, double disOff, out double[] latout, out double[] lonout, out double[] z) //{ // lonout = latout = z = null; // //double[] x = null; // //double[] y = null; // ////double[] z = null; // //double[] d = null; // //int pointNum = getSubLineByDKCode(startDKM, endDKM, stepm, out x, out y, out z, out d); // if (mPointCount > 0) // { // latout = new double[mPointCount]; // lonout = new double[mPointCount]; // for (int i = 0; i < mPointCount; i++) // { // CoordinateConverter.LatLonOffest(my[i], mx[i], md[i], angleOff, disOff, out latout[i], out lonout[i]); //lat, lon // } // z = mz; // } // return mPointCount; //} ///// <summary> ///// 求点与多条线段的最短距离,如果投影在多条线段内,返回t,否则f ///// </summary> ///// <param name="x">点</param> ///// <param name="y">点</param> ///// <param name="xa">多线段</param> ///// <param name="ya"></param> ///// <param name="ma"></param> ///// <param name="fromid">多线段起点下标</param> ///// <param name="toid">终点下标</param> ///// <param name="m">最近点</param> ///// <param name="dis">距离</param> ///// <returns></returns> //private bool getDistance(double x, double y, double[]xa, double[] ya, double[] ma ,int fromid, int toid, out double m, out double dis) //{ // bool found = false; // m = dis = 0; // double lx = xa[fromid]; // double ly = ya[fromid]; // double rx = xa[toid]; // double ry = ya[toid]; // if ((x - lx) * (rx - lx) + (y - ly) * (ry - ly) < 0) // { // m = ma[fromid]; // dis = CoordinateConverter.getUTMDistance(x, y, lx, ly); // } // else if ((x - rx)*(lx - rx) + (y - ry) * (ly - ry) < 0) // { // m = ma[toid]; // dis = CoordinateConverter.getUTMDistance(x, y, rx, ry); // } // else // { // found = true; // int minid = fromid; // dis = CoordinateConverter.getUTMDistance(x, y, lx, ly); // for (int i = fromid + 1; i<= toid; i++) // { // double di = CoordinateConverter.getUTMDistance(x, y, xa[i], ya[i]); // if (di < dis) { // dis = di; // minid = i; // } // } // int lid = minid - 1; // if (lid < fromid) lid = fromid; // int rid = minid + 1; // if (rid > toid) rid = toid; // double d1 = CoordinateConverter.getUTMDistance(x, y, xa[lid], ya[lid]); // double d2 = CoordinateConverter.getUTMDistance(x, y, xa[rid], ya[rid]); // double ddd =d1 /(d1 + d2); // //if (d1 > d2) // //{ // // ddd = disInterpolate(x, y, xa[lid], ya[lid], xa[rid], ya[rid]); // //} // //else // //{ // // ddd = 1 - disInterpolate(x,y,xa[rid],ya[rid],xa[lid],ya[lid]); // //} // m = ma[lid] + (ma[rid]-ma[lid]) * ddd; // double xm = xa[lid] + (xa[rid]-xa[lid]) *ddd; // double ym = ya[lid] + (ya[rid] - ya[lid]) * ddd; // dis = CoordinateConverter.getUTMDistance(x, y, xm, ym); // } // return found; //} ///误差太大 //private double disInterpolate(double x1,double y1,double x2,double y2,double x3,double y3) //{ // double dx1 = x1 - x2; // double dy1 = y1 - y2; // double dx2 = x3 - x2; // double dy2 = y3 - y2; // double len1 = Math.Sqrt(dx1 * dx1 + dy1 * dy1); // double len2 = Math.Sqrt(dx2 * dx2 + dy2 * dy2); // double cosa = (dx1 * dx2 + dy1 * dy2) / len1 / len2; // double d = len1 * Math.Sqrt (1 - cosa * cosa); // return d / len2; //} /// <summary> /// 给定经纬度,输出最近点里程与距离 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="mileage"></param> /// <param name="distance"></param> public void getPathMileagebyGPS(double x, double y, out double mileage, out double distance) { distance = 5000000; mileage = -1; if (!hasPath) { return; } //double m, d; //int step = Math.Max(100, (int)Math.Sqrt(mPointCount)); //int toid = 0; //for (int i = 0; i<mPointCount; i+= step) //{ // toid = Math.Min(i + step , mPointCount - 1); // getDistance(x, y, mx, my, mm, i, toid, out m, out d); // if (d<distance) // { // distance = d; // mileage = m; // } //} CSubLine.getMileagebyGPS(x, y, mm, mx, my, out mileage, out distance); }
/// <summary> /// 给定经纬度,输出里程与距离 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="mileage"></param> /// <param name="distance"></param> public void getDKMileagebyGPS(double x, double y, out double mileage, out double distance) { CSubLine.getMileagebyGPS(x, y, meter, longitude, latitude, out mileage, out distance); mileage = getDKMileagebyLocalMileage(mileage); }