13.1.5. Editing

Change resource

Execute following PUT request to change resource.

PUT /api/resource/(int: id)

Change resource request

Request Headers
Parameters
  • id – resource identifier

Request JSON Object
  • resource (jsonobj) – resource JSON object

Status Codes

Example request:

PUT /api/resource/8 HTTP/1.1
Host: ngw_url
Accept: */*

{"resource":
   {
       "display_name":"test3",
       "keyname":"qw4",
       "parent":{"id":7},
       "permissions":[],
       "description":"rrr5"
    }
}

Примечание

Payload of this request may be equal to create new resource request payload, but some fields can be omitted. Request must be authorized.

Move resource in terminal:

url='https://sandbox.nextgis.com'
login='administrator'
password='demodemo'

curl -d '{"resource":{"parent":{"id":373}}}' -u $login:$password -X PUT $url/api/resource/381

Change metadata

This query create metadata fields, or updating it if they exists.

Example request:

PUT /api/resource/8 HTTP/1.1
Host: ngw_url
Accept: */*

{
   "resmeta":{
      "items":{
         "UPDATED_AT":"2018-11-07 14:00",
         "CHECKED_AT":"2018-11-07 12:00"
      }
   }
}

Same steps with curl:
curl --user "user:password" -H 'Accept: */*' -X PUT -d '{"resmeta": {"items":{"UPDATED_AT":"2018-11-07 14:00", "CHECKED_AT":"2018-11-07 12:00"}}}' http://<ngw url>/api/resource/(int:id)

Change file bucket resource

To change file bucket execute following PUT request:

PUT /api/resource/(int: id)

Change file bucket request.

Request Headers
Parameters
  • id – resource identifier

Request JSON Object
  • resource (jsonobj) – resource JSON object

  • file_bucket (jsonobj) – file bucket JSON object

Status Codes

Example request:

PUT /api/resource/22 HTTP/1.1
Host: ngw_url
Accept: */*

 {
   "file_bucket": {
     "files": [
       {
         "mime_type": "application/x-dbf",
         "name": "grunt_area_2_multipolygon.dbf",
         "size": 36607
       },
       {
         "mime_type": "application/x-esri-shape",
         "name": "grunt_area_2_multipolygon.shp",
         "size": 65132
       },
       {
         "mime_type": "application/x-esri-shape",
         "name": "grunt_area_2_multipolygon.shx",
         "size": 1324
       },
       {
         "id": "fb439bfa-1a63-cccc-957d-ae57bb5eb67b",
         "mime_type": "application/octet-stream",
         "name": "grunt area description.txt",
         "size": 50
       }
     ]
   },
   "resource": {
     "cls": "file_bucket",
     "description": "some new text",
     "display_name": "new grunt_area",
     "keyname": null,
     "parent": {
       "id": 0
     }
   }
 }

In this example, file grunt area description.txt will added, files grunt_area_2_multipolygon.cpg, grunt_area_2_multipolygon.prj - deleted, and bucket name and description will changed.

Change lookup table resource

To change flookup table execute following PUT request:

PUT /api/resource/(int: id)

Change lookup table request.

Request Headers
Parameters
  • id – resource identifier

Request JSON Object
  • resource (jsonobj) – resource JSON object

  • lookup_table (jsonobj) – lookup table values JSON object. Key - value JSON object struct.

Status Codes

Example request:

PUT /api/resource/22 HTTP/1.1
Host: ngw_url
Accept: */*

{
  "lookup_table": {
     "items": {
         "car": "Машина",
         "plane": "Самолет"
     }
  }
}

Same steps with curl:

$ curl --user "user:password" -H 'Accept: */*' -X PUT -d '{"lookup_table":
{"items":{"car":"Машина", "plane":"Самолет"}}}'
http://<ngw url>/api/resource/

Change feature

To change feature in vector layer execute following request:

PUT /api/resource/(int: layer_id)/feature/(int: feature_id)

Change feature request

Parameters
  • layer_id – layer resource identifier

  • feature_id – feature identifier

Request Headers
Request JSON Object
  • geom (string) – geometry in WKT format (geometry type and spatial reference must be corespondent to layer geometry type and spatial reference)

  • id (int) – feature identifier

Request JSON Array of Objects
  • fields – attributes array in form of JSON field name - value object

Status Codes

Example request:

PUT /api/resource/3/feature/1 HTTP/1.1
Host: ngw_url
Accept: */*

{
  "extensions": {
    "attachment": null,
    "description": null
  },
  "fields": {
    "Age": 1,
    "DateTr": {
      "day": 7,
      "month": 2,
      "year": 2015
    },
    "Davnost": 4,
    "Foto": 26,
    "Nomerp": 1,
    "Nomers": 1,
    "Samka": 0,
    "Sex": 3,
    "Sizeb": 0.0,
    "Sizef": 0.0,
    "Sizes": 9.19999980926514,
    "Snowdepth": 31,
    "Wher": "\u043b\u044b\u0436\u043d\u044f",
    "id01": 0
  },
  "geom": "MULTIPOINT (15112317.9207317382097244 6059092.3103669174015522)",
  "id": 1
}

In request payload add only changed fields. Other fields will stay unchanged. Also geometry field may be skipped.

To change features in batch mode use patch request.

PATCH /api/resource/(int: layer_id)/feature

Change features request

Parameters
  • layer_id – layer resource identifier

Request Headers
Request JSON Array of Objects
  • geom (string) – geometry in WKT format (geometry type and spatial reference must be corespondent to layer geometry type and spatial reference)

  • fields (jsonarr) – attributes array in form of JSON field name - value object

  • id (int) – feature identifier

Status Codes

Request accepts array of JSON objects. If feature identifier is not present in PATCH body a feature will be created, else - changed.

Example request:

PATCH /api/resource/3/feature/ HTTP/1.1
Host: ngw_url
Accept: */*

[
  {"geom": "POINT(30.20 10.15)", "fields": {"externalObjectId": "i1"}},
  {"id": 24, "geom": "POINT(30.20 10.15)", "fields": {"externalObjectId": "i2"}},
  {"geom": "POINT(30.20 10.15)", "fields": {"externalObjectId": "i3"}}
]

Example response body:

[
  {"id": 25},
  {"id": 24},
  {"id": 26}
]

Delete feature

To delete feature from vector layer execute following request:

DELETE /api/resource/(int: layer_id)/feature/(int: feature_id)

Delete feature request

Request Headers
Parameters
  • layer_id – resource identifier

  • feature_id – feature identifier

Status Codes

Example request:

DELETE /api/resource/3/feature/1 HTTP/1.1
Host: ngw_url
Accept: */*

Delete all features

To delete all feature in vector layer execute following request:

DELETE /api/resource/(int: layer_id)/feature/

Delete features request

Request Headers
Parameters
  • layer_id – resource identifier

Status Codes

Example request:

DELETE /api/resource/3/feature/ HTTP/1.1
Host: ngw_url
Accept: */*