I am working on a small web application which is supposed to display points on a Leaflet map which are served as WMS from GeoServer, backed by a PostGIS datastore.
The data and geometry format is the same for each user, however, different users should not interfere with each other but only see their own data on the map. I implemented this by assigning each user visiting the page a unique "upload_id" which is stored as a database column along with his data. Hence, the database looks i.e. like:
id (PK), attribute1, attribute2, ... , geometry, upload_id 1, a, b, ..., POINT(...), jhkgf 2, c, d, ..., POINT(...), jhkgf 3, e, f, ..., POINT(...), jhkgd 4, g, h, ..., POINT(...), sggfz 5, i, j, ..., POINT(...), sggfz 6, k, l, ..., POINT(...), sggfz 7, m, n, ..., POINT(...), sggfz
In this example, the first three points have been uploaded by one user and the last four points by a different user, hence the different
- For a user with upload_id xyz, call GeoServer's REST API to create a new layer called xyz based on a SQL view like
SELECT * from data_table where upload_id = xyzand then attach the parameter
layer=xyzto all of his WMS GetMap requests in Leaflet. This results in one GeoServer layer per data upload and each data set can be identified via the layer's name.
- Initialize the application with one GeoServer layer for all incoming data sets based on a SQL view like
SELECT * from data_table, similar to the fact that there is one PostGIS table for all data sets. Then, select the data that is to be displayed to each user by sending a CQL filter parameter or similar with each WMS GetMap request that contains the requested upload_id.
In summary, it comes down to either creating lots of small layers, one for each dataset, or rather filtering the data that is to be displayed out of one large layer. Are there any advantages or disadvantages to either of the approaches, performance wise or other? If that makes a difference, traffic on the application will be low (no more than 3-5 users at the same time) and data sets vary in size but none will contain more than approx. 5000 points.