2016-04-25 95 views
1

我正在用JAVA編寫ESRI幾何壓縮算法,我用這個linkJAVA中的ESRI幾何壓縮算法

使用中提供的鏈接提到的指令,這是我的當前代碼:

public static void main(String[] args) { 
    String dirPoints = "-118.356654545455,34.1146;-118.356436363636,34.1143272727273;-118.356418181818,34.1142363636364;-118.356490909091,34.1137636363636"; 
    String compressedGeometry = ""; 
    double xPointPrev = 0.0; 
    double yPointPrev = 0.0; 
    int coefficient = 55000; 
    String coefficient_32 = Integer.toString(coefficient, 32); 
    compressedGeometry = coefficient_32 + compressedGeometry; 

    String[] path_XY = dirPoints.split(";"); 
    for (int i = 0, leni = path_XY.length; i < leni; i++) { 

     String[] xy = path_XY[i].split(","); 
     double pointX = Double.parseDouble(xy[0].trim()); 
     double pointY = Double.parseDouble(xy[1].trim()); 

     int xDifference = (int) Math.round(coefficient * (pointX - xPointPrev)); 
     int yDifference = (int) Math.round(coefficient * (pointY - yPointPrev)); 

     String xDifference_32 = Integer.toString(xDifference, 32); 
     compressedGeometry += xDifference_32; 

     String yDifference_32 = Integer.toString(yDifference, 32); 
     compressedGeometry += yDifference_32; 

     xPointPrev = pointX; 
     yPointPrev = pointY; 
    } 
    System.out.println(compressedGeometry); 
} 

預期輸出: 「+ 1lmo-66l1f + 1p8af + C-F + 1-5-4-Q」

但我得到這個:「1lmo-66l1g1p8afc-f1-5-4-q」

我錯過了什麼?任何幫助,高度讚賞。 謝謝,

回答

1

根據Integer.toString()

"If the first argument is not negative, no sign character appears in the result." 

所以我認爲你需要添加 「+」。

(我認爲f-g有他們的錯字)。

+0

謝謝,我的問題現在解決了。 –