Skip to content

Commit

Permalink
Update GeoJson section in reference documentation.
Browse files Browse the repository at this point in the history
Mention the relation of Point/GeoJsonPoint x/y coordinates to longitude/latitude.

Original Pull Request: #3956
  • Loading branch information
christophstrobl committed Feb 16, 2022
1 parent 2a3f746 commit 4f6501f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import org.springframework.data.geo.Point;

/**
* {@link GeoJson} representation of {@link Point}.
* {@link GeoJson} representation of {@link Point}. Uses {@link Point#getX()} as {@literal longitude} and
* {@link Point#getY()} as {@literal latitude}.
*
* @author Christoph Strobl
* @since 1.7
Expand All @@ -36,15 +37,17 @@ public class GeoJsonPoint extends Point implements GeoJson<List<Double>> {
/**
* Creates {@link GeoJsonPoint} for given coordinates.
*
* @param x : longitude
* @param y : latitude
* @param x longitude between {@literal -180} and {@literal 180} (inclusive).
* @param y latitude between {@literal -90} and {@literal 90} (inclusive).
*/
public GeoJsonPoint(double x, double y) {
super(x, y);
}

/**
* Creates {@link GeoJsonPoint} for given {@link Point}.
* <p>
* {@link Point#getX()} translates to {@literal longitude}, {@link Point#getY()} to {@literal latitude}.
*
* @param point must not be {@literal null}.
*/
Expand All @@ -57,6 +60,11 @@ public String getType() {
return TYPE;
}

/**
* Obtain the coordinates (x/longitude, y/latitude) array.
*
* @return the coordinates putting {@link #getX() x/longitude} first, and {@link #getY() y/latitude} second.
*/
@Override
public List<Double> getCoordinates() {
return Arrays.asList(Double.valueOf(getX()), Double.valueOf(getY()));
Expand Down
6 changes: 6 additions & 0 deletions src/main/asciidoc/reference/mongodb.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,12 @@ public class Store {
----
====

[TIP]
====
If the `coordinates` of a GeoJSON object represent _latitude_ and _longitude_ pairs, the _longitude_ goes first followed by _latitude_. +
`GeoJsonPoint` therefore treats `getX()` as _longitude_ and `getY()` as _latitude_.
====

[[mongo.geo-json.query-methods]]
==== GeoJSON Types in Repository Query Methods

Expand Down

0 comments on commit 4f6501f

Please sign in to comment.