In the end, I decided to get the coordinates from Postgres using the ST_AsText () method, instead of extracting them from some kind of geography object in Java. Then I just parsed the polygon string in Java.
The PostgreSQL statement that I executed looks like this:
SELECT id, name, ST_AsText(area) FROM area_table;
In Java, I retrieve a string from a ResultSet after executing my JDBC request:
String area = rs.getString("ST_AsText");
And I get something similar to this:
"POLYGON((-49 52,123 52,123 -4,-49 -4,-49 52))"
Then I just analyzed the points from this.
double[] bounds = new double[8]; int k = 0; for (int i = 0; i < points.length; i++) { String[] lonLat = points[i].split(" "); for (int j = 0; j < lonLat.length; j++) { bounds[k++] = Double.parseDouble(lonLat[j]); } }
I don't know if this is the best way to do this, but it is the best way that I could figure out on my own.
source share