2.5. Adding resources

Layer is one of the main components of NextGIS Web software. Layer is a raster image or a vector file (table from database). To join layers on a map you need to set a style (or style set) to display a layer.

Styles may be set only for vector layers.

Interface for adding of PostGIS layers, vector and raster layers is practically the same. Firstly you provide layer parameters and then add a style.

2.5.1. Raster layer

To add a raster layer navigate to a group where you want to create it. In Actions pane click Create resource ‣ Raster layer. Create resource dialog for raster layer layer will open and look like Pic. 2.11..

../../_images/admin_layers_create_raster_layer_resourse_description.png

Pic. 2.11. Create resource dialog for raster layer.

Enter display name that will be visible in administrator interface and in map layer tree. Fields Keyname and Description are not required.

Switch from Resource tab to Raster layer tab. Raster layer tab is presented on Pic. 2.12..

../../_images/admin_layers_create_raster_layer_upload.png

Pic. 2.12. Raster layer tab with button for upload of raster file.

Then you need to specify a coordinate system the raster will be reprojected to. By default there are only (WGS84 and Pseudo Mercator (EPSG:3857) ). Then you need to specify a file.

Note

The file should be in GeoTIFF format with 3 or 4 bands (RGB or RGBA).

After a file is successfully uploaded you need to create a style (if it was not create automatically). When creating a map (for more information see subsection. Creation of web map) you can add a raster to a map by selecting a raster and its style.

2.5.1.1. Raster layer with transparency (clip or alpha channel)

Most of utilities does not create alpha channel and only add a NoData value. To transform NoData value to alpha channel use a command line utility gdalwarp. Here is an example of this command.

gdalwarp -t_srs EPSG:3857 -multi -dstalpha -dstnodata none -wo \
"UNIFIED_SRC_NODATA=YES" -co COMPRESS=JPEG \
d:\temp\o\ast_20010730_010043_rgb.tif d:\temp\o\ast_20010730_010043_rgba.tif

Note

NextGIS Manager simplifies this process. Software has an option to upload a raster to NextGIS Web and cut using alpha channel.

2.5.2. Vector layer from file

To add a vector layer navigate to a group where you want to create it. In Actions pane in Create resource section select Vector layer action. A dialog for creation of vector layer will open. Enter display name that will be visible in administrator interface and in map layer tree. Fields Keyname and Description are not required. Switch from Resource tab to Vector layer tab. Vector layer tab is presented on Pic. 2.13..

../../_images/admin_layers_create_vector_layer_resourse_description1.png

Pic. 2.13. Create resource dialog for vector layer.

Then you need to specify a coordinate system the vector data will be reprojected to. By default there are only (WGS84 and Pseudo Mercator (EPSG:3857) ).

Then you need to specify source file (click button Select, see Pic. 2.14.). Source files could be in the following formats:

  • ESRI Shapefile;
  • GeoJSON.

Note

In case of ESRI Shapefile all components (dbf, shp, shx, prj and other files) should be compressed to a zip-archive. Shapefile should have UTF-8 or Windows-1251 encoding.

Note

If you upload data through web-interface, do not use EPSG:3857. Use EPSG:4326 or other coordinate systems (EPSG:3857 mentioned on Vector layer tab is a storage CRS not related to data CRS).

Output file should not have invalid geometries (QGIS tool should output an empty list of invalid geometries), dates should not have NULL values, there should not be attribute names: id (ID), geom(GEOM).

Special restriction for WFS protocol: attribute names should begin only with letter or (_), next allowed sybmols in name is letters, digits, (-), (_), (.).

Coordinate system should be recognized by GDAL (output of gdalinfo should contain coordinate system definition).

../../_images/admin_layers_create_vector_layer_upload1.png

Pic. 2.14. Vector layer tab with button for upload of vector file.

Also you need to specify encoding that is used for attributes. If encoding is not set ESRI Shapefile should have a file with encoding description (cpg extension). In case of GeoJSON encoding is always UTF-8.

After a file is successfully uploaded you need to create a style. For more information about creation of styles see subsection Vector layer styles.

When creating a map (for more information see subsection. Creation of web map) you can add a vector layer to a map by selecting its style.

Note

NextGIS Manager simplifies this process. Software has an option to upload of vector files in different formats to NextGIS Web without separate archiving.

2.5.3. Vector layer from PostGIS

To add a vector layer from database with PostGIS extension you need to create a resource PostGIS connection. It is enough to create one connection. In Actions pane select Create resource ‣ PostGIS connection. Create PostGIS connection dialog is shown on Pic. 2.15..

map to buried treasure

Pic. 2.15. Create resource dialog for PostGIS connection.

Enter display name that will be visible in administrator interface. Do not confuse this name with a name of layers in a database.

Fields Keyname and Description are not required.

Switch from Resource to PostGIS connection tab. PostGIS connection tab is presented on Pic. 2.16..

Then enter PostGIS database connection parameters to connect data for display.

../../_images/admin_layers_create_postgis_connection_db_logins.png

Pic. 2.16. PostGIS connection tab of Create resource dialog.

Then you can add single PostGIS layers. Navigate to a group where you want create layers. In Actions pane select Create resource ‣ PostGIS layer. Create resource for PostGIS layer is presented on Pic. 2.17..

../../_images/admin_layers_create_postgis_layer_resourse_description.png

Pic. 2.17. Create resource dialog for PostGIS layer.

Enter display name that will be visible in administrator interface and in map layer tree. Fields Keyname and Description are not required. Switch from Resource tab to PostGIS layer tab. Create resource dialog for PostGIS layer is presented on Pic. 2.18..

../../_images/admin_layers_create_postgis_layer_tablename.png

Pic. 2.18. PostGIS layer tab of create resource dialog.

Then perform the following steps:

  1. From a dropdown list select a database connection (creation of a connection is described above).
  2. Enter a schema of a database where layer data is stored. Single database can store multiple schemas. Each schema contains tables and views. If there is only one schema its called public. For more information see PostgreSQL DBMS manual.
  3. Enter Table name (PostGIS layer). You need to know names of tables and columns in your database. Display of tables and views is not a feature of NextGIS Web. To view them you can use: NextGIS Manager or PgAdmin software.
  4. Enter ID column. Ususally when data is loaded to PostGIS using :program: NextGIS Manager software an ogc_fid column is created. If data was loaded in another way the name of column may be different. An ID column should follow rules for data type: the value type should be a number (numeric) and it should be a primary key.
  5. Enter geometry column name (if data was loaded to PostGIS using NextGIS Manager software usually a geometry column called wkb_geometry is created. If data is loaded in another way the name of column may be different).
  6. Parameters Geometry type, Coordinate system and Attribute definitions are not required so you can use default values.

NextGIS Web software supports adding of tables with point, line and polygon geometries stored in a single geometry column. This is required for some specific datasets: e.g. if one table stores coordinates for parks as polygons and trash cans as points in a single table. In this case in NextGIS Web you need to add three different layers for each type of geometry and select appropriate geometry type in Geometry type parameter.

After layer is created you need to set a label attribute to display labels. Navigate to layer edit dialog and set a checkbox for the required field in Label attribute column.

If structure of a database has changed (column names, column types, number of columns, table names etc.) you need to update attribute definitions in layer properties. To perform changes select Update ‣ PostGIS layer ‣ Attribute definitions ‣ Reload and click Save.

2.5.3.1. Create layers with conditions

In NextGIS Web you can not define queries using a WHERE SQL expression. This provides additional security (prevention of SQL Injection attack). To provide query capability you need to create views with appropriate queries.

To do this connect to PostgreSQL/PostGIS database using pgAdminIII, then navigate to data schema where you want to create a view, right click tree item Views and select New view (see. Pic. 2.19.. number 1). Also you can right click on schema name and select New object ‣ New view. Enter the following information to create new view dialog:

  1. View name («Properties» tab).
  2. Data schema where to create a view («Properties» tab).
  3. SQL query («Definition» tab).
../../_images/pgadmin3.png

Pic. 2.19. Main dialog of pgAdminIII software.

The numbers indicate: 1. – Database items tree; 2 – a button for table open (is active if a table is selected in tree); 3 – SQL query for view.

After that you can display a view to check if query is correct without closing pgAdminIII (see Pic. 2.19.. number 2).

2.5.4. WMS layer

NextGIS Web is a WMS client. To connect a WMS layer you need to know its address. WMS server should be able to serve it using a coordinate system EPSG:3857. You can check for this coordinate system presence by making a GetCapabilites request to a server and examining the response. For example a WMS layer provided by Geofabrik (GetCapabilities), responds in EPSG:4326 and EPSG:900913. While EPSG:900913 and EPSG:3857 are technically the same, NGW requests data in 3857 and server does not support for that coordinate system.

To add WMS layer you need to create a resource called WMS connection. You may create a single connection for many layers. In the Actions pane select Create resource ‣ WMS connection. Create resource dialog for WMS connection is presented on Pic. 2.20..

../../_images/admin_layers_create_wms_connection_description.png

Pic. 2.20. Create resource dialog for WMS connection.

Enter display name that will be visible in administrator interface. Do not confuse this name with a name of layers in a database. Fields Keyname and Description are not required.

Switch from Resource tab to WMS connection tab. WMS connection tab is presented on Pic. 2.21.. Then you need to enter WMS server connection parameters from which you want to display data.

../../_images/admin_layers_create_wms_connection_url.png

Pic. 2.21. WMS connection tab of Create resource dialog.

Then you may start to add single WMS layers. Navigate to a group you want to create WMS layers in. In the Actions pane select Create resource ‣ WMS layer. Create resource dialog for WMS layer is presented Pic. 2.22..

../../_images/admin_layers_create_wms_layer_name.png

Pic. 2.22. Create resource dialog for WMS layer.

Enter display name that will be visible in administrator interface and in map layer tree. Fields Keyname and Description are not required. Switch from Resource tab to WMS layer tab. WMS layer tab of create resource dialog is presented on Pic. 2.23..

../../_images/admin_layers_create_wms_layer_parameters.png

Pic. 2.23. WMS layer tab of Create resource dialog.

Then perform the following steps:

  1. Select WMS connection that was created earlier.
  2. Select coordinate system which to use for requests to WMS server (by default there are only WGS84 / Pseudo Mercator (EPSG:3857) ).
  3. If parameters are correct the parameter Format will display MIME-types list that are served by a server. Select an appropriate one.
  4. If parameters are correct the parameter WMS layers will display a list of layers that are server by a server. Select required layers by clicking underlined names. You can select several layers.

Parameters to add a WMS layer for Public cadastral map by Rosreestr:

URL http://maps.rosreestr.ru/arcgis/services/Cadastre/CadastreWMS/MapServer/WmsServer?

Version 1.1.1.

2.5.5. WMS service

NextGIS Web software could perform as WMS server. This protocol is used to provide images for requested extent. To deploy a WMS service you need to add a resource.

In Actions pane select Create resource ‣ WMS service. Create resource dialog will open. Enter display name that will be visible in administrator interface and in map layer tree.

On WMS service tab add links to styles of required layers to a list. (see Pic. 2.24..) For each added style you should set a unique key. You can copy it from the name.

../../_images/admin_layers_create_wms_service_layers.png

Pic. 2.24. Example of WMS service settings for delivery of separate sheets of topographic maps.

After a resource is created you will see a message with WMS service URL which you can use in other software, e.g. NextGIS QGIS or JOSM. Then you need to set access permissions for WMS service. See section Setting permissions.

NextGIS Web layer could be added to desktop, mobile and web gis in different ways.

2.5.5.1. Connection to WMS

NextGIS Web is a WMS server. Any WMS layes could be added to a software that supports WMS layers. You need to know WMS service URL. You can get in on WMS service properties page. Example:

http://demo.nextgis.ru/resource/60/wms?

2.5.5.2. Connection to WMS in GDAL

Single NextGIS Web layers could be added as WMS. To use them through GDAL utilities you need to create an XML file for required layer. You need an URL for WMS service to create that file. You need to enter these parameters to ServerUrl string in example below. The rest remains unchanged.

<GDAL_WMS>
 <Service name="WMS">
     <Version>1.1.1</Version>
     <ServerUrl>http://176.9.38.120/practice2/api/resource/85/wms?</ServerUrl>
     <SRS>EPSG:3857</SRS>
     <ImageFormat>image/png</ImageFormat>
     <Layers>moscow_boundary_multipolygon</Layers>
     <Styles></Styles>
 </Service>
 <DataWindow>
   <UpperLeftX>-20037508.34</UpperLeftX>
   <UpperLeftY>20037508.34</UpperLeftY>
   <LowerRightX>20037508.34</LowerRightX>
   <LowerRightY>-20037508.34</LowerRightY>
   <SizeY>40075016</SizeY>
   <SizeX>40075016.857</SizeX>
 </DataWindow>
 <Projection>EPSG:3857</Projection>
 <BandsCount>3</BandsCount>
</GDAL_WMS>

If you need an image with transparency (alpha channel) set <BandsCount>4</BandsCount>

Gdal utility call example. The utility gets an image by WMS from NGW and saves it to a GeoTIFF format

$ gdal_translate -of "GTIFF" -outsize 1000 0  -projwin  4143247 7497160 \
4190083 7468902   ngw.xml test.tiff

2.5.5.3. Connection to TMS in GDAL

Single layers of NextGIS Web could be added as TMS. You need t create an XML file for required layer. To create this file you need the information about NGW address and a layer number (in the example: address - http://demo.nextgis.ru/ngw_kl, layer number - 5). You need to enter these parameters to ServerUrl string in example below. The rest remains unchanged.

<GDAL_WMS>
 <Service name="TMS">
     <ServerUrl>http://demo.nextgis.ru/api/component/render/tile?
                z=${z}&x=${x}&y=${y}&resource=5
     </ServerUrl>
 </Service>
 <DataWindow>
     <UpperLeftX>-20037508.34</UpperLeftX>
     <UpperLeftY>20037508.34</UpperLeftY>
     <LowerRightX>20037508.34</LowerRightX>
     <LowerRightY>-20037508.34</LowerRightY>
     <TileLevel>18</TileLevel>
     <TileCountX>1</TileCountX>
     <TileCountY>1</TileCountY>
     <YOrigin>top</YOrigin>
 </DataWindow>
 <Projection>EPSG:3857</Projection>
 <BlockSizeX>256</BlockSizeX>
 <BlockSizeY>256</BlockSizeY>
 <BandsCount>4</BandsCount>
 <Cache />
</GDAL_WMS>

2.5.6. WFS service

Setup of WFS layer is performed the same way as for WMS service but you add a layer instead of a style.

For more information see:

NextGIS Web can act as WFS server. Third party software could edit vector data on server using this protocol. To deploy a WFS service you need to add a resource. In Actions pane select Create resource ‣ WFS service. Create resource dialog will open. Enter display name that will be visible in administrator interface and in map layer tree. On WFS service tab add links to required layers to the list. For each added layer you should set a unique key. You can copy it from the name (see Pic. 2.25.).

../../_images/admin_layers_create_wfs_service_layers1.png

Pic. 2.25. Example of WFS service settings for delivery of separate sheets of topographic maps.

For each layer you can set a limit for the number of features transfered at once. By default the value is 1000. If this parameter is empty the limit will be disable and all features will be trasfered to the client. But this could result in high load of a server and cause significant timeouts because of high volumes of transfered data.

After a resource is created you need to open it in administrator interface one more time. You will see a message with WFS service URL which you can use in other software, for example NextGIS QGIS. Then you need to set access permissions for WFS service. See section Setting permissions.

2.5.7. Creation of a resource group

Resources could be joined to groups. For example you can join base layers to one group, satellite imagery to another group and thematic data to one more group etc.

Groups help organize layers in Control panel and help manage access permissions in a convenient way.

To create a resource group navigate to root group and on Actions pane select Create resource ‣ Resource group. Create resource dialog for resource group is presented on Pic. 2.26..

../../_images/admin_layers_create_group1.png

Pic. 2.26. Create resource dialog for resource group.

In create resource dialog enter:

  • Display name
  • Keyname – not required, may be empty
  • Description – not required, may be empty

and then click Create.

2.5.8. Typical structure

With NextGIS Web application experience we recommend the following typical structure for organizing resources.

Typical structure

Main resource group
      Web maps
              Master web map
              Test web map
      PostGIS connections
              PostGIS on server
      Data layers
              Base data
                      Borders
                      Infrastructure - linear features
                      Accounting area
              Thematic data
                      Results of measurements on accounting area
                      Results of measurements on accounting routes
                      Observation points for rare species
              Relief
                      ASTER DEM
                              DEM
                              Isolines
              Topographic data
                      Openstreetmap
                              Roads
                              Administrative borders
                              Hydrology
                              Railway stations
                              Railway roads
                              Landuse
                      1 : 100000
                              M-37-015
                              M-37-016
                              M-37-017
              Satellite imagery
                      Landsat-8
                      Ikonos