Skip to content

Spatial Data Retrieval API

Spatial values retrieved from the database are formatted per the GeoJSON specification.

sample-point-column.zoom70

When the data is retrieved from the database using the Object Retrieval API, columns of the spatial types are formatted as GeoJSON objects. Notice the structure of the location property in the response body below:

cURL  Request:

curl -X GET 'https://api.backendless.com/APP-ID/REST-API-KEY/data/Person/first'

Response body:

{  
  "created": 1573915664979,  
  "updated": 1575645151891,  
  "objectId": "5573DC95-79C7-1CDF-FF19-198DC95C4F00",  
  "ownerId": null,  
  "___class": "Person",  
  "location": {  
    "type": "Point",  
    "coordinates": [  
      -96.77016753,  
      32.82433675  
    ],  
    "srsId": 4326,  
    "___class": "com.backendless.persistence.Point"  
  }  
}

Where Clause Operators

A where clause is a condition used in the data retrieval API. The condition identifies the objects which should be retrieved from the database. There are several specialized where clause operators which work specifically with the columns of the spatial data types.

Within Operator

This operator retrieves all data objects whose values for the specified spatial type column are within the boundary of the specified geometry.

Syntax:

Within( spatialColumnName, 'Geometry as WKT' ) = Condition

where:

Argument                Description
spatialColumnName name of a spatial type column in the data table where the data objects are retrieved from; Returned objects have values in the spatialColumnName column which are within the geometry identified by 'Geometry as WKT'.
'Geometry as WKT' a WKT string (must be enclosed into single quotes) which designates the boundary of a shape where Backendless will search for values from the spatialColumnName column;
Condition True or False

Examples:

Retrieve all data objects where the geometries in the location column are within the specified polygon:

Within(location, 'POLYGON((-154.53617745476788 7.820063820687473, -154.53617745476788 51.13813853838118, -14.87797432976788 51.13813853838118, -14.87797432976788 7.820063820687473, -154.53617745476788 7.820063820687473))') = True

Assuming the location column contains POINT values, retrieve all data objects where the points in location are the same as the specified WKT point:

Within(location, POINT (-96.77016753 32.82433675)') = True

Contains Operator

This operator retrieves all data objects whose values for the specified spatial type column complete contain the specified geometry. This operator performs the retrieval in the opposite relationship as Within (see above).

Syntax:

Contains( spatialColumnName, 'Geometry as WKT' ) = Condition

where:

Argument                Description
spatialColumnName name of a spatial type column in the data table where the data objects are retrieved from; Returned objects have values in the spatialColumnName column which contain the geometry identified by 'Geometry as WKT'.
'Geometry as WKT' a WKT string (must be enclosed into single quotes) which designates the boundary of a shape which must be contained within the values from the spatialColumnName column;
Condition True or False

Examples:

Retrieve all data objects where the geometries in the visitedPlaces column contain the specified point:

Contains( visitedPlaces, 'POINT(36.643763, -116.396023)') = True

distanceOnSphere Operator

This operator returns the minimal spherical distance between the POINT values in the column (first argument) and the POINT value in the second argument. This operator can be used to effectively perform a search in radius. The operator returns the value in meters. Backendless identifies all objects whose values for the specified column match the condition.

Syntax:

// search in radius - calculates the distance between the value in the column (first argument) and the point in the second argument   
distanceOnSphere( spatialColumnName, 'POINT as WKT' )  

// calculate the distance between the point in spatialColumnNameFrom and the point in spatialColumnNameTo  
distanceOnSphere( spatialColumnNameFrom, spatialColumnNameTo )

where:

Argument                Description
spatialColumnName name of a column of type POINT. The return value is the distance in meters between the value in the spatialColumnName column and the point specified in the second argument
'POINT as WKT' a WKT string (must be enclosed into single quotes) which designates a POINT for which Backendless will calculate the distance on sphere. The distance is calculated between this point and the POINT values stored in spatialColumnName.
spatialColumnNameFrom name of a column of type POINT. The return value is the distance in meters between the value in this column and the value in the same object/record from the spatialColumnNameTo column.
spatialColumnNameTo name of a column of type POINT. The return value is the distance in meters between the value in this column and the value in the same object/record from the spatialColumnNameFrom column.

Examples:

Retrieve all data objects whose values in the location column are located within 1000 meters from a point with coordinates 33.077570 -96.823563:

distanceOnSphere(location, 'POINT(33.077570 -96.823563)') <= 1000

Retrieve all data objects where the distance between the values in the pickupLocation and the dropoffLocation columns is less than 1000 meters:

distanceOnSphere(pickupLocation, dropoffLocation) <= 1000

GetX

This operator returns the X coordinate (the longitude) for the POINT values stored in the specified column.

Syntax:

GetX( spatialColumnName ) op Value

where:

Argument                Description
spatialColumnName name of a column of type POINT. Returned objects have X/longitude values in the spatialColumnName column which satisfy the condition expressed via op Value.
op one of the following comparison operators:
> greater than
< less than
>= greater than or equals
<= less than or equals
= equals
!= not equals
Value a numeric value to compare the return value of the operator with.

Examples:

Retrieve all data objects whose longitude values in the location column are in the range between 41.92 and 44.66 (the continental United States):

GetX(location) > 41.92 && GetX(location) < 44.66

GetY

This operator returns the y coordinate (the latitude) for the POINT values stored in the specified column.

Syntax:

GetY( spatialColumnName ) op Value

where:

Argument                Description
spatialColumnName name of a column of type POINT. Returned objects have Y/latitude values in the spatialColumnName column which satisfy the condition expressed via op Value.
op one of the following comparison operators:
> greater than
< less than
>= greater than or equals
<= less than or equals
= equals
!= not equals
Value a numeric value to compare the return value of the operator with.

Examples:

Retrieve all data objects whose latitude values in the location column are in the range between -124.27 and -117.12 (the continental United States):

GetY(location) > -124.27 && GetY(location) < -117.12

AsWKT

This operator returns the WKT representation for the values stored in the specified column.

Syntax:

AsWKT( spatialColumnName ) op Value

where:

Argument                Description
spatialColumnName name of a column values of which will be used to obtain the WKT representation from.
op one of the following comparison operators:
= equals
!= not equals
Value a string value to compare the return value of the operator with.

Examples:

Retrieve all data objects which match the specified WKT representation

AsWKT( location ) = 'POINT( 41.92 -124.27 )'

AsGeoJSON

This operator returns the GeoJSON representation for the values stored in the specified column.

Syntax:

AsGeoJSON( spatialColumnName ) op Value

where:

Argument                Description
spatialColumnName name of a column values of which will be used to obtain the GeoJSON representation from.
op one of the following comparison operators:
= equals
!= not equals
Value a string value to compare the return value of the operator with.

Examples:

Retrieve all data objects which match the specified GeoJSON representation

AsGeoJSON( location ) = 'TBD'