On Thu, 25 Apr 2019 at 21:19, Bo Victor Thomsen
<[email protected]> wrote:
>
> Hi all -
>
> I have a python plugin where I iterate through all vectorlayers and get the
> source for each layer using
>
> mySource = myVectorLayer.source()
>
> The result could be something like this: (one line)
>
> restrictToRequestBBOX='1' srsname='EPSG:25832'
> typename='dai:theme-pg-natura2000_omraader_habitatnatur'
> url='http://wfs2-miljoegis.mim.dk/dai/ows?version=1.1.0' table="" sql=
>
>
> The question: - How can i split this string into parts ? (In this case:
> restrictToRequestBBOX, srsname, typename, url, sql)
Use QgsDataSourceUri -- that's what it's designed for.
so something like
uri = QgsDataSourceUri(layer.source())
table = uri.table()
user = uri.username()
restrict_bbox = uri.param("restrictToRequestBBOX")
etc
For non-db layers (eg disk based OGR/GDAL layers, you should use
QgsProviderRegistry.instance().decodeUri(layer.source())
Nyall
>
> The obvious method is to use ex.: myList = mySource.split(' ')
>
> But that depends on that no part id or value contains a "blank"
>
> Is there a more secure method to do the spiltting?
>
> --
> Med venlig hilsen / Kind regards
>
> Bo Victor Thomsen
>
> _______________________________________________
> QGIS-Developer mailing list
> [email protected]
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
_______________________________________________
QGIS-Developer mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer