我有一个名为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.getBytes("RANGE"));
fromBytes(rs.getBytes("RANGE"));
}
已经使用arcGIS中的二进制文件对RANGE(二进制/ BLOB)字段进行了编码,并保存在数据库中。
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
的坐标和geometryType,但是如何从中获得经度和纬度
在其中一个示例中,他们使用了JS reff。
for item in (GeometryDataXYValue)!{
let xValue = item.paths?.ofX
let yValue = item.paths?.ofY
//recieve x y point
currentPoint = AGSPoint(x: xValue!, y: yValue!, spatialReference: AGSSpatialReference.webMercator())
//convert to lat long by AGSSpatialReference.wgs84()
if let aReference = AGSGeometryEngine.projectGeometry(currentPoint!, to: AGSSpatialReference.wgs84()) as? AGSPoint {
currentPoint = aReference
}
}
var long:Double = currentPoint!.x
var lat: Double = currentPoint!.y
print("value long lat = \(long , lat)")
}
但是我想要在Java中进行相同的转换。
这是另一个示例