Skip to content

Commit

Permalink
Apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cbullinger committed Jul 28, 2023
1 parent 24326dc commit c45e2a7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ class Geospatial : RealmTest() {
)
// :snippet-end:
// :snippet-start: geobox
val box1 = GeoBox.Companion.create(
val box1 = GeoBox.create(
bottomLeft = GeoPoint.create(47.3, -122.7),
topRight = GeoPoint.create(48.1, -122.1)
)
val box2 = GeoBox.Companion.create(
val box2 = GeoBox.create(
bottomLeft = GeoPoint.create(47.5, -122.4),
topRight = GeoPoint.create(47.9, -121.8)
)
Expand Down Expand Up @@ -150,11 +150,6 @@ class Geospatial : RealmTest() {
val polygonWithTwoHoles = GeoPolygon.create(outerRing, hole1, hole2)
// :snippet-end:

// :snippet-start: geopoint-query
var geopointQuery =
realm.query<Company>("location GEOWITHIN $circle1").find()
// :snippet-end:

// :snippet-start: geocircle-query
val companiesInLargeCircle =
realm.query<Company>("location GEOWITHIN $circle1").find()
Expand Down
4 changes: 2 additions & 2 deletions source/examples/generated/kotlin/Geospatial.snippet.geobox.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
val box1 = GeoBox.Companion.create(
val box1 = GeoBox.create(
bottomLeft = GeoPoint.create(47.3, -122.7),
topRight = GeoPoint.create(48.1, -122.1)
)
val box2 = GeoBox.Companion.create(
val box2 = GeoBox.create(
bottomLeft = GeoPoint.create(47.5, -122.4),
topRight = GeoPoint.create(47.9, -121.8)
)

This file was deleted.

35 changes: 19 additions & 16 deletions source/sdk/kotlin/realm-database/schemas/data-types/geospatials.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Geospatial Data Types - Kotlin SDK
:depth: 2
:class: singlecol

.. versionadded:: v1.11.0

Kotlin version 1.11.0 and later adds support for experimental geospatial APIs.

Geospatial data, or "geodata", specifies points and geometric objects on the Earth's
surface. With the geodata types, you can create queries that check whether a given
point is contained within a shape. For example, you can find all coffee shops within
Expand All @@ -18,28 +22,29 @@ point is contained within a shape. For example, you can find all coffee shops wi
Geospatial Data Types
---------------------

The Kotlin SDK supports the following geospatial data types:
The Kotlin SDK supports geospatial queries using the following data types:

- GeoPoint
- GeoCircle
- GeoBox
- GeoPolygon

.. note::

Currently, geospatial data types cannot be persisted. For example, you can't
declare a property that is of type ``GeoBox``.

These types can only be used as arguments for geospatial queries.

.. _kotlin-geopoint:

GeoPoint
~~~~~~~~

A `GeoPoint <{+kotlin-local-prefix+}reference/Realms.GeoPoint.html>`__ defines a specific
location on the Earth's surface. All of the geospatial data types use ``GeoPoints``
to define their location.

.. note::

In methods that take a ``GeoPoint``, you can alternatively provide a tuple of
doubles, where the first double is the latitude and the second double is the
longitude. The SDK interprets these tuples as ``GeoPoints``. The examples on
this page demonstrate both approaches.

.. _kotlin-geocircle:

GeoCircle
Expand All @@ -53,7 +58,7 @@ object to specify the radius of the circle.

You can define the radius in kilometers, miles, degrees, or radians.

The following code shows two examples of creating a circle:
The following example creates 2 circles:

.. literalinclude:: /examples/generated/kotlin/Geospatial.snippet.geocircle.kt
:language: kotlin
Expand Down Expand Up @@ -97,8 +102,10 @@ Because a polygon is a closed shape, you must provide a minimum of 4 points:

The fourth point in a polygon *must* be the same as the first point.

You can also exclude areas within a polygon by defining one or more "holes". A
hole is another polygon whose bounds fit completely within the outer polygon.
You can also exclude areas within a polygon by defining one or more "holes".
A hole is another polygon whose bounds fit completely within the outer polygon.
Holes can also be nested within each other. A location is considered inside the
polygon if it is included in an odd number of rings.

The following example creates 3 polygons:

Expand Down Expand Up @@ -170,6 +177,7 @@ The following image shows the results of creating these two ``Company`` objects:

Querying Geospatial Data
------------------------

To query against geospatial data, you can use the ``GEOWITHIN`` operator with
:ref:`RQL <realm-query-language>`. This method takes the ``coordinates``
property of an embedded object and checks if that point is contained within
Expand All @@ -185,11 +193,6 @@ the geodata region.
Examples
~~~~~~~~

The following example shows how to query for geospatial data:

.. literalinclude:: /examples/generated/kotlin/Geospatial.snippet.geopoint-query.kt
:language: kotlin

The following examples show querying against various shapes to return a list of
companies within the shape:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ Realm supports the following field data types:
- ``BacklinksDelegate<T>``, a `backlinks <{+kotlin-local-prefix+}io.realm.kotlin.ext/backlinks.html>`__
delegate used to define an inverse relationship between
`RealmObjects <{+kotlin-local-prefix+}io.realm.kotlin.types/-realm-object/index.html>`__.
- The following :ref:`geospatial types <kotlin-geospatial>`:

- ``GeoPoint``
- ``GeoCircle``
- ``GeoBox``
- ``GeoPolygon``

Realm stores all non-decimal numeric types as ``Long`` values.
Similarly, Realm stores all decimal numeric types as ``Double``
Expand Down

0 comments on commit c45e2a7

Please sign in to comment.