I wrote a Spring-Application where I use the com.google.maps.GeocodingApi.GeocodingApi
to retreive coordinates for addresses. After that I use the method com.vividsolutions.jts.geom.GeometryFactory.createPoint()
to generate a Point I can store in my Oracle Database. I created the GeometryFactory like this: new GeometryFactory(new PrecisionModel(), 3857)
.
I built a spatial index on the coordinate column in the specific Table with the following code, so that I can run spatial Querys on it:
INSERT INTO USER_SDO_GEOM_METADATA(TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES('ADRESSE', 'KOORDINATE', SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', -180, 180, 0.05), SDO_DIM_ELEMENT('Y', -90, 90, 0.05)), 3857);
CREATE INDEX koords ON ADRESSE (KOORDINATE) INDEXTYPE IS MDSYS.SPATIAL_INDEX PARAMETERS ('layer_gtype=POINT sdo_max_memory=200000000');
When I just retreive the coordinates and present them on a Google Maps map, everything works as expected. The problem I have is, that the spatial querys I use to filter the data don't seem to work properly. I am using SDO_WITHIN_DISTANCE to get all coordinates that are inbound a 100 km radius from a coordinate I am using as a parameter. After that, I use SDO_GEOM.SDO_DISTANCE to calculate the distance between the coordinates in km. The resulting markers on the map are always in a spherical form instead of a circle and the calculated distances are also totally wrong. I tried many SRID's, but the calculations are always wrong. I suspect that I have to transform the coordinates or that I have to store them with a differnt SRID, so that the calculations made by the Oracle functions give me the expected results, but since now I couldn't make it work.
As Albert Godfrind mentioned in his comments, I was using the wrong SRID and additionally mixed up the latitude with longitude.