About 1.SQL views
Geoserver+postgresql+openlayers (leaflet) is currently the mainstream GIS development tool. PostgreSQL is used to store map data, GeoServer is used to publish map data, openlayers or leaflet is used to access the publishing map. Normally when data in shapefiles format is imported into the PostgreSQL database, we need to publish all the data through geoserver so that we can access it. In general, this mode of operation is not a problem, because the map as a basic service, once published will not change. But for the indoor map is not, if a mall has 5 layers, each floor layer has 5 map layer, for such a mall need to put these 25 map layers in GeoServer all published in order to access all the map of the mall. If you could put up with the 25 layers of this mall, would you still be able to put up a map of thousands of malls? If you can't stand it, you'll have to figure it out. Since publishing a map is a mechanical duplication of work, can we think of some way to help us with this work? This is our Sqlview appearance.
First introduce SQL View, through Sqlviews can do the following things:
(1) The database view can be published in GeoServer as a table, while GeoServer's sqlviews can not only implement simple query publication, but also input parameters as the condition of query view.
(2) Sqlviews can publish stored procedures or function of the database to perform more complex logical operations and queries.
(3) SQL views query can be parameterized by string substitution, parameter values can always be used in WMS and WFS requests, input values can be verified by the set of regular expressions to eliminate the risk of SQL injection attacks.
(4) Sqlviews is a result of database operation and query, can not use wfs_t to operate it, but wfs,wms can request or query normally.
2. Create a SQL views view with query criteria:
(1) Login geoserver, click Layer, select Workspace, create new layer.
(2) Create a new SQL Views view layer and publish it.
This creates a view that publishes the incoming table name data.
The default value for TBL is set to a table that will always exist in the database, with regular expressions set to allow only alphanumeric and underscore entries.
The property values are set for the type and coordinate system of the output result.
(3) Layer access
When you get a map through the WMS, just pass the value of the TBL through the viewparams.
Http://10.20.135.14/geoserver/parking/wms? service=wms&version=1.3.0&request=getmap&format=image%2fpng&transparent=true&layers= parking%3avtingchewei&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 a number of parameters. A single parameter is a key-value pair, that is, p1 is the parameter name, and V1 is the parameter value.
The view methods for accessing the publication through WMS are:
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 stores only need to publish 5 views in the GeoServer, and the Code of the publishing view can be pre-written into GeoServer to be packaged in. This system does not need to publish the map in any store use.
3. Create a SQL view view with function
Solve the issue of layer publishing, and finally can breathe a sigh of relief. But I didn't think the tricky question was still behind. The leader makes the interior navigation function. Do it, who let us is the hard-pressed yards of farmers. Then how to do indoor navigation, do this function, we still have to plan. The first is to write the shortest path query algorithm, and then query the path only need to start and end of the location of the input algorithm query, and finally the results of the query through the WMS or WFS way to get, displayed on the map.
When we write the shortest path planning algorithm, we need the input: the location of the road name, start point and end point of the user's floor, then we Chi Chi, the war 3 days and three nights, fix.
Then query, good to do, directly according to the above, put it, the mall's 5 floors are published a result path based on the corresponding floor view, wit bar? No,no,no! is a man who knows nothing of his mind. This time must be replaced by a new method, the shortest path planning algorithm as a function embedded in the PostgreSQL database, the input parameters of the function is: The user's floor, the starting point position, the end position, the output parameter is the starting point and the end points directly through the coordinates.
Finally, the shortest path results can be obtained by WMS or WFS.
Dynamically publish map layers with Sqlview