Best practices for working with geometries in Tilebox.
[-180, 180]
and latitude values are within [-90, 90]
.Geometry
and Geography
data types. The primary distinction lies in how edge interpolation is handled along the antimeridian. Geometry
represents a shape in an arbitrary 2D Cartesian coordinate system and does not perform edge interpolation.
In contrast, Geography
typically wraps around the antimeridian by performing edge interpolation, such as converting Cartesian coordinates to a 3D spherical coordinate system. Typically, Geography types limit x
coordinates to [-180, 180]
and y
coordinates to [-90, 90]
, whereas Geometry
types have no such limitations.
Tilebox does not differentiate between Geometry
and Geography
types. Instead, it offers a query option to specify a coordinate reference system. This controls whether geometry intersections and containment checks are performed in a 3D spherical coordinate system (which correctly handles antimeridian crossings) or a standard 2D Cartesian lat/lon coordinate system.
Point
is a specific location on the Earth’s surface, represented by a longitude
and latitude
coordinate.
Ring
A Ring
is a collection of points that form a closed loop. The order of the points within the ring matter, since that defines the winding order of the ring, which is either clockwise or counter-clockwise.
Every ring should be explicitly closed, meaning that the first and last point should be the same.
Polygon
A Polygon
is a collection of rings. The first ring, the exterior ring
defines the polygon’s boundary. Any other rings are called interior rings
, representing holes within the polygon.
MultiPolygon
A MultiPolygon
is a collection of polygons.
Client SDK | Geometry library used by Tilebox |
---|---|
Python | Shapely |
Go | Orb |
Polygon
geometry, covering the area of the state of Colorado using Tilebox Client SDKs.
colorado.wkb
file containing a binary encoding of the Colorado polygon, it can be read as follows.
shapely
library supports this out of the box, and the orb
library for Go supports it as well via the github.com/paulmach/orb/encoding/ewkb
package.A linear ring MUST follow the right-hand rule with respect to the area it bounds, i.e., exterior rings are counterclockwise, and holes are clockwise.Thus, polygon exterior rings must have a counter-clockwise winding order, and interior rings must have a clockwise winding order. Failing to follow this rule can lead to unexpected query results, as shown below. Take the following
Polygon
consisting of the same exterior ring but in different winding orders.
Correct (counter-clockwise) winding order
Incorrect (clockwise) winding order
Polygon
with an exterior ring in clockwise winding order.
Instead, such geometries should be defined as a Polygon
consisting of two rings:
Polygon
that crosses the antimeridian.
A geometry that crosses the antimeridian
lon=173
to lon=-175
is interpreted as a 348-degree
line crossing the null meridian, spanning nearly the entire globe.
Visualizations of such geometries often appear as shown below.
Incorrect handling of a geometry crossing the antimeridian
[-180, 180]
bounds.
Expressing the geometry in such a way, may look like this.
-180
.
antimeridian
python package also is a great resource for learning more about possible antimeridian issues, how the cutting algorithm works and edge cases to be aware of.[-180, 180]
range, making it easier to work with themGeometry covering both poles (view of north pole)
Geometry covering both poles (view of south pole)
90
and -90
meridians.
For a circular cap covering the north pole, this results in four triangular parts, which can be combined into a MultiPolygon
. Visualization libraries and intersection/containment checks performed in cartesian coordinate space will typically handle such a geometry correctly.
A geometry covering the north pole