mysql的linestring、point从jdbc读入为byte[] 类型,下面的java代码实现逐次读取经纬度数据,返回double数组:
public static double[] bytestoPoints(byte[] arr){
if(arr==null){
return null;
}
if(arr.length==25){
return bytesToOnePoint(arr);
}
return bytesToMutiPoints(arr);
}
private static double bytes2Double(byte[] arr,int start) {
long value = 0;
for (int i = 0; i < 8; i++) {
value |= ((long) (arr[start+i] & 0xff)) << (8 * i);
}
return Double.longBitsToDouble(value);
}
private static double[] bytesToOnePoint(byt