72112

how to Convert X and Y to lat and long

<h3>Question</h3>

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


<h3>Answer1:</h3>

You can get the lat and long by using the geotools library.

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(); } }
<h3>Answer2:</h3>

Please try the following methods to obtain data:

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

来源:https://stackoverflow.com/questions/61995654/how-to-convert-x-and-y-to-lat-and-long

Recommend

  • how to Convert X and Y to lat and long
  • how to Convert X and Y to lat and long
  • how to Convert X and Y to lat and long
  • How to process future stream to create an instance of class with list property
  • TypeScript type guard doesn't realize string union has been reduced
  • Difference between Canvas and Grid to Move, Resize, Rotate UIElements
  • Normalization does not preserve code point
  • how to unwrap a std::reference_wrapper like boost::unwrap_reference
  • WooCommerce Free Shipping - Remove raw or change the text name on checkout and email
  • YTPlayerView: Remove Share Button in top right corner
  • Circular animation not working on SVG
  • twitter bootstrap for high resolution mobile displays
  • UITextField get focus and then lose focus immediately due to return YES in textFieldShouldReturn
  • select multiple elements with group by in spark.sql
  • How to implement 'if' in Gherkin
  • Get frequency distribution of a decimal range in MySQL
  • Cannot retrieve CustomAttributes in Interceptor using DynamicProxy
  • Preventing duplicate slashes in file paths in R
  • Is this usage of the const keyword in line with its intention?
  • Human readable URL Scheme for ASP.NET MVC
  • Iterating over mmaped gzip file with boost
  • Wicket countdown timer will not self-update
  • Efficiently comparing generated code between two Git revisions of the source
  • Streaming huge json with Akka Stream
  • How to bend a cylinder in three.js?
  • query a json key in postgres json field
  • Github logged in user's public activities
  • Spring + Tiles2 - put-attribute from model?
  • Google Geocoding API limit exceeded on cell network, but not on wifi
  • Decimal to ASCII Conversion [closed]
  • Inet6Address valid for invalid IPv6 Address
  • plot dirac function in matlab
  • Corda: How to implement hierarchical relationships between state data persisted to H2
  • jQuery Ajax call to WCF service returning “Method not allowed (405)”
  • Please update your Node runtime to version >=0.12.x
  • Keep rows with certain values always at the bottom while sorting in jquery tablesorter plugin
  • Connect to a local database from phpmyadmin with R
  • Create an Office365 mailbox from within C# Web API method
  • Support of :after in IE7
  • How to use FirstOrDefault inside Include