# Miscellaneous

## Get resource data

Geodatata can be fetched for vector and raster layers. For vector layers
(PostGIS and Vector) geodata returns in [GeoJSON](../../../glossary.html.md#term-GeoJSON) or [CSV](../../../glossary.html.md#term-CSV) formats.
For raster layers (Raster, [WMS](../../../glossary.html.md#term-WMS)) - tiles ([TMS](../../../glossary.html.md#term-TMS)) or image.
For QGIS styles - qml file.

### Export vector layer as file

**The following request returns GPKG, GeoJSON or CSV file from vector layer**:

### GET /api/resource/(*int:* id)/export?format=GPKG&srs=4326&zipped=True&fid=ngw_id&encoding=UTF-8

**Example request**: [https://sandbox.nextgis.com/api/resource/4308/export?format=GPKG&srs=4326&zipped=False&fid=ngw_id&encoding=UTF-8](https://sandbox.nextgis.com/api/resource/4308/export?format=GPKG&srs=4326&zipped=False&fid=ngw_id&encoding=UTF-8)

Format string is case-sensitive. For formats and options list see [https://docs.nextgis.ru/docs_ngcom/source/data_export.html](https://docs.nextgis.ru/docs_ngcom/source/data_export.html)

### GeoJSON

**The following request returns GeoJSON file from vector layer**:

#### Versionadded
Добавлено в версии 3.0.

### GET /api/resource/(*int:* id)/geojson

GeoJSON file request

* **Request Headers:**
  * [Accept](https://www.rfc-editor.org/info/rfc7231#section-5.3.2) – must be `*/*`
  * [Authorization](https://www.rfc-editor.org/info/rfc7235#section-4.2) – optional Basic auth string to authenticate
* **Parameters:**
  * **id** – resource identifier
* **Status Codes:**
  * [200 OK](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/200) – no error

**Example request**:

```http
GET /api/resource/55/geojson HTTP/1.1
Host: ngw_url
Accept: */*
```

### Render

**The following request returns TMS from raster layer**:

#### Versionadded
Добавлено в версии 3.0.

### GET /api/component/render/tile?z=(*int:* z)&x=(*int:* x)&y=(*int:* y)&resource=(*int:* id1),(*int:* id2)...

Tile request

* **Request Headers:**
  * [Accept](https://www.rfc-editor.org/info/rfc7231#section-5.3.2) – must be `*/*`
  * [Authorization](https://www.rfc-editor.org/info/rfc7235#section-4.2) – optional Basic auth string to authenticate
* **Query Parameters:**
  * **id2** (*id1,*) – style resources id’s
  * **z** – zoom level
  * **x** – tile number on x axis (horizontal)
  * **y** – tile number on y axis (vertical)
  * **cache** – optional parameter (defaults true). If value set false tile will render from scratch
  * **nd** – Return code if tile not present. Available values are: 204, 404, 200. Defaults to 200.
* **Status Codes:**
  * [200 OK](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/200) – no error
  * [204 No Content](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/204) – no tile
  * [404 Not Found](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/404) – no tile

**The following request returns image from raster layer**:

#### Versionadded
Добавлено в версии 3.0.

### GET /api/component/render/image?extent=(*float:* minx),(*float:* miny),(*float:* maxx),(*float:* maxy)&size=(*int:* width),(*int:* height)&resource=(*int:* id1),(*int:* id2)...

Image request

* **Request Headers:**
  * [Accept](https://www.rfc-editor.org/info/rfc7231#section-5.3.2) – must be `*/*`
  * [Authorization](https://www.rfc-editor.org/info/rfc7235#section-4.2) – optional Basic auth string to authenticate
* **Query Parameters:**
  * **id2** (*id1,*) – style resources id’s
  * **maxy** (*minx, miny, maxx,*) – image spatial extent
  * **height** (*width,*) – output image size
  * **cache** – optional parameter (defaults true). If value set false tile will render from scratch
* **Status Codes:**
  * [200 OK](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/200) – no error

#### NOTE
Styles order should be from lower to upper.

**Example request**:

```http
GET /api/component/render/tile?z=7&x=84&y=42&resource=234 HTTP/1.1
Host: ngw_url
Accept: */*
```

### QML Style (QGIS Layer style)

**The following request returns QML from QGIS style**:

#### Versionadded
Добавлено в версии 3.0.1.

### GET /api/resource/(*int:* id)/qml

QML file request

* **Request Headers:**
  * [Accept](https://www.rfc-editor.org/info/rfc7231#section-5.3.2) – must be `*/*`
  * [Authorization](https://www.rfc-editor.org/info/rfc7235#section-4.2) – optional Basic auth string to authenticate
* **Parameters:**
  * **id** – resource identifier
* **Status Codes:**
  * [200 OK](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/200) – no error

**Example request**:

```http
GET /api/resource/56/qml HTTP/1.1
Host: ngw_url
Accept: */*
```

### MVT (vector tiles)

MVT data can be fetched only for NextGIS Web vector layer.

**The following request returns MVT data**:

#### Versionadded
Добавлено в версии 3.0.4.

### GET /api/component/feature_layer/mvt?x=(*int:* x)&y=(*int:* y)&z=(*int:* z)&resource=(*int:* id1),(*int:* id2)...&simplification=(*int:* s)

Vector tile request

* **Request Headers:**
  * [Accept](https://www.rfc-editor.org/info/rfc7231#section-5.3.2) – must be `*/*`
  * [Authorization](https://www.rfc-editor.org/info/rfc7235#section-4.2) – optional Basic auth string to authenticate
* **Query Parameters:**
  * **id2** (*id1,*) – Vector or PostGIS layers identifies
  * **z** – zoom level
  * **x** – tile number on x axis (horizontal)
  * **y** – tile number on y axis (vertical)
  * **s** – simplification level (0 - no simplification, 8 - default value)
* **Status Codes:**
  * [200 OK](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/200) – no error

#### NOTE
Vector or PostGIS layers identifies order should be from lower to upper.

Layers names in MVT will be ngw:(int:id), where id is vector or PostGIS layer identifier.

**Example request**:

```http
GET /api/component/feature_layer/mvt?resource=56&z=11&x=1234&y=543 HTTP/1.1
Host: ngw_url
Accept: */*
```

#### Deprecated
Устарело, начиная с версии 3.0.4.

### GET /api/resource/(*int:* id)/(*int:* z)/(*int:* x)/(*int:* y).mvt

MVT request

* **Deprecated:**
* **Request Headers:**
  * [Accept](https://www.rfc-editor.org/info/rfc7231#section-5.3.2) – must be `*/*`
  * [Authorization](https://www.rfc-editor.org/info/rfc7235#section-4.2) – optional Basic auth string to authenticate
* **Parameters:**
  * **id** – resource identifier
  * **z** – zoom level
  * **x** – x tile column
  * **y** – y tile row
* **Status Codes:**
  * [200 OK](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/200) – no error

**Example request**:

```http
GET /api/resource/56/11/1234/543.mvt HTTP/1.1
Host: ngw_url
Accept: */*
```

## Identify by polygon

To get features intersected by a polygon execute following request.

### POST /api/feature_layer/identify

Identification request

* **Request Headers:**
  * [Accept](https://www.rfc-editor.org/info/rfc7231#section-5.3.2) – must be `*/*`
  * [Authorization](https://www.rfc-editor.org/info/rfc7235#section-4.2) – optional Basic auth string to authenticate
* **Response JSON Object:**
  * **srs** (*int*) – Spatial reference identifier
  * **geom** (*string*) – Polygon in WKT format
* **Response JSON Array of Objects:**
  * **layers** (*int*) – layers id array
* **Status Codes:**
  * [200 OK](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/200) – no error

**Example request**:

```http
POST /api/feature_layer/identify HTTP/1.1
Host: ngw_url
Accept: */*

{
    "srs":3857,
    "geom":"POLYGON((4188625.8318882 7511123.3382522,4188683.1596594 7511123.
                     3382522,4188683.1596594 7511180.6660234,4188625.8318882
                     7511180.6660234,4188625.8318882 7511123.3382522))",
    "layers":[2,5]
}
```

**Example response**:

```json
{
  "2": {
    "featureCount": 1,
    "features": [
      {
        "fields": {
          "Id": 25,
          "name": "Church 1514-1925"
        },
        "id": 3,
        "label": "#3",
        "layerId": 2
      }
    ]
  },
  "5": {
    "featureCount": 0,
    "features": []
  },
  "featureCount": 1
}
```
