Skip to content

Spatial Data Create/Update API

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

POINT Values

Consider the following table schema in Backendless database. Notice the pickupLocation and the dropoffLocation columns. Both are of type POINT:

sample-schema-geo

The following code demonstrates how to create a new object with POINT properties in the Order table:

Notice the formatting of the dropoffLocation and the pickupLocation properties - they follow the structure of the Point GeoJSON  geometry.

**Request method: **

POST

Request header:

Content-Type:application/json

Request body:

{  
  "orderName": "Fun times",  
  "dropoffLocation": {  
    "type": "Point",  
    "coordinates": [ 37.6189, 55.752917 ]  
  },  
  "pickupLocation": {  
    "type": "Point",  
    "coordinates": [ 37.578639, 55.782309 ]  
  }  
}

cURL request:

Important

Make sure to replace xxxx in the domain name in the sample request below to the one assigned to your application.

curl \  
-H Content-Type:application/json \  
-X POST  \  
-d "{ \  
  "orderName": "Fun times", \  
  "dropoffLocation": { \  
    "type": "Point", \  
    "coordinates": [ 37.6189, 55.752917 ] \  
  }, \  
  "pickupLocation": { \  
    "type": "Point", \  
    "coordinates": [ 37.578639, 55.782309 ] \  
  } \  
}" \  
-v https://xxxx.backendless.app/api/data/Order

Codeless Reference

The example below creates a new object containing two GeoJSON (Point) objects and saves it to the database called Order:

data_spatial_createupdate_1

where:

Argument                Description
table name Name of the data table where a new record must be saved.
object An object to save in the database. Object properties must match the names of the table columns. The object must not have the objectId property.
return result Optional parameter. When this box is checked, the operation returns the saved object with the objectId property.

When you run the code(or Codeless logic), you will see the following in the database:

sample-geo-create-map

LINESTRING Values

Creating objects with LINESTRING properties works similarly to the example shown above - request must use the GeoJSON format to describe a linestring value. For example, the code below creates an object in the Travel table with a LINESTRING route:

Notice the formatting of the route property - it follows the structure of the LineString GeoJSON  geometry.

**Request method: **

POST

Request header:

Content-Type:application/json

Request body:

{  
  "name": "Route 66",  
  "route": {  
    "type": "LineString",  
    "coordinates": [  
      [ -90.13875858, 38.68967135 ],  
      [ -95.93953983, 36.2131248 ],  
      [ -97.49959842, 35.53656483 ],  
      [ -101.8282117, 35.26791494 ],  
      [ -105.87118045, 35.72083154 ],  
      [ -106.61825076, 35.14794417 ],  
      [ -111.63900272, 35.20182535 ],  
      [ -118.24178592, 34.07195769 ]  
    ]  
  }  
}

cURL request:

Important

Make sure to replace xxxx in the domain name in the sample request below to the one assigned to your application.

curl \  
-H Content-Type:application/json \  
-X POST  \  
-d "{ \  
  "name": "Route 66", \  
  "route": { \  
    "type": "LineString", \  
    "coordinates": [ \  
      [ -90.13875858, 38.68967135 ], \  
      [ -95.93953983, 36.2131248 ], \  
      [ -97.49959842, 35.53656483 ], \  
      [ -101.8282117, 35.26791494 ], \  
      [ -105.87118045, 35.72083154 ], \  
      [ -106.61825076, 35.14794417 ], \  
      [ -111.63900272, 35.20182535 ], \  
      [ -118.24178592, 34.07195769 ] \  
    ] \  
  } \  
}" \  
-v https://xxxx.backendless.app/api/data/Travel

Codeless Reference

The example below creates a new object containing one GeoJSON (LineString) object and saves it to the database called Travel:

data_spatial_createupdate_2

where:

Argument                Description
table name Name of the data table where a new record must be saved.
object An object to save in the database. Object properties must match the names of the table columns. The object must not have the objectId property.
return result Optional parameter. When this box is checked, the operation returns the saved object with the objectId property.

When you run the code(or Codeless Logic), you will see the following object in the database:

sample-linestring

POLYGON Values

Creating objects with properties of type POLYGON can be done by using the corresponding GeoJSON format. Consider the following example, it is a data table called Building with a schema which includes a column named shape of type POLYGON:

building-table-schema

The code below demonstrates how to create a new object with a POLYGON property in the database:

Notice the formatting of the shape property - it follows the structure of the Polygon GeoJSON

**Request method: **

POST

Request header:

Content-Type:application/json

Request body:

{  
  "name": "Pentagon",  
  "shape": {  
    "type": "Polygon",  
    "coordinates": [  
      [  
        [ -77.05786152, 38.87261877 ],  
        [ -77.0546978, 38.87296123 ],  
        [ -77.05317431, 38.87061405 ],  
        [ -77.0555883, 38.86882611 ],  
        [ -77.05847435, 38.87002898 ],  
        [ -77.05786152, 38.87261877 ]  
      ],  
      [  
        [ -77.05579215, 38.87026286 ],  
        [ -77.05491238, 38.87087264 ],  
        [ -77.05544882, 38.87170794 ],  
        [ -77.05669337, 38.87156594 ],  
        [ -77.05684357, 38.87072228 ],  
        [ -77.05579215, 38.87026286 ]  
      ]  
    ]   
  }  
}

cURL request:

Important

Make sure to replace xxxx in the domain name in the sample request below to the one assigned to your application.

curl \  
-H Content-Type:application/json \  
-X POST  \  
-d "{ \  
  "name": "Pentagon", \  
  "shape": { \  
    "type": "Polygon", \  
    "coordinates": [ \  
      [ \  
        [ -77.05786152, 38.87261877 ], \  
        [ -77.0546978, 38.87296123 ], \  
        [ -77.05317431, 38.87061405 ], \  
        [ -77.0555883, 38.86882611 ], \  
        [ -77.05847435, 38.87002898 ], \  
        [ -77.05786152, 38.87261877 ] \  
      ], \  
      [ \  
        [ -77.05579215, 38.87026286 ], \  
        [ -77.05491238, 38.87087264 ], \  
        [ -77.05544882, 38.87170794 ], \  
        [ -77.05669337, 38.87156594 ], \  
        [ -77.05684357, 38.87072228 ], \  
        [ -77.05579215, 38.87026286 ] \  
      ] \  
    ] \  
  } \  
}" \  
-v https://xxxx.backendless.app/api/data/Building

Codeless Reference

The example below creates a new object containing one GeoJSON (Polygon) object and saves it to the database called geolocation:

data_spatial_types_13

where:

Argument                Description
table name Name of the data table where a new record must be saved.
object An object to save in the database. Object properties must match the names of the table columns. The object must not have the objectId property.
return result Optional parameter. When this box is checked, the operation returns the saved object with the objectId property.

After running the code(or Codeless Logic), you will see the following object in the database:

data_spatial_types_14