<html><body>Thank you a lot. I have managed to move forward, but i am not there yet:/<br>I can definitely reach the database since the command:<br> v.in.ogr  -l input= "PG:host=172.21.3.20 dbname=mydb user=dbusername password=passwd"<br>prints out names of my tables in database.<br>But command<br>v.in.ogr input= "PG:host=172.21.3.20 dbname=mydb user=dbusername password=passwd" output=outpoint  layer=myschema.mytable<br>prints an error about "missing '=' after 'mydb' in connection info string" (at the end). This seems maybe like pg error than grass.script, doesnt it?<br><br>Thx. <br>Vil<br><br><span style="font-size:12px">DBMI-PostgreSQL driver error:<br>Connection failed.<br>missing "=" after "mydb" in connection info string<br><br>DBMI-PostgreSQL driver error:<br>Connection failed.<br>missing "=" after "mydb" in connection info string<br><br>WARNING: Unable to open database <dbname=mydb schema=myschema> by<br>         driver <pg><br>WARNING: Unable open database <dbname=mydb schema=myschema> by<br>         driver <pg><br>WARNING: Unable to find table <outputpoint> linked to vector map<br>         <outputpoint><br>Creating attribute table for layer <myschema.mytable>...<br>DBMI-PostgreSQL driver error:<br>Connection failed.<br>missing "=" after "mydb" in connection info string<br><br>DBMI-PostgreSQL driver error:<br>Connection failed.<br>missing "=" after "mydb" in connection info string<br><br>WARNING: Unable to open database <dbname=mydb schema=myschema> by<br>         driver <pg><br>ERROR: Unable to open database <dbname=mydb schema=myschema> by<br>       driver <pg></span><br><br><br><br><aside>
---------- Původní e-mail ----------<br>
Od: Moritz Lennert <mlennert@club.worldonline.be><br>
Komu: Vilem Ded <Ded.V@seznam.cz><br>
Datum: 13. 2. 2018 14:58:22<br>
Předmět: Re: [GRASS-user] load vector map from PostGIS
</aside><br><blockquote data-email="mlennert@club.worldonline.be">Le Tue, 13 Feb 2018 14:09:31 +0100 (CET),
<br>"Vilem Ded" <Ded.V@seznam.cz> a écrit :
<br>
<br>> Hi, 
<br>> is there any possibility to download data  into local grass database 
<br>> (topologcal) from remote postgis server? (without getting error)
<br>> Or is the issue still pending?
<br>> (http://osgeo-org.1560.x6.nabble.com/Unable-
<br>> to-link-to-postgis-postgresql-td5285313.html) I am using Python to
<br>> work with GRASS. And honestly, I got lost in outputs of db.*
<br>> functions:
<br>
<br>AFAIK, you should not need to go through all the db.* functions to
<br>import your data. Not much time to look any further into this, but check
<br>this thread:
<br>https://lists.osgeo.org/pipermail/grass-dev/2017-May/085032.html/
<br>
<br>In brief, you should be able to import your data with a simple v.in.ogr
<br>call, without any db.connect/db.login magic.
<br>
<br>Moritz
<br>
<br>> 
<br>> #set database and login
<br>> gscript.run_command('db.connect',
<br>> database="host=172.21.3.20,dbname=mydb", driver="pg",  verbose = True)
<br>> gscript.run_command('db.login', user="dbusername", password="passwd", 
<br>> overwrite = True)
<br>> 
<br>> #verifying connection
<br>> gscript.run_command('db.connect', flags='p')
<br>> output:
<br>> driver: pg
<br>> database: host=172.21.3.20,dbname=mydb
<br>> schema: 
<br>> group: 
<br>> #so everything looks fine so far
<br>> 
<br>> #here comes the trouble - simple list tables in db
<br>> gscript.run_command('db.tables', flags='p', verbose = True)
<br>> output:
<br>> DBMI-PostgreSQL driver error:
<br>> Connection failed.
<br>> could not connect to server: No such file or directory
<br>>     Is the server running locally and accepting
<br>>     connections on Unix domain socket
<br>> "/var/run/postgresql/.s.PGSQL.5432"?
<br>> 
<br>> DBMI-PostgreSQL driver error:
<br>> Connection failed.
<br>> could not connect to server: No such file or directory
<br>>     Is the server running locally and accepting
<br>>     connections on Unix domain socket
<br>> "/var/run/postgresql/.s.PGSQL.5432"?
<br>> 
<br>> ERROR: Unable to open database <host=172.21.3.20,dbname=mydb>
<br>> 
<br>> #but for example:
<br>> gscript.run_command('v.external',
<br>>                     input="PG:dbname=mydb host=172.21.3.20",
<br>>                     flags='l', overwrite =  True)
<br>> output:
<br>> --actuall list of all tables in mydb - so i CAN connect to the server!
<br>> 
<br>> #same for mapping external link - following will create external link
<br>> gscript.run_command('v.external',
<br>>                     input="PG:dbname=mydb host=172.21.3.20
<br>> user=dbusername password=password",
<br>>                     layer="myschema.mytable", output='outpoints,
<br>> overwrite = True)
<br>> output:
<br>> WARNING: No key column detected.
<br>> WARNING: Feature table <outpoints> has no primary key defined. Unable
<br>> to define DB links.
<br>> WARNING: Feature table <outpoints> has no primary key defined
<br>> WARNING: Random read is not supported for this layer. Unable to build
<br>>          topology.
<br>> v.external complete. Link to vector map <outpoints> created.
<br>> 
<br>> #weird, because i have primary key defined in the table, following is 
<br>> printing description of that external link
<br>> gscript.vector_info("outpoints")
<br>> 
<br>> #if i try to load data from database
<br>> gscript.run_command('v.in.ogr',
<br>>                     input="PG:dbname=mydb host=172.21.3.20",
<br>>                     layer='myschema.mytable',geometry="mygeomcolumn",
<br>> output = "outpoints2", overwrite =  True, type="point")
<br>> output:
<br>> Check if OGR layer <myschema.mytable> contains polygons...
<br>>  100%�����
<br>> WARNING: Vector map <outpoints2> already exists and will be
<br>> overwritten DBMI-PostgreSQL driver error:
<br>> Connection failed.
<br>> could not connect to server: No such file or directory
<br>>     Is the server running locally and accepting
<br>>     connections on Unix domain socket
<br>> "/var/run/postgresql/.s.PGSQL.5432"?
<br>> 
<br>> DBMI-PostgreSQL driver error:
<br>> Connection failed.
<br>> could not connect to server: No such file or directory
<br>>     Is the server running locally and accepting
<br>>     connections on Unix domain socket
<br>> "/var/run/postgresql/.s.PGSQL.5432"?
<br>> 
<br>> WARNING: Unable to open database <host=172.21.3.20,dbname=macfishdb>
<br>> by driver <pg>
<br>> WARNING: Unable open database <host=172.21.3.20,dbname=macfishdb> by
<br>> driver <pg>
<br>> WARNING: Unable to find table <outpoints2> linked to vector map
<br>> <lp_grass> Creating attribute table for layer
<br>> <at_macfish.loggerpos>... DBMI-PostgreSQL driver error:
<br>> Connection failed.
<br>> could not connect to server: No such file or directory
<br>>     Is the server running locally and accepting
<br>>     connections on Unix domain socket
<br>> "/var/run/postgresql/.s.PGSQL.5432"?
<br>> 
<br>> DBMI-PostgreSQL driver error:
<br>> Connection failed.
<br>> could not connect to server: No such file or directory
<br>>     Is the server running locally and accepting
<br>>     connections on Unix domain socket
<br>> "/var/run/postgresql/.s.PGSQL.5432"?
<br>> 
<br>> WARNING: Unable to open database <host=172.21.3.20,dbname=mydb> by
<br>>          driver <pg>
<br>> ERROR: Unable to open database <host=172.21.3.20,dbname=mydb> by
<br>>        driver <pg>
<br>> 
<br>> My version of grass:
<br>> GRASS version:
<br>> 7.4.0 
<br>> GRASS SVN revision:
<br>> exported 
<br>> Build date:
<br>> 2018-01-26 
<br>> Build platform:
<br>> x86_64-pc-linux-gnu 
<br>> GDAL:
<br>> 2.2.2 
<br>> PROJ.4:
<br>> 4.9.2 
<br>> GEOS:
<br>> 3.5.1 
<br>> SQLite:
<br>> 3.11.0 
<br>> Python:
<br>> 2.7.12 
<br>> wxPython:
<br>> 3.0.2.0 
<br>> Platform: Linux-4.4.0-112-generic-x86_64-with-Ubuntu-16.04-xenial   
<br>> 
<br>> Version of python:
<br>> 
<br>> Python 2.7.12 64bits
<br>> 
<br>> Content of my .grass7/dblogin:
<br>> pg|host=172.21.3.20, dbname=mydb|dbusername|passwd||
<br>> sqlite|$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db|dbusername|passwd||
<br>> pg|macfishdb|dbusername|passwd||
<br>> pg|host=172.21.3.20,dbname=mydb|dbusername|passwd||
<br>> 
<br>> Thank you for any comment
<br>> Dead Vil
<br>> 
<br>> 
<br>
<br></blockquote></body></html>