问题
I have a table called IK_TEMP
and it contains columns called 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"));
}
The RANGE field(binary / BLOB) field is already encoded using binary from arcGIS and saved in the Database.
http://www.geopackage.org/spec120/#gpb_format
I want to decode this RANGE field using java.
Here I have tried with fromBytes method
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);
}
}
I am getting x
and y
coordinates and geometryType in geometry
object, But how can I get lat and long from this
In one of the example they have given in 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)")
}
But I want the same conversion in java.
This is another example
example
来源:https://stackoverflow.com/questions/62036982/formula-to-convert-x-and-y-coordinates-to-lat-and-long