如何将 X 和 Y 转换为纬度和经度

how to Convert X and Y to lat and long

我有一个名为 IK_TEMP 的 table,它包含名为数据、范围的列。

        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"));
            }

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);
            }

        }

我在 geometry 对象中得到 xy 坐标和几何类型,但是我怎样才能从这个

中得到纬度和经度

他们在 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 中进行相同的转换。 这是另一个例子

请尝试以下方法获取数据:

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);
}

您可以使用 geotools 库获取纬度和经度。

Coordinate coordinate = new Coordinate(geometry.getEnvelope().getMaxX(), geometry.getEnvelope().getMaxY());
            MathTransform transform;
            Coordinate targetGeometry;
            double latitude;
            double longitude;
            try {

            //sourceCRS is to convert the X and Y coordinates to lat long
            CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:25832");
            CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");

                transform = CRS.findMathTransform(sourceCRS, targetCRS, false);
                targetGeometry = JTS.transform(coordinate, coordinate, transform);
                latitude = targetGeometry.getX();
                longitude = targetGeometry.getY();
            } catch (FactoryException | TransformException e) {
                e.printStackTrace();
            }
        }