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
Make it possible to use 'inbuilt:'-uri with OGR provider #39175
Conversation
Loading the easter egg 'world' actually loads an inbuild gpkg from the (install dir) resources directory. It ends up in the project file with the eg following uri: source="inbuilt:/data/world_map.gpkg|layername=countries" This commit makes it possible to actually (re)use that uri in the OGR provider. So in pyqgis you can now do: iface.addVectorLayer('inbuilt:/data/world_map.gpkg|layername=countries', 'Countries', 'ogr')
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 needs to be done in a different way -- it's not a provider level responsibility (and infact the OGR provider already works with it for layers coming from projects).
Rather you'd need to edit QgisApp::addVectorLayerPrivate to extract the filename from the vectorLayerPath argument (via QgsProviderRegistry::instance()->decodeUri() ) and then push the returned path value through QgsPathResolver().readPath() before updating the parsed uri map with the resolved value, and then reencode this uri for use in the rest of addVectorLayerPrivate.
Let me know if you'd like to tackle this or want me to...
Thanks @nyalldawson ! I will try this myself first, if in trouble I'll call for help :-) |
Totally up to you and what git workflow you're comfortable with! :D |
Maybe it's better to implement a convenient way to resolve the path of "inbuilt:" to absolute paths. Then the output could be used in the OGR provider call, the usual way. Curently By the way there have been talks before about elevating the world layer from 'easter egg' status. It is already used as the base layer for the projection bounds overview. (Implemented in |
@arongergely note that
works... |
Yes that should work! It was a long while ago - but I remember I hit some issues when i was implementing code for multiplatform use - . Considering people may use the cookbook on windows.. UNIX / Windows file separators issue? the string literal contains the file separators. |
But in any case one could just handle that via the |
Not sure if this is still handy, but I was looking for some code to use the world map in the PyQGIS cookbook...
Loading the easter egg 'world' actually loads an inbuild gpkg from
the (install dir) resources directory.
It ends up in the project file with the eg following uri:
source="inbuilt:/data/world_map.gpkg|layername=countries"
This commit makes it possible to actually (re)use that uri in the
OGR provider.
So in pyqgis you can now do:
I do not think this breaks anything?
I'm aware this also works