<div dir="ltr">Thanks Richard for your time. Comments between lines.<div class="gmail_extra"><br><div class="gmail_quote">2014-12-09 15:39 GMT-05:00 Richard Duivenvoorde <span dir="ltr"><<a href="mailto:rdmailings@duif.net" target="_blank">rdmailings@duif.net</a>></span>:<br><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On 09-12-14 16:41, Germán Carrillo wrote:<br>
> Hi Richard,<br>
><br>
> thanks a lot for your response. However, I think we aren't talking about<br>
> the same :)<br>
> I understand this thread was opened to ask about how to open a PostGIS<br>
> Layer from the OS (say GNU/Linux) command line at QGIS startup.<br>
<br>
</span>ah, sorry sorry :-(<br> <br></blockquote><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
well, I take this as a challenge...<br>
(short version: go to the end, either use a vrt file or a qgs file)<br>
<br>
looking into the code:<br>
<br>
<a href="https://github.com/qgis/QGIS/blob/master/src/app/qgisapp.cpp#L4206" target="_blank">https://github.com/qgis/QGIS/blob/master/src/app/qgisapp.cpp#L4206</a><br>
<br>
it looks like you can only use ogr provider for this...<br>
<br></blockquote><div>Good catch!</div><div> </div><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
here:<br>
<br>
<a href="http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/loadlayer.html" target="_blank">http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/loadlayer.html</a><br>
<br>
<br>
there is an example to use a MySQL uri... so I tried that one first.<br>
</blockquote><div><br></div><div>I sent the MySQL example to Martin :D<br></div><div>Do you see now why I was trying with the uri.uri()?</div><div> </div><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">All is based on ogr, so we need the ogr driver:<br><br></blockquote><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<a href="http://www.gdal.org/drv_pg.html" target="_blank">http://www.gdal.org/drv_pg.html</a><br>
<br>
tried stuff like:<br>
<br>
PG:'dbname=bag host=localhost port=5432 user=geo<br>
<span class="">password=xxx sslmode=disable key=gid estimatedmetadata=true srid=28992<br>
type=MULTIPOLYGON table="bag8mrt2014"."provincie" (geovlak) sql='<br>
<br>
</span>but all that I got working was a simple:<br>
<br>
ogrinfo -ro PG:'host=localhost user=geo password=gwwvgeo dbname=bag<br>
sslmode=disable'<br>
<br>
but using that kind of uri's did not make QGIS load, it kept showing:<br>
<br>
Unable to load /tmp/PG:host=localhost user=geo password=xxx dbname=bag<br>
sslmode=disable<br>
<br>
apparently QGIS ALWAYS prepends the basepath (/tmp for me) in front of<br>
the 'filename'. It has to be a real file ??<br></blockquote><div><br></div><div>Same here, QGIS prepends the user's folder.</div><div> </div><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
THEN: ok, so it has to be ogr AND a file...<br>
There is gdal's Virtual Format:<br>
<br>
<a href="http://www.gdal.org/drv_vrt.html" target="_blank">http://www.gdal.org/drv_vrt.html</a><br>
<br>
so with some trial and error I prepared the following vrt file, for<br>
exact the same data as the earlier email:<br>
<br>
<OGRVRTDataSource><br>
<br>
<OGRVRTLayer name="test"><br>
<SrcDataSource>PG:host=localhost user=geo password=*** dbname=bag<br>
sslmode=disable</SrcDataSource><br>
<SrcSQL>select * from bag8mrt2014.provincie</SrcSQL><br>
<LayerSRS>epsg:28992</LayerSRS><br>
</OGRVRTLayer><br>
<br>
</OGRVRTDataSource><br>
<br>
saved it as mypgconnection.vrt, and NOW I can load it with:<br>
<br>
qgis mypgconnection.vrt  \o/<br>
<br>
another option, is to create a qgs project file with that postgresql<br>
connection and fire up qgis with that one<br>
<br>
qgis mypgproject.qgs<br>
<br>
you could maybe create the qgs file dynamically to have your<br>
schema/table names in place<br>
<br></blockquote><div><br></div><div>Yes, actually my main requirement is to generate string connections dynamically. To be honest, I don't think writing to a file is the best way to achieve such task.</div><div> </div><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
ok, it's all a little hacking, but hopefully of use :-)<br>
<br>
Regards,<br>
<br>
Richard Duivenvoorde<br>
</blockquote></div><br>Thanks again!</div><div class="gmail_extra"><br></div><div class="gmail_extra">Don't you think --help gives users misleading information? It says that you can load PostGIS layers in the FILE parameter and, apparently, there is no way of doing that. </div><div class="gmail_extra"><br></div><div class="gmail_extra">The use case I have in mind is to select spatial tables from pgAdmin3 and open them in QGIS.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Regards, </div><div class="gmail_extra"><br></div><div class="gmail_extra">Germán<br clear="all"><div><br></div>-- <br><div class="gmail_signature">-----------<br>   |\__  <br>(:>__)(<br>   |/    <br><br>Soluciones Geoinformáticas Libres                            <br><a href="http://geotux.tuxfamily.org/">http://geotux.tuxfamily.org/</a><br><a href="http://twitter.com/GeoTux2">http://twitter.com/GeoTux2</a><br></div>
</div></div>