Sqlview: How to dynamically publish a map layer; sqlview: How to dynamically publish a map

Source: Internet
Author: User

Sqlview: How to dynamically publish a map layer; sqlview: How to dynamically publish a map

1. SQL Views

Geoserver + postgresql + openlayers (leaflet) is a mainstream gis development tool. Postgresql is used to store map data, geoserver is used to publish map data, and openlayers or leaflet is used to access publish map. Under normal circumstances, after data in the shapefile format is imported into the postgresql database, we need to publish all the data through geoserver so that the access can be made. In general, this operation method is fine, because as a basic service, once published, the map will not change. But it cannot be used for indoor maps. If a mall has five layers and each floor has five layers, for such a mall, you need to publish all the 25 map layers in geoserver to access all the maps of the mall. If you still can tolerate the release of 25 layers for this mall, can you still tolerate the release of maps for thousands of malls? If you cannot stand it, you have to solve it. Since map publishing is a mechanical repetitive task, can we come up with some ways to help us do this. At this time, our sqlView was launched.

First, we will introduce SQL View and use SQLViews to do the following:

(1) The database view can be released as a table in geoserver, while the SQLViews of geoserver can not only achieve simple query Publishing, but also enter parameters as conditions for querying the view.

(2) SQLViews can publish database stored procedures or functions to perform more complex logical operations and queries.

(3) SQL Views queries can be parameterized by string replacement. The parameter values can be used in all wms and wfs requests, the input value can be verified using the set regular expression to eliminate the risk of SQL injection attacks.

(4) SQLViews is a result of database operations and queries. You cannot use wfs_t to operate on it, but wfs and wms can both request or query normally.

2. Create an SQL Views view with query conditions:

(1) log on to geoserver, click layer, select workspace, and create a new layer.

(2) create and publish an SQL Views layer.


A view is created to publish the input table name data.

The default value of tbl is set to a table that always exists in the database, and the regular expression is set to only allow the input of letters, numbers, and underscores.


Set the output result type and coordinate system in the attribute value.

(3) layer access

When obtaining a map through wms, you only need to pass the tbl value through viewparams.

Http: // 10.20.135.14/geoserver/parking/wms? SERVICE = WMS & VERSION = 1.3.0 & REQUEST = GetMap & FORMAT = image % 2 Fpng & TRANSPARENT = true & LAYERS = parking % 3 AvTingchewei & CRS = EPSG % 3A4326 & STYLES = & WIDTH = 2700 & HEIGHT = 1200 & BBOX = 20.02708134918213% 2C110. 33805803565978% 2C20. 03351865081787% 2C110. 3525419643402 & viewparams = tbl % 3Awanghaiguojia_b2_tingchewei

Viewparams format is generally viewparams = p1: v1; p2: v2 ;... You can add several parameters. Different parameters are separated by commas (,). A single parameter is a key-value pair, that is, p1 is the parameter name, and v1 is the parameter value.

You can use wms to access the published view as follows:

var params = {LAYERS:'parking:vTingchewei',FORMAT:'image/png'};varviewparams = ['tbl:wanghaiguojia_b2_tingchewei'];params.viewparams= viewparams;varvTingchewei = new ol.layer.Image({source:new ol.source.ImageWMS({url:'http://10.20.135.14/geoserver/parking/wms', params:params,serverType:'geoserver',})});

In this way, more malls only need to publish the view five times in geoserver, and the code of the published view can be written into geoserver and packaged in advance. In this way, the system does not need to publish maps for use in any mall.

3. Create an SQL View containing Functions

After solving the issue of layer Publishing, we can finally breathe a sigh of relief. However, I did not expect the problem to be followed. The leader provides the indoor navigation function. Let's do it. Who makes us a hard-earned codoon. So how should we implement indoor navigation? before doing this function, we should plan it. First, you need to write the Shortest Path query algorithm. Then, you only need to input the start and end locations into the algorithm to query the path. Finally, you can obtain the query results through wms or wfs, displayed on the map.

When writing the shortest path planning algorithm, we need to enter the road name, start point, and end point of the user's floor. Then, we will try again three days and three nights.

Next, let's look at the query. Just put it above and publish a result path view based on the results of the five floors of the mall. Is it witty? NO, NO, NO! It's easy to understand things. At this time, you must change the method to write the shortest path planning algorithm as a Function and embed it into the postgresql database. The input parameter of this function is: User floor, start point, the end point. The output parameter is the coordinate of the point directly passing through the start point and the end point.

Finally, obtain the Shortest Path result through wms or wfs.

The above implementation section introduces the Sqlview Dynamic Release of map layers. I hope it will be helpful to you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.