Previous Next JavaScript must be enabled to correctly display this content

## Lines and Coordinate System

As shown in the previous section, all kinds of geometries are specified in terms of a set of positions. However, for line strings and polygons, the actual geometrical shape is formed by the lines connecting their positions. The GeoJson specification defines a line between two points as the straight line that connects the points in the (flat) cartesian coordinate system whose horizontal and vertical axes are the longitude and latitude, respectively. More precisely, the coordinates of every point on a line that does not cross the antimeridian between a point P1 = (lon1, lat1) and P2 = (lon2, lat2) can be calculated as:

    P = (lon, lat) = (lon1 + (lon2 - lon1) * t, lat1 + (lat2 - lat1) * t)

with t being a real number greater than or equal to 0 and smaller than or equal to 1.

However, Oracle NoSQL Database uses a geodetic coordinate system (WGS 84) and as a result deviates from the GeoJson specification by using geodetic lines: A geodetic line between 2 points is the shortest line that can be drawn between the 2 points on the ellipsoidal surface of the earth. For a simplified, but more illustrative definition, assume for a moment that the earth surface is a sphere. Then, the geodetic line between two points on earth is the minor arc between the two points on the great circle corresponding to the points, i.e., the circle that is formed by the intersection of the sphere and the plane defined by the center of the earth and the two points.

The following figure shows the difference between the geodetic and straight lines between Los Angeles and London.

Figure 11-1 Geodetic vs Straight Line

Description of "Figure 11-1 Geodetic vs Straight Line"

(source: https://developers.arcgis.com)

The following figure shows the difference between the two coordinate systems for a square defined by points P1, P2, P3, and P4. The square is assumed to be in the northern hemisphere. The 2 vertical lines of the square are the same in both systems; points on each of these lines have the same longitude. This is not true for the "horizontal" lines. In the GeoJson system all points on the P1-P2 line (the blue line) have the same latitude (so this line is part of an earth parallel). But the geodetic line between P1 and P2 forms a curve (the red line) to the north of the GeoJson line. The difference between the two lines (the curvature) gets more pronounced closer to the poles and as the distance between P1 and P2 increases.

Figure 11-2 Geodetic vs GeoJson Box

Description of "Figure 11-2 Geodetic vs GeoJson Box"

When searching for points or other geometries inside the [P1, P2, P3, P4] polygon (using one of the functions described in the next section), Oracle NoSQL Database uses the geodetic view of the search polygon. So, for example, points that are between the blue and the red P1-P2 lines will not appear in the result. What if you really want to search inside the blue box? Such a search can be approximated by adding points between P1-P2 and P4-P3 in the definition of the search polygon. This is illustrated in the following figure, where we have added points P5 and P6. We can see that with the [P1, P6, P2, P3, P5, P4] polygon, the area difference between the geodetic and GeoJson boxes is smaller than with the [P1, P2, P3, P4] polygon.

Figure 11-3 Approximating a Search within a GeoJson Box

Description of "Figure 11-3 Approximating a Search within a GeoJson Box"