I need Java equivalent of these Postgis functions: Basically it converts point with given radius to the polygon of radius shape, using buffer transformation.
NEW.geom = cast(st_buffer(cast(ST_SetSRID(ST_GeomFromText(NEW.geometry), 4326) AS GEOGRAPHY), 1000 * NEW.geometry_radius) AS GEOMETRY(Polygon, 4326));
I'm doing this operations, but the result is not the same. The radius in result is wrong, and distance projected on the map may vary depending on location on the Earth. My goal is, when I ask for 3 km radius, to get circle which is equivalent of 3 km radius projected in Google maps, OSM or other web mapping software .
But database code (PostGIS functions) mentioned above, does it correctly, as I want it.
This is my code in Kotlin using JTS transformations:
// create geometry explicitly in 4326
val reader = WKTReader(GeometryFactory(PrecisionModel(PrecisionModel.FLOATING), 4326))
val geom = reader.read(wkt)
// convert to projection in meters
val transformToMeters = CRS.findMathTransform(EPSG_4326, EPSG_3857, false)
val projectionMeters = JTS.transform(sourceGeometry, transformToMeters)
val poly = projectionMeters.buffer(radius*1000)
val transformToDeg = CRS.findMathTransform(EPSG_3857, EPSG_4326, false)
val resultGeometry = JTS.transform(poly, transform)