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.

Users of the application upload the point data via some HTML/JavaScript forms to the webserver (implemented with Python/Flask) which then parses the data (some csv format) and writes it to the PostGIS database from where it can be served by GeoServer as WMS.

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 upload_id.

Now, in order to display the correct data to each user (his upload_id is available in the JavaScript/Leaflet part of the application), I see two possibilities on how to proceed after the data has been uploaded and inserted into the database as described above:

  1. 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 = xyz and then attach the parameter layer=xyz to 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.
  2. 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.

  • does it have to be secure? i.e. is it the end of the world if I see user2's data? – Ian Turton Jan 7 '16 at 17:14
  • No, that would not be a problem from a security point of view if this was possible. It should just not happen unintentionally. – Dirk Jan 7 '16 at 17:26
  • 1
    I'd probably just go with simple cql filter (and make sure you index user id) – Ian Turton Jan 7 '16 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.