<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi,</div><div><br></div><div>I have a similar question to this that was asked some time ago, or I want to include gdals polygonize in my plugin to convert a raster to polygons.<br></div><div><br></div><div>As a first approach I added following code to the plugin (where "db" is a class containing all information required to connect to a database, "s_tbl" is the name of new table to create and "file_name_with_path" is a text string with the path).</div><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:"Courier New"">run_text = <span style="color:rgb(106,135,89)">"""gdal_polygonize.bat {file_w_path} -f PostgreSQL PG:"host='{host}' port='{port}' dbname='{dbname}' user='{username}' password=<br></span><span style="color:rgb(106,135,89)">'{password}'" {s_tbl}<br></span><span style="color:rgb(106,135,89)">    """</span>.format(<span style="color:rgb(170,73,38)">host</span>=<span style="color:rgb(148,85,141)">self</span>.db.dbhost<span style="color:rgb(204,120,50)">, </span><span style="color:rgb(170,73,38)">port</span>=<span style="color:rgb(148,85,141)">self</span>.db.dbport<span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">               </span><span style="color:rgb(170,73,38)">dbname</span>=<span style="color:rgb(148,85,141)">self</span>.db.dbname<span style="color:rgb(204,120,50)">, </span><span style="color:rgb(170,73,38)">username</span>=<span style="color:rgb(148,85,141)">self</span>.db.dbuser<span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">               </span><span style="color:rgb(170,73,38)">password</span>=<span style="color:rgb(148,85,141)">self</span>.db.dbpass<span style="color:rgb(204,120,50)">, </span><span style="color:rgb(170,73,38)">s_tbl</span>=<span style="color:rgb(148,85,141)">self</span>.s_tbl<span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">               </span><span style="color:rgb(170,73,38)">file_w_path</span>=<span style="color:rgb(148,85,141)">self</span>.file_name_with_path)<br>run = subprocess.Popen(run_text)<br>run.wait()</pre></div>It works fine for me, but as was pointed out gdal_polygonize.bat is the "python 2 solution". </div><div dir="ltr"><br></div><div dir="ltr">To understand how to run the command properly with python3 I tried to install a fresh copy of QGIS (via osgeo4w and only choose to install qgis:desktop version 3.4.3-2) and where "gdal_polygonize.bat" isn't located in my "bin folder", when I now tries to run the polygonize tool I get following error:</div><div dir="ltr">"<span style="white-space:pre-wrap">GDAL command output:</span></div>
<p style="margin:0px;white-space:pre-wrap"><span style="font-family:"Courier New";color:rgb(119,119,119)">'gdal_polygonize.bat' is not recognized as an internal or external command,<br></span></p>
<p style="margin:0px;white-space:pre-wrap"><span style="font-family:"Courier New";color:rgb(119,119,119)">operable program or batch file."</span></p><p style="margin:0px;white-space:pre-wrap"><span style="font-family:"Courier New";color:rgb(119,119,119)"><br></span></p>If I shall use GDAL functions in QGIS3 what would be the working solution (that works on Windows, Linux and Mac)</div><div dir="ltr"><br></div><div>Thanks,</div><div>Axel</div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, 27 Sep 2018 at 00:19, Jürgen E. Fischer <<a href="mailto:jef@norbit.de">jef@norbit.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Idan,<br>
<br>
On Thu, 27. Sep 2018 at 00:53:32 +0300, Idan Miara wrote:<br>
> 1. As I'm targeting only Python3 (using python3-gdal-2.2.4-1.tar.bz2), I<br>
> was wandering if I need to provide also the Python27 for the gdal-python<br>
> scripts (gdal-python-2.2.4-2.tar.bz2) ?<br>
> Are they all the gdal-python scripts Python3 compatible? If so, why does<br>
> gdal-python-2.2.4-2.tar.bz2 include the Python27 libs/site-packages and not<br>
> in a separate file as for Python3?<br>
<br>
gdal-python is for python2<br>
python3-gdal for python3<br>
<br>
Which is also what you need to install to get the bindings and the required<br>
dependencies (except for optional parts a gdal-ecw, gdal-oracle etc.)<br>
<br>
> I understand it must be possible because somehow starting qgis-bin.exe<br>
> works (I guess it has to do with the qgis-bin.env file, but how does it<br>
> work?<br>
<br>
That is actually done by QGIS itself.  QGIS's postinstall runs the qgis*bat<br>
with --postinstall argument, which in turn will read the qgis*.vars file, which<br>
has a list of environment variables that are required to run qgis and dumps<br>
them to the qgis*.env file.  The latter is then used whenever the exe is<br>
started directly - for instance to make it pinnable (see src/app/mainwin.cpp).<br>
<br>
To enable python3 you need to call py3_env.bat.  That will also add the scripts<br>
directory of python3 to the path, which has the python3 versions of the gdal<br>
scripts.  However the wrapper batch files (eg.  gdal_merge.bat) are only<br>
generated in gdal-python and use python2.<br>
<br>
<br>
Jürgen<br>
<br>
-- <br>
Jürgen E. Fischer           norBIT GmbH             Tel. +49-4931-918175-31<br>
Dipl.-Inf. (FH)             Rheinstraße 13          Fax. +49-4931-918175-50<br>
Software Engineer           D-26506 Norden             <a href="http://www.norbit.de" rel="noreferrer" target="_blank">http://www.norbit.de</a><br>
QGIS release manager (PSC)  Germany                    IRC: jef on FreeNode<br>
_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></blockquote></div>