我有一个名为IK_TEMP
的表,它包含名为data,range的列。
String sql = "SELECT DATA, RANGE FROM IK_TEMP";
try (Connection conn = this.connect();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql)){
// loop through the result set
while (rs.next()) {
System.out.println(rs.getString("DATA") + "\t" +
rs.getString("RANGE"));
fromBytes(rs.getBytes("RANGE"));
}
RANGE字段(二进制/ BLOB)字段已经使用来自arcGIS的二进制文件进行了编码,并保存在数据库中。http://www.geopackage.org/spec120/#gpb_format
我想使用Java解码此RANGE字段。
[Here I have tried with fromBytes方法
public void fromBytes(byte[] bytes) {
this.bytes = bytes;
ByteReader reader = new ByteReader(bytes);
// Get 2 bytes as the magic number and validate
String magic = null;
try {
magic = reader.readString(2);
} catch (UnsupportedEncodingException e) {
throw new GeoPackageException(
"Unexpected GeoPackage Geometry magic number character encoding: Expected: "
+ GeoPackageConstants.GEOMETRY_MAGIC_NUMBER);
}
if (!magic
.equals(GeoPackageConstants.GEOMETRY_MAGIC_NUMBER)) {
throw new GeoPackageException(
"Unexpected GeoPackage Geometry magic number: "
+ magic
+ ", Expected: "
+ GeoPackageConstants.GEOMETRY_MAGIC_NUMBER);
}
// Get a byte as the version and validate, value of 0 = version 1
byte version = reader.readByte();
if (version != GeoPackageConstants.GEOMETRY_VERSION_1) {
throw new GeoPackageException(
"Unexpected GeoPackage Geometry version: "
+ version
+ ", Expected: "
+ GeoPackageConstants.GEOMETRY_VERSION_1);
}
// Get a flags byte and then read the flag values
byte flags = reader.readByte();
int envelopeIndicator = readFlags(flags);
reader.setByteOrder(byteOrder);
// Read the 5th - 8th bytes as the srs id
srsId = reader.readInt();
// Read the envelope
envelope = readEnvelope(envelopeIndicator, reader);
// Save off where the WKB bytes start
wkbGeometryIndex = reader.getNextByte();
// Read the Well-Known Binary Geometry if not marked as empty
if (!empty) {
geometry = GeometryReader.readGeometry(reader);
}
}
但是问题是我在x
对象中获得了y
和geometry
,使用此x
和y
我无法获得经度和纬度。
请尝试以下方法获取数据:
Blob picture = resultSet.getBlob("RANGE");
inputStream = picture.getBinaryStream();
outputStream = new FileOutputStream("D:\\blob\\RANGE.jpg");
byte[] bufferBytes = new byte[1024];
int len = 0;
while ((len = inputStream.read(bufferBytes)) != -1) {
outputStream.write(bufferBytes, 0, len);
}