-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add basemap to qgs project #12
Conversation
filters/map_composition.py
Outdated
# add basemap to the qgs project so it can be called later to create a thumbnail | ||
qgis_layer = QgsRasterLayer('type=xyz&url=http://tile.osm.org/{z}/{x}/{y}.png?layers=osm', 'osm', 'wms') | ||
if not qgis_layer.isValid(): | ||
print("osm not found") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hindari print sih kalau bisa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, avoid using print
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Logger, because we can't see it if it is using print statement.
filters/map_composition.py
Outdated
# Add layer to the registry | ||
QgsMapLayerRegistry.instance().addMapLayer(qgis_layer) | ||
# add basemap to the qgs project so it can be called later to create a thumbnail | ||
qgis_layer = QgsRasterLayer('type=xyz&url=http://tile.osm.org/{z}/{x}/{y}.png?layers=osm', 'osm', 'wms') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make another parameter that accepts basemap urls/source.
@lucernae instead of using logger, i'll keep with the current implementation. i've updated the osm request so no more hardcoded. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will add the OSM layer in the project. Are you sure it's what you want? (in WMS, QGS, ...)
Please also update the readme with this new parameter saying it's optional.
filters/map_composition.py
Outdated
@@ -46,7 +46,8 @@ def responseComplete(self): | |||
FILES=/path/1.shp;/path/2.shp;/path/3.asc& | |||
NAMES=Layer 1;Layer 2;Layer 3& | |||
REMOVEQML=true& | |||
OVERWRITE=true | |||
OVERWRITE=true& | |||
BASEMAP=[<base map url>, <base map name>] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like other parameters, you should put the example how to use it:
BASEMAP=http://foo.com/{z}/{x}/{y}.png;OSM
filters/map_composition.py
Outdated
if params.get('BASEMAP'): | ||
# basemap is comprised of url and name with semicolon as separator | ||
basemap = params.get('BASEMAP').split(';') | ||
if len(basemap) > 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
==2 ?
filters/map_composition.py
Outdated
if len(basemap) > 1: | ||
qgis_layer = QgsRasterLayer(basemap[0], basemap[1], 'wms') | ||
if not qgis_layer.isValid(): | ||
request.appendBody('%s cannot found' % basemap[1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cannot be found
@boney-bun why are you doing this? See my comment in the issue! Do not add anything to the QGIS project. |
Hi @Gustry
i've tried a few scenario in the geonode. it seems to be harmless. @gubuntu this PR is to overcome the technical challenge in the geonode and qgis-server perspective for kartoza/geonode#401. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked the layer order too?
Just make sure if the base layer were to be put last, then it is at the bottom of the layers when rendered.
If it is on top, it will cover all layers.
README.md
Outdated
@@ -14,6 +14,7 @@ | |||
* NAMES, compulsory, it's a list of names, separated by a semicolon. It will be used for the legend. Items in this list should match layers in the FILES list. | |||
* OVERWRITE, optional, false by default. Boolean if we can overwrite the existing PROJECT above. Values can be '1', 'YES', 'TRUE', 'yes', 'true'. | |||
* REMOVEQML, optional, false by default. Boolean if we can remove the QML. The style is already in the QGS file. Values can be '1', 'YES', 'TRUE', 'yes', 'true'. | |||
* BASEMAP, optional, None by default. it's a list of string comprised of a tile url and its service name, separated by a semicolon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give example of values here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me tile url
like mentioned, it's what we get on geonode or a normal TILE url such as: http://tile.osm.org/{z}/{x}/{y}.png
but here, you want a URI according to QGIS specifications (with type=
)
Well, I think @Gustry 's concern is similar to what I told you previously. If you put a basemap, does the basemap gets accidentally rendered in WMS tile request from map client? You can check this by requesting the tile via WMS after creating a QGS project with basemap. If it is ok, you can proceed. All of our docker build for QGIS Server includes otf-project and it is possible that it was used on another project, so we have to make sure it doesn't have any unexpected side effects. This will achieve:
From @gubuntu 's comment in the issue:
We did this by putting all the layer's connections in the QGIS project file. If we want to include the basemap, we have to put it in QGIS project file, in order for one WMS request to return all the layers including basemap as a map thumbnail. |
since this is done it's worth testing so merge and deploy to testing. If upstream accepts it, great! |
filters/map_composition.py
Outdated
@@ -46,7 +46,8 @@ def responseComplete(self): | |||
FILES=/path/1.shp;/path/2.shp;/path/3.asc& | |||
NAMES=Layer 1;Layer 2;Layer 3& | |||
REMOVEQML=true& | |||
OVERWRITE=true | |||
OVERWRITE=true& | |||
BASEMAP='type=xyz&url=http://tile.osm.org/{z}/{x}/{y}.png?layers=osm;osm' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering what is the ?layers=osm
for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add the simple quote too in the documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the function of layers=osm
is to naming the layer as osm. so that we can refer to the layer name later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just wondering, is there any pros for having a new parameter?
We already have FILES
for path to layers and NAMES
for the name of each path. Now we are introducing a new one BASEMAP
which include path and name.
Would it be difficult to use the same API?
FILES=type=xyz&url=http://foo/{z}{x}{y}.png;/path/1.shp;/path/2.shp;/path/3.asc&
NAMES=OSM;Layer 1;Layer 2;Layer 3&
NAMES=Layer 1;Layer 2;Layer 3&
Just a question, it looks a little tricky in my example.
I can see your point @Gustry i initially though that the BASEMAP parameter would be easier to understand when a new user read the doc. but, if we would like to avoid adding a new parameter, your idea work too. |
@lucernae i'm not sure if i understand your comment correctly.
does the steps on the GIF below is what you meant? |
@Gustry, that makes sense. We can just use that, but maybe we need a different name since it's not just FILES anymore. Maybe SOURCES is a good idea, but we still handles FILES for legacy support. What do you think?
That's not what I meant, but I'll try that later tonight @boney. Sorry for the late reply. |
a8c1394
to
e1a59ca
Compare
- This will enable inserting Tile URL as basemap stored in QGIS Project - Update README
e1a59ca
to
ddf4b75
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Gustry @boney-bun I made some changes. Need review and comment on this.
filters/map_composition.py
Outdated
# Overwrite means create from scratch again | ||
remove(project_path) | ||
|
||
sources_parameters = params.get('SOURCES') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the params name because now it's not just files.
But we still support old name
return | ||
else: | ||
remove(project_path) | ||
if exists(project_path) and overwrite: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes now:
- If overwrite is specified, then delete qgs project file and create new later
- If project exists and not overwrite, then update layer registry
|
||
QgsMessageLog.logMessage('Setting up project to %s' % project_path) | ||
project = QgsProject.instance() | ||
project.setFileName(project_path) | ||
if exists(project_path) and not overwrite: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If project exists and not overwrite, then we read from current file first.
# Add layer to the registry | ||
if overwrite: | ||
# Insert all new layers | ||
QgsMapLayerRegistry.instance().addMapLayers(qgis_layers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just insert all of new layers, because the old file was deleted.
# 2. Compare source, if it is the same, don't update | ||
# 3. If it is a new name, add it | ||
# 4. If same name but different source, then update | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I miss something here, but this is the update rules.
Sure, better SOURCES. Because we can later add PostGIS or other sources of layers (not only file based). Just use SOURCES first, and if FILES is still used, you can add a warning in the output saying that is deprecated. Il will review tomorrow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick review tonight ;-)
Nice work
@@ -10,7 +10,9 @@ | |||
* Parameters : | |||
* SERVICE=MAPCOMPOSITION, compulsory | |||
* PROJECT, compulsory, path where the project will be written on the file system. | |||
* FILES, compulsory, it's a list of files on the filesystem, separated by a semicolon. | |||
* SOURCES, compulsory, it's a list of layer sources. It can be tile url or QGIS DataSource URI or files on the filesystem, separated by a semicolon. | |||
Especially for QGIS DataSource URI, it must be url quoted twice (first the url, second the whole datasource string). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just move FILES here, at the end of SOURCES.
Previously FILES
README.md
Outdated
OVERWRITE=true | ||
``` | ||
|
||
In the sample request above, note that the datasource: ```type%253Dxyz%2526url%253Dhttp%25253A%2F%2Fa.tile.osm.org%2F%25257Bz%25257D%2F%25257Bx%25257D%2F%25257By%25257D.png``` were urlquoted twice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use single quote for inline code ;-)
Nothing to update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hahaha... my habit, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
i have only one comment regarding a mere coding style.
filters/map_composition.py
Outdated
files_parameters = params.get('FILES') | ||
if not files_parameters: | ||
request.appendBody('FILES parameter is missing.\n') | ||
if not sources_parameters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is perhaps a matter of coding style.
but sometimes it leads a new developer to believe that there's a repeated if condition in the second checks.
perhaps we need to add a comment here describing the business logic.
something like:
# if SOURCES and FILES don't exist, ask for providing SOURCES
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will add some comment.
Thanks everyone |
what ar you waiting for @boney-bun? |
fix kartoza/geonode#401