궤적 압축 알고리즘
장면 설명
GPS 데이터 레코드 파일이 주어지면 각 레코드에는 두 개의 좌표 필드, 경도 및 치수가 포함되어 있으며 거리 임계 값에 따라 레코드를 압축하고 모든 필터링 된 레코드의 위도 및 경도 좌표와 트랙을 형성합니다.
알고리즘 설명
이 알고리즘에는 광범위한 용도가 있습니다.
궤적 압축 알고리즘은 두 가지 범주, 즉 무손실 압축 및 손실 압축으로 나뉩니다. 무손실 압축 알고리즘에는 주로 허프만 코딩이 포함되며, 손실 압축 알고리즘은 배치 처리 방법과 온라인 데이터 압축 방법으로 나뉩니다. 배치 프로세싱 방법에는 DP (Douglas-Peucker) 알고리즘, TD-TR (하향식 시간 반격) 알고리즘 및 Bellman 알고리즘이 포함됩니다. 온라인 데이터 압축 방법에는 슬라이딩 창, 열린 창, 안전한 지역 기반 방법 등이 포함됩니다.
또한 이 기사를 참조 할 수 있습니다 .
코드 구현
import 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; import java.io.inputStreamReader; java.text.decimalformat; import java.util.arraylist; import java.util.iterator; import java.util.iterator; import javax.swing.jframe; import javax.swing.jpanel; public class tracjectorycom {public static void main [] args) 예외 {// threshold 정의 * // double maxdistanceerror =/ * *//// 위치 포인트 arraylist <enpoint> enplist = new ArrayList <enpoint> (); // 소스 데이터 파일의 주소의 파일 개체 작성 // 소스 파일의 스토리지 주소를 변경 해야하는 위치입니다. 주소에 "/", 다른 "/"를 추가하는 것을 기억하십시오. 이유 "/"는 탈출 기호입니다. // 이것은 c : /users/administrator/desktop/11.6/2007-10-14-gps.logfile sourcefile = 새 파일 ( "./ 2007-10-14-gps.log")로 작성할 수 있습니다. getenpointfromfile (sourcefile); // 이것은 목록에서 데이터를 읽었는지 여부를 테스트하고 목록의 데이터 수를 확인하는 것입니다. system.out.println (enplist.size ());/** 데이터 처리* 메소드 열기 창 트랙 압축 메소드 열기* //// 대상 포인트를 저장하는 세트 arraylist <enpoint> repointList = new ArrayList <NewPoint> (); repointList = repointList = OpenWindowtra (enplist, maxDistanceError); system.out.println (repointList.size ());/ * * 대상 파일에 씁니다 */file targetfile = 새 파일 ( "./ 2007-10-14-gpsresult.log"); writeTestPointTofile (TargetFile, RepointList);/ * * 소형 속도 계산 */double cpl = (double) repointList.size ()/(double) enplist.size () * 100; decimalformat df = new decimalformat ( "0.00000"); system.out.out.println ( "compression the the compertation :"); 거리 오류**/double avediserr = getMeanDisteror (enplist, repointlist); system.out.println (avediserr);/** 비교 차트를 형성하기위한 선을 그리기 위해 선을 그리십시오* /// generateImage (enplist, repointlist);}/** 제공된 파일 정보에서 추출물을 호출하여 각각의 포인트를 저장하기위한 전환 기능을 호출합니다. 포인트*/public static arraylist <enpoint> getenpointfoyfile (file fgps)은 예외를 {arraylist <enpoint> pgpsarray = new arraylist <enpoint> (); if (fgps.exists () && fgps.isfile () {inputstreamreader read = new inputstream기 (fiveInputStream); bufferedReader = new bufferedReader (read); // 캐시드 읽기 초기화 문자열 str; strgps [] strgps; int i = 0; (dftodu (strgps [3]); p.pn = (dftodu (strgps [5]); pgpsarray.add (p);} breader.close ();} 반환 pgpsarray;}/*** 기능 함수 : 원래 위도와 길이 좌표 데이터를도 얻어진 lattoduate*/problic extritude*/problic extritude*/problic extritude*/problic extritude*/**. str) {int indexd = str.indexof ( '.'); // get. 문자 문자열 strm = str.substring (0, indexd-2); // 정수 부품 문자열 strn = str.substring (indexd-2); // 십진 부품 double d = double.parsedouble (strm)+double.parsedouble (strn)/60; return d;}/** 열기 창*의 compress coorded* lists lists lists lists lists lists lists list of a compress 구현*. 알고리즘 설명 : * 초기 지점 및 부동 소수점은 투영 지점을 계산하고, 투영 지점과 궤적 지점과 임계 값 사이의 거리를 판단합니다. 거리가 임계 값*보다 크면 초기 포인트가 TargetList에 배치되고 부동 소수점은 새로운 초기 포인트로 앞으로 검색되며 새로운 초기 포인트는 새로운 플로팅 포인트로 두 번째로 뒤로 검색됩니다. 여기에는 새로운 초기 포인트 위치 +1이 목록 길이와 동일하는 판단이 있습니다. 이것은 부동 소수점*/public static arraylist <enpoint> openwindowtra (arraylist <enpoint> sourcernist, double maxdis) {arraylist <enpoint> targetlist = new arraylist <enpoint> (); // 초기 포인트 위치를 정의하는 초기 포인트 위치를 정의합니다. 2Int floatpoint = 2; // 현재 트랙 포인트 위치의 초기 포인트 위치를 1int nowpoint = 1; int len = sourcelist.size ()로 정의합니다. 모든 Windows arraylist <enpoint> listpoint = new arraylist <enpoint> (); listpoint.add (nowcelist.get)에 대한 지점을 결정하는지 () 창에서 트랙 포인트를 업데이트하려면 부울 플래그 = 거짓; // 창의 모든 지점과 투영 지점 사이의 거리가 (enpoint point : listpoint) {double disoftwo = getDistance (sourcercernist.get (startpoint), sourcelist.get (floatpoint), point; if (disoftwo> = 30) {flag = true; break;}} if (flag) {// 창의 점 거리가 임계 값보다 큽니다. // 초기 포인트는 대상 목록에 추가됩니다. 대상 목록에 추가됩니다. (sourcercernist.get (startpoint)); // 초기 점 변경 시작점 = floatpoint -1; // 플로팅 지점 변경 += 1; if (floatPoint> = len) {targetList.Add (sourcelist.get (floatPoint-1)); break;} // 창의 지점은 listpoint.clear (); // system.out.println (listpoint.size ()); listpoint.add (sourcelist.get (startpoint +1));} else {// 거리가 임계 값보다 작습니다. // 초기 포인트는 변경되지 않은 상태로 유지됩니다. // 현재 창 컬렉션은 현재 부동 소수점 ListPoint.add (sourcercernist.get (floatPoint))을 추가합니다. 임계 값, 창 포인트를 무시하고 (floatpoint> = len) {targetlist.add (startpoint (startpoint)); targetList.Add (sourcelist.get (floatPoint-1));}} flag = false;} return targetlist;}/* 트랙 포인트 사이의 거리를 계산합니다. 현재 트랙 포인트 C * 삼각형 영역 공식 */public static double getdistance (enpoint a, enpoint b, enpoint c) {double 거리 = 0; double a = math.abs (geodist (a, b)); double b = math.abs (b, c); double c = math.abs (a, c); Math.sqrt (p * (pb) * (pb) * (pc)); 거리 = s * 2.0/a; 반환 거리;}/ * * arraylist copy function * * // * 함수가 제공 한 기능 */// * 다음 거리 계산 방법을 얻기 위해 거리를 계산하기 위해 거리를 계산하는 기능 */public double geodist (Enpoint pa, enpoint pa) {Enpoint PA)를 연구하지 못했습니다. 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) * radlat2) - Math.sin (radlat1) *. math.cos (radlat2) * math.cos (delta_lon); double top = math.sqrt (top_1 * top_1 + top_2 * top_2); double bottom = math.sin (radlat1) * math.sin (radlat2) + math.cos (radlat1) * math.cos (radlat2) * math.cos (delta_); math.atan2 (상단, 하단); 이중 거리 = delta_sigma * 6378137.0; 반환 거리;} public static double rad (double d) {return d * math.pi/180.0;}/ * * 파일에 압축 된 위치 지점을 쓰기 */public static void writtestpointtofile (file outgpsfile, viraylist). 예외 {iterator <enpoint> ifilter = pgpspointfilter.iterator (); randomaccessfile rfilter = new randomaccessfile (outgpsfile, "rw"); sfilter.getBytes (); rfilter.write (bfilter);} rfilter.close ();}/*** 함수 함수 : 평균 거리 오차를 찾으십시오* 평균 거리를 반환*/public static double getmeandisteror (arraylist <enpoint> pgpsarray, arraylist> pgpsarrayre) {double sumdist = 0.0; i = 1; i <pgpsarrayre.size (); i ++) {double = ""end = "pgpsarrayre.get (i) .id;" int = ""J = "start+1; pre = ""return = ""start = "pgpsarrayre.get (i-1) .id;" sumdist = ""> <fre> import java.text.decimalformat; public class enpoint는 <enpoint> {public int id; // point idpublic double pe; // dimension public double pn; // dimension public enpoint () {} // 빈 생성자 공개 문자열 toString () {return this. getResultString () {DecimalFormat df = new DecimalFormat ( "0.000000"); reture this.id+"#"+df.format (this.pe)+","+df.format (this.pn)+" /n";}@overdide public int into (enpoint other) {if (this.id <elop.id) "" "" "" "" "" this.id = ""> Other.id) 반환 1; 그렇지 않으면 반환 0;}}요약
위는 Java 프로그래밍 구현 궤적 압축 알고리즘의 열린 창 인스턴스 코드에 대한이 기사의 전체 내용입니다. 모든 사람에게 도움이되기를 바랍니다. 단점이 있으면 메시지를 남겨 두십시오.