<html style="direction: ltr;">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<style type="text/css">body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
</head>
<body style="direction: ltr;" bidimailui-charset-is-forced="true"
bgcolor="#FFFFFF" text="#000000">
<br>
<br>
<div class="moz-cite-prefix">On 02/11/2016 00:25, Phillip Allen
wrote:<br>
</div>
<blockquote
cite="mid:CACUiXmhi2QO+Dro4wb_g-XXJ0ce05u+vfbXMabcgbTU3ewodJA@mail.gmail.com"
type="cite">
<div dir="ltr">Hi,<br>
<br>
I am writing a short python script to create a PostGIS table,
loop through a csv file, run a series of grass commands, then
save the final vector polygons to the PostGIS table. All of the
PostGIS commands were being issued by the db.execute. <br>
<br>
</div>
</blockquote>
If you want the GRASS vector to be exported to a PostGIS table
(including geometry) then you probably should be using v.out.ogr.<br>
IIUC db.execute is intended to save only the attributes to
PostgreSQL.<br>
<br>
<blockquote
cite="mid:CACUiXmhi2QO+Dro4wb_g-XXJ0ce05u+vfbXMabcgbTU3ewodJA@mail.gmail.com"
type="cite">
<div dir="ltr">In the code below I got the message:<br>
ERROR: Unable to open database
<host=localhost,dbname=ss_basin_test><br>
<br>
As seen in the 30th line I tried to send user & password
along with the database info but that gave an error as well.
When I tried to run db.login it said I had to use the
"overwrite" flag. If I overwrite the login info this script I
will have to reset it when I am done and I am not sure how to do
that. <br>
<br>
How do I connect to the db with db.execute and send the
user/password information?<br>
The first half of my code is below.<br>
<br>
thanks,<br>
<br>
Phil<br>
<br>
<br>
<br>
# IMPORT CSV & LOOP THROUGH COORDINATES FOR r.water.outlet<br>
import os<br>
import sys<br>
<br>
#set up GRASS environment variables<br>
sys.path.append(os.path.join(os.environ['GISBASE'], 'etc',
'python'))<br>
import grass.script as g<br>
import grass.script.setup as gsetup<br>
gisbase = os.environ['GISBASE']<br>
<br>
gisdb = 'E:\DEM_12_5\grassdata'<br>
location = 'dem_12_5'<br>
mapset = 'PERMANENT'<br>
<br>
# first join the new snap table's cat column to the original
attribute table<br>
# v.out.ascii input=th_ss_aem_snap_r5@PERMANENT type=point
output=C:\data\th_ss_aem_snap_r5.csv columns=COD_MUESTR
format=point separator=comma precision=20<br>
txtfile = 'c:/data/th_ss_aem_snap_r5.csv'<br>
txtfileWKT = 'c:/data/th_ss_aem_snap_r5_WKT.txt'<br>
pgsrid = '32618'<br>
<br>
pg_user = 'postgres'<br>
pg_user_pwd = 'xxxx'<br>
pg_schema = 'basin'<br>
pg_tbl_name = 'samp_basin'<br>
pg_host = 'localhost'<br>
pg_dbname = 'ss_basin_test'<br>
<br>
txt_pg_tbl_create = 'CREATE TABLE ' + pg_tbl_name + ' (x double
precision, y double precision, samp_id character varying(254)
PRIMARY KEY, geom geometry(POLYGON, ' + pgsrid + ') )'<br>
<br>
#txt_pg_db = 'host=' + pg_host + ',dbname=' + pg_dbname +
',user=' + pg_user + ',password=' + pg_user_pwd<br>
txt_pg_db = 'host=' + pg_host + ',dbname=' + pg_dbname<br>
<br>
gsetup.init(gisbase, gisdb, location, mapset)<br>
<br>
# Create PostGIS Polygon Table<br>
# g.run_command('db.login', driver='pg', user=pg_user,
password=pg_user_pwd )<br>
g.run_command('db.execute', sql=txt_pg_tbl_create , driver='pg',
database=txt_pg_db, schema=pg_schema)<br>
<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
grass-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/grass-user">http://lists.osgeo.org/mailman/listinfo/grass-user</a></pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Micha Silver
Arava Drainage Authority
+972-523-665918</pre>
</body>
</html>