軌道圧縮アルゴリズム
シーンの説明
GPSデータレコードファイルが与えられた場合、各レコードには2つの座標フィールド、経度と寸法が含まれており、距離のしきい値に応じてレコードを圧縮し、すべてのフィルターされたレコードの緯度と経度座標を持つトラックを形成します。
アルゴリズムの説明
このアルゴリズムには、幅広い用途があります。
軌道圧縮アルゴリズムは、2つのカテゴリに分けられます。つまり、ロスレス圧縮と損失のある圧縮です。ロスレス圧縮アルゴリズムには主にHuffmanコーディングが含まれ、Losy Compressionアルゴリズムはバッチ処理方法とオンラインデータ圧縮法に分けられます。バッチ処理方法には、DP(Douglas-Peucker)アルゴリズム、TD-TR(トップダウン時間比)アルゴリズム、およびBellmanアルゴリズムが含まれます。オンラインデータ圧縮方法には、スライディングウィンドウ、開いたウィンドウ、安全なエリアベースの方法などが含まれます。
この記事を参照することもできます。 「軌道圧縮を実装するJavaプログラミングのためのDouglas-Peuckerアルゴリズムの詳細なコード」
コード実装
java.awt.color; Import java.awt.graphics; import java.awt.point; Import java.awt.toolkit; Import java.io.bufferedReader; Import java.io.file; Import java.io.fileinputStream; Impont java.io.inutstreamcccccccccer. java.text.DecimalFormat;import java.util.ArrayList;import java.util.Iterator;import javax.swing.JFrame;import javax.swing.JPanel;public class TrajectoryCom {public static void main(String[] args) throws Exception{//Threshold definition double maxDistanceError = 30;/* * File reading* *///Storageファイルから読み取られた位置ポイントの情報arraylist <enpoint> enplist = new arrayList <enpoint>(); //ソースデータファイルのアドレスのファイルオブジェクトを作成する//これは、ソースファイルのストレージアドレスを変更する必要がある場合です。アドレスに「/」が含まれている場合は、別の「/」を追加することを忘れないでください。理由はエスケープシンボル// getEnPointFromFile(sourceFile); //これは、リスト内のデータを読み取ったかどうかをテストし、リスト内のデータの数を確認します。 system.out.println(enplist.size());/**データ処理*メソッドをコメントしてください。 openWindowtra(enplist、maxdistanceerror); system.out.println(repointlist.size());/ * *ターゲットファイルに書き込み * writeTestpointTofile(targetfile、repointList);/ * *コンパクトレート計算 */double cpl =(double)repointList.size()/(double)enplist.size() * 100; decimalformat()decimalformat( "0.000000"); system.out.out.out.out:平均距離エラー**/double avediserr = getMeanDisterRor(enplist、RepointList); system.out.println(avediserr);/**比較チャート* /// generateimage(enplist、perpointlist);}/**提供されたファイル情報からの抽出ポイントの抽出ポイントを抽出します。すべての位置ポイントの収集*/public static arraylist <enpoint> getEnpointfromfile(ファイルfgps)スロー{arraylist <enpoint> pgpsArray = new arraylist <enpoint>(); if(fgps.exists()&f()&fgps.isfile()){inputstreamreadedertream BufferedReader Breader = new BufferedReader(read); // cached read initialization string str; strgps [] strgps; int i = 0; while((str = breader.readline()!= null){// read strgps = str.split( ""); enpoint p = new enpot( (dftodu(strgps [3])); p.pn =(dftodu(strgps [5])); pgpsarray.add(p);} breader.close();} return pgpsarray;}/***関数:元の緯度と長期の座標データを変換します。 str){int indexd = str.indexof( '。'); // get。文字文字列strm = str.substring(0、indexd-2); // integer part string strn = str.substring(indexd-2); // decimal part double d = double.parsedouble(strn)+double.parsedouble(strn)/60; return d;}アルゴリズムの説明: *初期点と浮動小数点投影点を計算し、投影点と軌跡ポイントとしきい値の間の距離を判断します。距離がしきい値*よりも大きい場合、初期点はターゲットリストに配置され、フローティングポイントは新しい初期ポイントとして前方に検索され、新しい初期ポイントは新しいフローティングポイントとして2番目のものとして後方に検索します。ここに、新しい初期ポイント位置+1がリストの長さに等しいかどうかという判断があります。これにより、フローティングポイントの選択が決定されます*これはエンドポイントに処理されます**/public static arraylist <enpoint> openwindowtra(arraylist <enpote> sourcelist、double maxdis){arraylist <enpoint>ターゲットリスト= new arraylist <enpote>(); 2int floatpoint = 2; //現在のトラックポイント位置の初期ポイント位置を1int nowpoint = 1; int len = sourcelist.size(); //すべてのWindows arraylist <enpoint> listpoint = new arraylist <enpoint>(); listpoint.add(sourepoint.get);ウィンドウのトラックポイントを更新するかどうかのブールフラグ= false; //ウィンドウと投影ポイントのすべてのポイント間の距離が(enpoint Point:listpoint)のしきい値より大きいかどうかを計算して判断するif(disoftwo> = 30){flag = true; break;}} if(flag){//ウィンドウ内のポイントの距離はしきい値より大きく//初期ポイントはターゲットリストターゲットリスト(Saurcelist.get(StartPoint)); if(floatpoint> = len){targetlist.add(sourcelist.get(floatpoint-1)); break;} //ウィンドウのポイントはlistpoint.clear(); // system.out.println(listpoint.size()); listpoint.add(sourcelist.get(startpoint +1));} else {//距離はしきい値よりも少ない//初期点は変更されないままですしきい値、ウィンドウポイントを無視し、エンドポイントをターゲットポイントに直接追加する場合、(floatpoint> = len){saurcelist.add(startpoint)); targetlist.add(sourcelist.get(floatpoint-1)); break;}} flag = false;}ターゲットポイントを返すポイントの間の距離を消費します。および現在のトラックポイントC *三角領域式式 */public static double getDistance(enpoint A、enpoint B、enpoint C){double distance = 0; double a = math.abs(adist(a、b)); double b = math.abs(b、c)); double c = math.abs(c); double c = mathist(a c)/c)/bd(a、c); Math.sqrt(P *(PA) *(PB) *(PC));距離= S * 2.0/A; return距離;}/ * *コピー機能 * * // *提供された関数 *次の距離計算方法を取得するために距離を計算する関数 *私は距離を計算する方法 */public geodist pa){enpo1) rad(pa.pn); double radlat2 = rad(pb.pn); double delta_lon = rad(pb.pe -pa.pe); double top_1 = math.cos(radlat2) * math.sin(delta_lon); double top_2 = math.cos(radlat1) Math.Cos(Radlat2) * Math.Cos(Delta_lon); double Top = math.sqrt(top_1 * top_1 + top_2 * top_2); double bott = math.sin(radlat1) * math.sin(radlat2) + math.cos(radlat1) * math.cos(radlat2) * math.cos(dedlon); delta_sigma = math.atan2(top、bottom); double distang = delta_sigma * 6378137.0; return distance;} public static double rad(double d * math.pi/180.0;}/ * *圧縮位置のポイント情報を書き込みファイルに書き込み * pgpspointfilter)スロー例外{iterator <tonpoint> ifilter = pgpspointfilter.iterator(); randomaccessfile rfilter = new randomaccessfile(outgpsfile、 "rw"); while(ifilter.hasnext()){enpoint p = ifilter.next(); bfilter = sfilter.getBytes(); rfilter.write(bfilter);} rfilter.close();}/*** function関数:平均距離エラー*平均距離を返します*/public static getmeandististerror(arraylist <enpoint> pgpsarray、arraylist <enpers < i = 1; i <pgpsarrayre.size(); i ++){double = "" end = "pgpsarrayre.get(i).id;" int = "" j = "start+1; j <end; j ++){" means = "sumdist/(pgpsarray.size());" pre = "" return = "" start = "pgpsarrayre.get(i-1).id;" sumdist = "" "> <pre> import java.text.decimalformat; public class enpoings emplesments Camparable <enpoint> {public int id; // point idpublic double pe; //経度パブリックパブリックPN; //寸法{} //空の構成要素パブリックストリングtoString() getResultString(){decimalformat df = new decimalformat( "0.000000"); return this.id+"#"+df.format(this.pe)+"+"+" /n";}@public int compareto(enpoint){retunt other = oter = "" "" "" " this.id = ""> other.id)return 1;それ以外の場合は0;}}要約します
上記は、Javaプログラミングの実装軌跡圧縮アルゴリズムのオープンウィンドウインスタンスコードに関するこの記事の内容全体です。私はそれが誰にでも役立つことを願っています。欠点がある場合は、それを指摘するためにメッセージを残してください。