Skip to content

Commit 52d5c22

Browse files
author
rblazek
committed
new script + qgis module for vector to PostGIS export, fix for #1190
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10899 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4616b62 commit 52d5c22

File tree

5 files changed

+152
-1
lines changed

5 files changed

+152
-1
lines changed

src/plugins/grass/config/default.qgc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
</section>
5353
<section label="Export vector">
5454
<grass name="v.out.ogr"/>
55-
<grass name="v.out.ogr.postgis"/>
55+
<grass name="qgis.v.out.ogr.pg"/>
5656
<grass name="v.out.ogr.gml"/>
5757
<grass name="v.out.ogr.mapinfo"/>
5858
<grass name="v.out.ascii"/>
Loading
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassmodule.dtd">
3+
4+
<qgisgrassmodule label="Export vector to PostGIS (PostgreSQL) database table." module="qgis.v.out.ogr.pg.py">
5+
<option key="input" layeroption="layer" typeoption="type" />
6+
<option key="olayer" />
7+
<option key="database" />
8+
<!--option key="schema" /-->
9+
<option key="host" />
10+
<option key="port"/>
11+
<option key="user"/>
12+
<option key="password"/>
13+
</qgisgrassmodule>
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/usr/bin/env python
2+
3+
############################################################################
4+
#
5+
# MODULE: qgis.v.out.ogr.pg.py
6+
# AUTHOR(S): Radim Blazek
7+
#
8+
# PURPOSE: Export a vectore to PostGIS (PostgreSQL) database table
9+
# COPYRIGHT: (C) 2009 by Radim Blazek
10+
#
11+
# This program is free software under the GNU General Public
12+
# License (>=v2). Read the file COPYING that comes with GRASS
13+
# for details.
14+
#
15+
#############################################################################
16+
17+
#%Module
18+
#% description: Export vector to PostGIS (PostgreSQL) database table.
19+
#% keywords: vector, export, database
20+
#%End
21+
22+
#%option
23+
#% key: input
24+
#% type: string
25+
#% gisprompt: old,vector,vector
26+
#% key_desc : name
27+
#% description: Name of input vector map
28+
#% required : yes
29+
#%end
30+
31+
#%option
32+
#% key: layer
33+
#% type: integer
34+
#% description: Number of input layer
35+
#% answer: 1
36+
#% required : yes
37+
#%end
38+
39+
#%option
40+
#% key: type
41+
#% type: string
42+
#% description: Feature type(s)
43+
#% options: point,kernel,centroid,line,boundary,area,face
44+
#% multiple: yes
45+
#% required : yes
46+
#%end
47+
48+
#%option
49+
#% key: olayer
50+
#% type: string
51+
#% description: Name of output database table
52+
#% required : yes
53+
#%end
54+
55+
#%option
56+
#% key: host
57+
#% type: string
58+
#% label: Host
59+
#% description: Host name of the machine on which the server is running.
60+
#% required : no
61+
#%end
62+
63+
#%option
64+
#% key: port
65+
#% type: integer
66+
#% label: Port
67+
#% description: TCP port on which the server is listening, usually 5432.
68+
#% required : no
69+
#%end
70+
71+
#%option
72+
#% key: database
73+
#% type: string
74+
#% key_desc : name
75+
#% gisprompt: old_dbname,dbname,dbname
76+
#% label: Database
77+
#% description: Database name
78+
#% required : yes
79+
#%end
80+
81+
# AFAIK scheme is not supported well by OGR
82+
##%option
83+
##% key: schema
84+
##% type: string
85+
##% label: Schema
86+
##% description: Database schema.
87+
##% required : no
88+
##%end
89+
90+
#%option
91+
#% key: user
92+
#% type: string
93+
#% label: User
94+
#% description: Connect to the database as the user username instead of the default.
95+
#% required : no
96+
#%end
97+
98+
#%option
99+
#% key: password
100+
#% type: string
101+
#% label: Password
102+
#% description: Password will be stored in file!
103+
#% required : no
104+
#%end
105+
106+
import sys
107+
import os
108+
import string
109+
try:
110+
import grass
111+
except:
112+
raise Exception ("Cannot find 'grass' Python module. Python is supported by GRASS from version 6.4" )
113+
114+
def main():
115+
input = options['input']
116+
layer = options['layer']
117+
type = options['type']
118+
olayer = options['olayer']
119+
host = options['host']
120+
port = options['port']
121+
database = options['database']
122+
#schema = options['schema']
123+
user = options['user']
124+
password = options['password']
125+
126+
# Construct dsn string
127+
dsn = "PG:dbname=" + database
128+
if host: dsn += " host=" + host
129+
if port: dsn += " port=" + port
130+
if user: dsn += " user=" + user
131+
if password: dsn += " password=" + password
132+
133+
if grass.run_command('v.out.ogr', input=input, layer=layer, type=type, format="PostgreSQL", dsn=dsn, olayer=olayer ) != 0:
134+
grass.fatal("Cannot export vector to database.")
135+
136+
if __name__ == "__main__":
137+
options, flags = grass.parser()
138+
main()

0 commit comments

Comments
 (0)