18.1.7. Create resource

Resource group

To create new group execute following request.

POST /api/resource/

Create resource group request.

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

  • cls (string) – type (must be resource_group, for a list of supported types see Resource classes)

  • parent (jsonobj) – parent resource json object

  • id (int) – parent resource identifier

  • display_name (string) – group name

  • keyname (string) – key (optional)

  • description (string) – description text, HTML supported (optional)

Status Codes

Example request:

POST /api/resource/ HTTP/1.1
Host: ngw_url
Accept: */*

 {"resource":
   {"cls":"resource_group",
    "parent":{"id":0},
    "display_name":"test",
    "keyname":"test_key",
    "description":"qqq"
   }
 }

Same steps with curl:

curl --user "administrator:demodemo" -H "Accept: */*" -X POST
-d '{"resource": {"cls": "resource_group", "display_name": "foldername", "parent": {"id": 0},
"description" : "Folder created from curl"} }' https://sandbox.nextgis.com/api/resource/

PostGIS Connection

To create PostGIS connection execute following request.

POST /api/resource/

PostGIS connection create request.

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

  • cls (string) – type (must be postgis_connection, for a list of supported types see Resource classes)

  • parent (jsonobj) – parent resource json object

  • id (int) – parent resource identifier

  • display_name (string) – name

  • keyname (string) – key (optional)

  • description (string) – description text, HTML supported (optional)

  • postgis_connection (jsonobj) – postgis connection JSON object

  • database (string) – Database name

  • hostname (string) – Database host

  • port (string) – Database port

  • password (string) – password

  • username (string) – login

Status Codes

Example request:

POST /api/resource/ HTTP/1.1
Host: ngw_url
Accept: */*

 {
   "postgis_connection": {
     "database": "postgis",
     "hostname": "localhost",
     "password": "secret",
     "username": "user"
   },
   "resource": {
     "cls": "postgis_connection",
     "description": "The localhost PostGIS Connection",
     "display_name": "localhost",
     "keyname": "localhost_key",
     "parent": {
       "id": 0
     }
   }
 }

PostGIS Layer

To create PostGIS layer execute following request.

POST /api/resource/

Create PostGIS layer request.

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

  • cls (string) – type (must be postgis_layer, for a list of supported types see Resource classes)

  • parent (jsonobj) – parent resource json object

  • id (int) – parent resource identifier

  • display_name (string) – name

  • keyname (string) – key (optional)

  • description (string) – description text, HTML supported (optional)

  • postgis_layer (jsonobj) – postgis layer JSON object

  • column_geom (string) – geometry column name (usually wkb_geometry)

  • column_id (string) – primary key column (usually ogc_fid)

  • connection (jsonobj) – PostGIS connection identifier (to create PostGIS connection see PostGIS Connection)

  • fields (string) – check to reread fields from database (must be update or not set)

  • geometry_type (string) – geometry type (if null, will read from database table). See ngwdev_geom_types

  • schema (string) – table schema

  • srs (jsonobj) – spatial reference JSON object

  • id – EPSG code

  • table (string) – table name

Status Codes

Example request:

POST /api/resource/ HTTP/1.1
Host: ngw_url
Accept: */*

 {
   "postgis_layer": {
     "column_geom": "wkb_geometry",
     "column_id": "ogc_fid",
     "connection": {
       "id": 31
     },
     "fields": "update",
     "geometry_type": null,
     "schema": "thematic",
     "srs": {
       "id": 3857
     },
     "table": "roads"
   },
   "resource": {
     "cls": "postgis_layer",
     "description": null,
     "display_name": "test",
     "keyname": null,
     "parent": {
       "id": 0
     }
   }
 }

Empty vector layer

To create empty vector layer execute following request:

POST /api/resource/

Create PostGIS layer request.

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

  • cls (string) – type (must be vector_layer, for a list of supported types see Resource classes)

  • parent (jsonobj) – parent resource json object

  • id (int) – parent resource identifier

  • display_name (string) – name

  • keyname (string) – key (optional)

  • description (string) – description text, HTML supported (optional)

  • vector_layer (jsonobj) – vector layer JSON object

  • fields (jsonarr) – array of json objects:

  • geometry_type (string) – geometry type. See ngwdev_geom_types

  • srs (jsonobj) – spatial reference json object

  • idEPSG code

Request JSON Array of Objects
  • keyname (string) – field name

  • datatype (string) – field type. See ngwdev_field_types

  • display_name (string) – field alias

Status Codes

Example request:

  POST /api/resource/ HTTP/1.1

  {
  "resource":{
      "cls":"vector_layer",
      "parent":{
          "id":0
      },
      "display_name":"Foo bar",
      "keyname":null,
      "description":null
  },
  "resmeta":{
      "items":{

      }
  },
  "vector_layer":{
      "srs":{ "id":3857 },
      "geometry_type": "POINT",
      "fields": [
          {
              "keyname": "REAL_FIELD",
              "datatype": "REAL"
          },
          {
              "keyname": "INTEGER_FIELD",
              "datatype": "INTEGER"
          },
          {
              "keyname": "DATE_FIELD",
              "datatype": "DATE"
          },
          {
              "keyname": "TIME_FIELD",
              "datatype": "TIME",
              "display_name": "TIME FIELD"
          }
      ]
  }
}

Same steps with curl:

curl -d „{ «resource»:{«cls»:»vector_layer», «parent»:{«id»:0}, «display_name»:»new»}, «vector_layer»:{«geometry_type»:»LINESTRING»,»srs»:{«id»:3857}, «fields»:[{«keyname»:»fieldname1»,»datatype»:»STRING»,»display_name»:»fld1»}]} }“ -u administrator:demodemo -X POST https://sandbox.nextgis.com/api/resource/

Vector layer with data

Vector layer creation from geodata source (Shapefile, GeoJSON) consists of following steps:

  1. Prepare vector geodata for layer

  2. Upload vector geodata

  3. Create vector layer

Preparing vector data

To prepare your data export it to ESRI Shapefile or GeoJSON format. Make sure there are no id field names. Layer must have spatial reference and UTF-8 or CP1251 encoding. Geometry must be valid and exist in all features, field names and values cannot include non-printable characters.

Uploading vector geodata

If geodata is in ESRI Shapefile format, all files must be packed into the one ZIP archive. GeoJSON file can be uploaded without archiving. Geodata uploading details see in File upload.

Create vector layer

To create vector layer execute following request:

POST /api/resource/

Create vector layer from uploaded file request.

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

  • cls (string) – type (must be vector_layer, for a list of supported types see Resource classes)

  • parent (jsonobj) – parent resource json object

  • id (int) – parent resource identifier

  • display_name (string) – name

  • keyname (string) – key (optional)

  • description (string) – description text, HTML supported (optional)

  • vector_layer (jsonobj) – vector layer JSON object

  • source (jsonobj) – JSON object with file upload response

  • srs (jsonobj) – spatial reference of creating vector layer. Only EPSG:3857 is supported

  • id – EPSG code

  • cast_geometry_type (string) – layer geometry type: POINT, LINESTRING or POLYGON. null for auto-detect (default)

  • cast_is_multi (bool) – is layer geometry multi. null for auto-detect (default)

  • cast_has_z (bool) – is layer geometry 3D. null for auto-detect (default)

  • skip_other_geometry_types (bool) – skip features with other geometry types, used if cast_geometry_type is specified (default: false)

  • fix_errors (string) – data errors fix level: NONE - do not fix (default), SAFE - without losing data, LOSSY - whatever possible

  • skip_errors (bool) – skip features with unfixable errors (default: false)

  • fid_source (bool) – feature ID source: SEQUENCE - ID is counted from 1 (default), FIELD - get ID from field (fid_field required), AUTO - get ID from field if fid_field is set, otherwise count from 1

  • fid_field (string) – field from which feature ID is taken (optional)

Status Codes

Example request:

POST /api/resource/ HTTP/1.1
Host: ngw_url
Accept: */*

 {
   "resource": {
     "cls": "vector_layer",
     "description": null,
     "display_name": "ggg www",
     "keyname": null,
     "parent": {
       "id": 0
     }
   },
   "vector_layer": {
     "source": {
       "encoding": "utf-8",
       "id": "2f906bf9-0947-45aa-b271-c711fef1d2fd",
       "mime_type": "application/zip",
       "name": "ngw1_1.zip",
       "size": 2299
     },
     "srs": {
       "id": 3857
     },
     "cast_geometry_type": "POLYGON",
     "cast_is_multi": true,
     "cast_has_z": false,
     "skip_other_geometry_types": true,
     "fix_errors": "LOSSY",
     "skip_errors": true,
     "fid_source": "AUTO",
     "fid_field": "ngw_id"
   }
 }

Same steps with curl:

$ curl -F file=@/tmp/bld.zip http://demo.nextgis.com/api/component/file_upload/

{"upload_meta": [{"id": "00cc4aa9-cca7-4160-b069-58070dff9399", "name": "bld.zip",
"mime_type": "application/octet-stream", "size": 62149}]}

$ curl --user "user:password" -H "Accept: */*" -X POST -d '{"resource":
{"cls": "vector_layer","description": "test curl create", "display_name": "buildings",
"keyname": null,"parent": {"id": 0}},"vector_layer": {"source": {"encoding": "utf-8",
"id": "00cc4aa9-cca7-4160-b069-58070dff9399","mime_type": "application/zip","name": "bld.zip",
"size": 62149},"srs": {"id": 3857}}}' http://demo.nextgis.com/api/resource/

{"id": 108, "parent": {"id": 0}}

Create vector layer in ogr2ogr:

$ ogr2ogr -f NGW -overwrite -t_srs EPSG:3857 -lco "KEY=data"
-lco "OVERWRITE=YES"  "NGW:https://sandbox.nextgis.com/resource/464/data"
PG:"dbname=gis" "data"

Ccreate vector layer with data group 464, layer will have name «data», keyname «data». Layer will take from local PostGIS database, table name is «data».

Feature in vector or PostGIS layer

To create new feature in vector layer execute following request:

POST /api/resource/(int: layer_id)/feature/?srs=(int: srs)

Create feature request

Parameters
  • layer_id – layer resource identifier

Query Parameters
  • srs – EPSG code for input SRS (will be automatically reprojected to destination SRS)

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)

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

Response JSON Object
  • id (int) – new feature identifier

Status Codes

Example request:

POST /api/resource/3/feature/ 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)"
}

For timestamp field input value must be divided on parts: day, month, day, hour, minute, second. In request payload add only set fields. Other fields will set to default values.

Example response body:

{"id": 25}

Add attachment to feature

Upload attachment as describe in File upload.

Add new attachment to feature in vector layer execute following request:

POST /api/resource/(int: layer_id)/feature/(int: feature_id)/attachment/

Add attachment request

Parameters
  • layer_id – layer resource identifier

  • feature_id – feature identifier

Request Headers
Request JSON Object
  • name (string) – file name

  • size (int) – attachment size from upload meta return after uploaded

  • mime_type (string) – attachment meta from upload meta return after uploaded

JSON Parameters
  • id (int) – upload file identifier from upload meta return after uploaded

Response JSON Object
  • id (int) – new attachment identifier

Status Codes

Example request:

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

{
  "name": "196.qml",
  "size": 1401,
  "mime_type":"application/octet-stream",
  "file_upload": {
    "id": "14158d93-3798-4f1f-ba18-f526e86e6e83",
    "size": 1401
  }
}

Example response body:

{"id": 7}

Batch create features in vector layer

To create multiple features in vector layer execute following request:

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

Payload is an array of feature definitions, like in POST request

Example of curl command to create empty vector layer:

$ curl --user "administrator:demodemo" -H "Accept: */*" -X POST
-d '{ "resource":{ "cls":"vector_layer", "parent":{ "id":0 },
"display_name":"Foo bar", "keyname":null, "description":null },
"resmeta":{ "items":{ } }, "vector_layer":{ "srs":{ "id":3857 },
"geometry_type": "POINT", "fields": [ { "keyname": "INTEGER_FIELD",
"datatype": "INTEGER" } ] } } ' http://dev.nextgis.com/sandbox/api/resource/

{"id": 994, "parent": {"id": 0}}

Example of curl command to upload two features in new vector layer:

$ curl --user "administrator:demodemo" -H "Accept: */*" -X PATCH
-d '[{"fields":{"INTEGER_FIELD":26},"geom":"POINT (15112666.6 6059666.6)"},
{"fields":{"INTEGER_FIELD": 27},"geom":"POINT (15112666.6 6059666.6)"}]'
http://dev.nextgis.com/sandbox/api/resource/994/feature/

Raster layer

Raster layer creation consists of following steps:

  1. Raster file prepare

  2. Upload raster

  3. Create raster layer

Preparing raster data

You can upload rasters in GeoTIFF format with 3 (RGB) or 4 (RGBA) bands. GeoTIFF file must have spatial reference, which can project to web map spatial reference (usually EPSG:3857). Value of bands color interpretation must be set. Compression (LZW, DEFLATE) can be used to decrease traffic. Pixel values must be between 0 to 255 (8 bit).

Loading raster

Prepared raster can be uploaded. See File upload.

Create raster layer

To create raster layer execute the following request:

POST /api/resource/

Create raster layer request.

Request Headers
Request JSON Object
  • cls (string) – type (must be raster_layer, for a list of supported types see Resource classes)

  • parent (jsonobj) – parent resource json object

  • id (int) – parent resource identifier

  • display_name (string) – name

  • keyname (string) – key (optional)

  • description (string) – description text, HTML supported (optional)

  • source (jsonobj) – JSON object with file upload response

  • srs (jsonobj) – spatial reference of creating vector layer. Should be the same as web map

  • id – EPSG code

Status Codes

Example request:

POST /api/resource/ HTTP/1.1
Host: ngw_url
Accept: */*

 {
   "resource": {
   "cls": "raster_layer",
   "display_name": "20150820_211250_1_0b0e",
   "parent": {"id": 101}
   },
   "raster_layer": {
     "source": {
       "id": "a2f381f9-8467-477c-87fa-3f71ecb749a5",
       "mime_type": "image/tiff",
       "size": 17549598
      },
     "srs": {"id": 3857}
   }
 }

Same steps with curl:

$ curl --user "user:password" --upload-file 'tmp/myfile.tif' http://demo.nextgis.com/api/component/file_upload/

{"id": "a2f381f9-8467-477c-87fa-3f71ecb749a5", "mime_type": "image/tiff", "size": 17549598}

$ curl --user "user:password" -H "Accept: */*" -X POST -d '{ "resource": {
"cls": "raster_layer", "display_name": "20150820_211250_1_0b0e", "parent": { "id": 101 } },
"raster_layer": { "source": {"id": "a2f381f9-8467-477c-87fa-3f71ecb749a5", "mime_type": "image/tiff",
"size": 17549598}, "srs": {"id": 3857} } }' http://demo.nextgis.com/api/resource/

{"id": 102, "parent": {"id": 101}}

File bucket

File bucket creation includes 2 steps:

  1. Upload files

  2. Execute POST request to create file bucket

File upload

Upload files to server. See File upload. Any file types are supported.

Create file bucket

To create file bucket execute following request:

POST /api/resource/

Create file bucket request.

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

  • cls (string) – type (must be file_bucket, for a list of supported types see Resource classes)

  • parent (jsonobj) – parent resource json object

  • id (int) – parent resource identifier

  • display_name (string) – name

  • keyname (string) – key (optional)

  • description (string) – description text, HTML supported (optional)

  • files (jsonobj) – Part of upload JSON response (files == upload_meta)

Status Codes

Example request:

POST /api/resource/ HTTP/1.1
Host: ngw_url
Accept: */*

 {
   "file_bucket": {
     "files": [
       {
         "id": "b5c02d94-e1d7-40cf-b9c7-79bc9cca429d",
         "mime_type": "application/octet-stream",
         "name": "grunt_area_2_multipolygon.cpg",
         "size": 5
       },
       {
         "id": "d8457f14-39cb-4f9d-bb00-452a381fa62e",
         "mime_type": "application/x-dbf",
         "name": "grunt_area_2_multipolygon.dbf",
         "size": 36607
       },
       {
         "id": "1b0754f8-079d-4675-9367-36531da247e1",
         "mime_type": "application/octet-stream",
         "name": "grunt_area_2_multipolygon.prj",
         "size": 138
       },
       {
         "id": "a34b5ab3-f3a5-4a60-835d-318e601d34df",
         "mime_type": "application/x-esri-shape",
         "name": "grunt_area_2_multipolygon.shp",
         "size": 65132
       },
       {
         "id": "fb439bfa-1a63-4384-957d-ae57bb5eb67b",
         "mime_type": "application/x-esri-shape",
         "name": "grunt_area_2_multipolygon.shx",
         "size": 1324
       }
     ]
   },
   "resource": {
     "cls": "file_bucket",
     "description": null,
     "display_name": "grunt_area",
     "keyname": null,
     "parent": {
       "id": 0
     }
   }
 }

Example response body:

{"id": 22, "parent": {"id": 0}}

Mapserver style

To create mapserver vector style execute following request:

POST /api/resource/

Create vector layer request.

Request Headers
Request JSON Object
  • mapserver_style (jsonobj) – Style json object.

  • xml (string) – MapServer xml style. Supported tags described in Теги языка картостилей Mapserver.

  • resource (jsonobj) – Resource json object.

  • cls (string) – type (must be mapserver_style, for a list of supported types see Resource classes)

  • parent (jsonobj) – parent resource json object

  • id (int) – parent resource identifier

  • display_name (string) – name

  • keyname (string) – key (optional)

  • description (string) – description text, HTML supported (optional)

Status Codes

Example request:

POST /api/resource/ HTTP/1.1
Host: ngw_url
Accept: */*

 {
   "mapserver_style" : {
     "xml" : "<map><layer><class><style><color blue=\"218\" green=\"186\" red=\"190\"/>
     <outlinecolor blue=\"64\" green=\"64\" red=\"64\"/></style></class></layer></map>"
   },
   "resource": {
     "cls": "mapserver_style",
     "description": null,
     "display_name": "grunt area style",
     "keyname": null,
     "parent": {
       "id": 0
     }
   }
 }

Example response body:

{"id": 24, "parent": {"id": 0}}

QGIS style

To create QGIS vector style for the layer do the following:

  1. Upload file with QGIS style to NGW. See File upload. Get id, mime_type and size from the reply.

  2. Create NGW resource via /api/resource/ as shown below:

POST /api/resource/ HTTP/1.1
Host: ngw_url
Accept: */*

 {
   "qgis_vector_style": {
      "file_upload": {
         "id": <id>,
         "mime_type": <mime type>,
         "size": <size>
      }
   },
   "res_meta": {
      "items": {
      }
   },
   "resource": {
     "cls": "qgis_vector_style",
     "description": null,
     "display_name": "My QGIS style",
     "keyname": null,
     "parent": {
       "id": <layer id>
     }
   }
 }

Raster style

To create raster style execute following request:

POST /api/resource/

Create raster layer request.

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

  • cls (string) – type (must be raster_style, for a list of supported types see Resource classes)

  • id (int) – parent resource identifier

  • display_name (string) – name

  • keyname (string) – key (optional)

  • description (string) – description text, HTML supported (optional)

Status Codes

Example request:

POST /api/resource/ HTTP/1.1
Host: ngw_url
Accept: */*

 {
   "resource": {
     "cls": "raster_style",
     "description": null,
     "display_name": "landsat style",
     "keyname": null,
     "parent": {
       "id": 0
     }
   }
 }

Example response body:

{"id": 25, "parent": {"id": 0}}

Lookup table

To create lookup table execute following request.

POST /api/resource/

Create lookup table request.

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

  • cls (string) – type (must be lookup_table, for a list of supported types see Resource classes)

  • id (int) – parent resource identifier

  • display_name (string) – name

  • keyname (string) – key (optional)

  • description (string) – description text, HTML supported (optional)

  • resmeta (jsonobj) – metadata JSON object. Key - value JSON object struct.

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

Status Codes

Example request:

POST /api/resource/ HTTP/1.1
Host: ngw_url
Accept: */*

 {
     "resource": {
         "cls": "lookup_table",
         "parent": {
             "id": 381
         },
         "display_name": "test_2",
         "keyname": null,
         "description": null
     },
     "resmeta": {
         "items": {}
     },
     "lookup_table": {
         "items": {
             "cat": "Машина"
         }
     }
 }

Example response body:

{"id": 25, "parent": {"id": 0}}

Same steps with curl:

$ curl --user "user:password" -H 'Accept: */*' -X POST -d '{"resource":{"cls":"lookup_table",
"parent":{"id":381},"display_name":"test_3","keyname":null,"description":null},"resmeta":
{"items":{}},"lookup_table":{"items":{"cat":"\u041c\u0430\u0448\u0438\u043d\u0430"}}}'
http://demo.nextgis.com/api/resource/

{"id": 385, "parent": {"id": 381}}

Web map

To create new web map execute following request.

POST /api/resource/

Example request:

POST /api/resource HTTP/1.1
Host: ngw_url
Accept: */*

{
"resource":{
   "display_name":"Test webmap",
   "parent":{
      "id":2317
   },
   "cls":"webmap"
},
"webmap":{
   "root_item":{
      "item_type":"root",
      "children":[
         {
            "layer_enabled":false,
            "layer_adapter":"tile",
            "display_name":"LT05_L1TP_124025_20010603_20161211_01",
            "layer_style_id":2284,
            "item_type":"layer"
         }
      ]
   }
}
}

Same steps with curl:

$ curl --user "login:password" -H "Accept: */*" -X POST
-d '{"resource": {"display_name": "cwm Вебкарта", "parent": {"id": 2317},
"cls": "webmap"}, "webmap": {"root_item": {"item_type": "root", "children":
[{"layer_enabled": false, "layer_adapter": "tile", "display_name": "LT05_L1TP_124025_20010603_20161211_01",
"layer_style_id": 2284, "item_type": "layer"}]}}}' http://demo.nextgis.com/api/resource/

WMS Service

To create new WMS service execute following request.

POST /api/resource/

Create WMS service request.

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

  • cls (string) – type (must be wmsserver_service, for a list of supported types see Resource classes)

  • id (int) – parent resource identifier

  • display_name (string) – name

  • keyname (string) – key (optional)

  • description (string) – description text, HTML supported (optional)

  • resmeta (jsonobj) – metadata JSON object. Key - value JSON object struct.

  • wmsserver_service (jsonobj) – JSON object with layers array (required).

  • layers (jsonarr) – array or WMS service layers. keyname, display_name and resource_id are mandatory.

Request JSON Array of Objects
  • keyname (string) – Key name for WMS service item. Name may be only ASCII symbols without spaces.

  • display_name (string) – Service item name.

  • resource_id (int) – Resource identifier which will be WMS layer datasource. Supported types are: vector layer style, raster style, WMS layer.

  • min_scale_denom (string) – Minimum scale to show WMS layer. String in form of «1 : 100000».

  • max_scale_denom (string) – Maximum scale to show WMS layer. String in form of «1 : 100000».

Status Codes

Example request:

POST /api/resource/ HTTP/1.1
Host: ngw_url
Accept: */*

{
 "resource": {
     "cls": "wmsserver_service",
     "parent": {
         "id": 0
     },
     "display_name": "Test WMS Service",
     "keyname": null,
     "description": null
 },
 "resmeta": {
     "items": {}
 },
 "wmsserver_service": {
     "layers": [
         {
             "keyname": "image1",
             "display_name": "Image #1",
             "resource_id": 127,
             "min_scale_denom": null,
             "max_scale_denom": null
         }
     ]
 }
}

Example response body:

{"id": 131, "parent": {"id": 0}}

Same steps with curl:

$ curl --user "login:password" -H "Accept: */*" -X POST
-d '{"resource":{"cls":"wmsserver_service","parent":{"id":0},
"display_name":"test1wms","keyname":null,"description":null},
"resmeta":{"items":{}},"wmsserver_service":{"layers":
[{"keyname":"test1","display_name":"test wms layer",
"resource_id":127,"min_scale_denom":null,"max_scale_denom":null}]}}'
http://demo.nextgis.com/api/resource/

{"id": 131, "parent": {"id": 0}}

WMS Connection

To create new WMS connection execute following request.

POST /api/resource/

Create WMS connection request.

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

  • cls (string) – type (must be wmsclient_connection, for a list of supported types see Resource classes)

  • id (int) – parent resource identificer

  • display_name (string) – name

  • keyname (string) – key (optional)

  • description (string) – description text, HTML supported (optional)

  • resmeta (jsonobj) – metadata JSON object. Key - value JSON object struct.

  • wmsclient_connection (jsonobj) – JSON object with connection properties (required).

  • url (string) – WMS service url.

  • username (string) – User name to connect to service.

  • password (string) – Password to connect to service.

  • version (string) – WMS version.

  • capcache (string) – If equal query - query capabilities from service.

Status Codes

Example request:

POST /api/resource/ HTTP/1.1
Host: ngw_url
Accept: */*

 {
     "resource": {
         "cls": "wmsclient_connection",
         "parent": {
             "id": 0
         },
         "display_name": "test connection",
         "keyname": null,
         "description": null
     },
     "resmeta": {
         "items": {}
     },
     "wmsclient_connection": {
         "url": "http://pkk5.rosreestr.ru/arcgis/services/Cadastre/CadastreWMS/MapServer/WMSServer",
         "username": null,
         "password": null,
         "version": "1.1.1",
         "capcache": "query"
     }
 }

Same steps with curl:

$ curl --user "login:password" -H "Accept: */*" -X POST
-d '{"resource":{"cls":"wmsclient_connection","parent":{"id":0},
"display_name":"test connection","keyname":null,"description":null},
"resmeta":{"items":{}},"wmsclient_connection":{"url":"http://pkk5.rosreestr.ru/arcgis/services/Cadastre/CadastreWMS/MapServer/WMSServer",
"username":null,"password":null,"version":"1.1.1","capcache":"query"}}'
http://demo.nextgis.com/api/resource/

{"id": 131, "parent": {"id": 0}}

WMS Layer

To create WMS layer from WMS connection execute following request.

POST /api/resource/

Create WMS layer request.

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

  • cls (string) – type (must be wmsclient_layer, for a list of supported types see Resource classes)

  • id (int) – parent resource identifier

  • display_name (string) – name

  • keyname (string) – key (optional)

  • description (string) – description text, HTML supported (optional)

  • resmeta (jsonobj) – metadata JSON object. Key - value JSON object struct.

  • wmsclient_layer (jsonobj) – JSON object with layer properties (required).

  • connection (jsonobj) – WMS connection.

  • imgformat (string) – Image format. Available values can fetched from WMS connection.

  • wmslayers (string) – String with layer identifiers separated with comma. Available layers can fetched from WMS connection.

  • vendor_params (jsonobj) – Additional parameters added to each request. This is key and value list.

Status Codes

Example request:

POST /api/resource/ HTTP/1.1
Host: ngw_url
Accept: */*

 {
     "resource": {
         "cls": "wmsclient_layer",
         "parent": {
             "id": 0
         },
         "display_name": "layer1",
         "keyname": null,
         "description": null
     },
     "resmeta": {
         "items": {}
     },
     "wmsclient_layer": {
         "connection": {
             "id": 18
         },
         "srs": {
             "id": 3857
         },
         "imgformat": "image/png",
         "wmslayers": "1,2",
         "vendor_params": {
            "key1": "value1"
         }
     }
 }

Same steps with curl:

$ curl --user "login:password" -H "Accept: */*" -X POST
-d '{"resource":{"cls":"wmsclient_layer","parent":{"id":0},
"display_name":"layer1","keyname":null,"description":null},
"resmeta":{"items":{}},"wmsclient_layer":{"connection":{"id":18},
"srs":{"id":3857},"imgformat":"image/png","wmslayers":"1,2"}}'
http://demo.nextgis.com/api/resource/

{"id": 131, "parent": {"id": 0}}

Tracker

To create tracker execute following request.

POST /api/resource/

Create tracker request.

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

  • cls (string) – type (must be tracker, for a list of supported types see Resource classes)

  • id (int) – parent resource identifier

  • display_name (string) – name

  • keyname (string) – key (optional)

  • description (string) – description text, HTML supported (optional)

  • resmeta (jsonobj) – metadata JSON object. Key - value JSON object struct.

  • tracker (jsonobj) – JSON object with tracker properties (required).

  • unique_id (string) – Tracker unique identifier (usually IMEA or GUID).

  • description – Tracker description.

  • device_type (string) – Only supported ng_mobile.

  • consumption_lpkm (float) – Fuel consumption per 100 kilometers.

Status Codes
POST /api/resource/ HTTP/1.1
Host: ngw_url
Accept: */*

 {
     "resource": {
         "cls": "wmsclient_layer",
         "parent": {
             "id": 0
         },
         "display_name": "layer1",
         "keyname": null,
         "description": null
     },
     "resmeta": {
         "items": {}
     },
     "tracker": {
         "unique_id": "test-001",
         "description": "test desc",
         "device_type": "ng_mobile",
         "consumption_lpkm": 5.0
    }
 }

Same steps with curl:

$ curl --user "login:password" -H "Accept: */*"
-d '{"resource":{"cls":"tracker","parent":{"id":4141},
"display_name":"test4","keyname":null,"description":null},
"tracker":{"is_registered":"","unique_id":"971f1-ffc-0f7073",
"description":"","device_type":"ng_mobile","consumption_lpkm":null},
"resmeta":{"items":{}}}' http://demo.nextgis.com/api/resource/

{"id": 4206, "parent": {"id": 4141}}