-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new script + qgis module for vector to PostGIS export, fix for #1190
git-svn-id: http://svn.osgeo.org/qgis/trunk@10899 c8812cc2-4d05-0410-92ff-de0c093fc19c
- Loading branch information
rblazek
committed
Jun 10, 2009
1 parent
ca4fa4e
commit 80ac2f0
Showing
5 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassmodule.dtd"> | ||
|
||
<qgisgrassmodule label="Export vector to PostGIS (PostgreSQL) database table." module="qgis.v.out.ogr.pg.py"> | ||
<option key="input" layeroption="layer" typeoption="type" /> | ||
<option key="olayer" /> | ||
<option key="database" /> | ||
<!--option key="schema" /--> | ||
<option key="host" /> | ||
<option key="port"/> | ||
<option key="user"/> | ||
<option key="password"/> | ||
</qgisgrassmodule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#!/usr/bin/env python | ||
|
||
############################################################################ | ||
# | ||
# MODULE: qgis.v.out.ogr.pg.py | ||
# AUTHOR(S): Radim Blazek | ||
# | ||
# PURPOSE: Export a vectore to PostGIS (PostgreSQL) database table | ||
# COPYRIGHT: (C) 2009 by Radim Blazek | ||
# | ||
# This program is free software under the GNU General Public | ||
# License (>=v2). Read the file COPYING that comes with GRASS | ||
# for details. | ||
# | ||
############################################################################# | ||
|
||
#%Module | ||
#% description: Export vector to PostGIS (PostgreSQL) database table. | ||
#% keywords: vector, export, database | ||
#%End | ||
|
||
#%option | ||
#% key: input | ||
#% type: string | ||
#% gisprompt: old,vector,vector | ||
#% key_desc : name | ||
#% description: Name of input vector map | ||
#% required : yes | ||
#%end | ||
|
||
#%option | ||
#% key: layer | ||
#% type: integer | ||
#% description: Number of input layer | ||
#% answer: 1 | ||
#% required : yes | ||
#%end | ||
|
||
#%option | ||
#% key: type | ||
#% type: string | ||
#% description: Feature type(s) | ||
#% options: point,kernel,centroid,line,boundary,area,face | ||
#% multiple: yes | ||
#% required : yes | ||
#%end | ||
|
||
#%option | ||
#% key: olayer | ||
#% type: string | ||
#% description: Name of output database table | ||
#% required : yes | ||
#%end | ||
|
||
#%option | ||
#% key: host | ||
#% type: string | ||
#% label: Host | ||
#% description: Host name of the machine on which the server is running. | ||
#% required : no | ||
#%end | ||
|
||
#%option | ||
#% key: port | ||
#% type: integer | ||
#% label: Port | ||
#% description: TCP port on which the server is listening, usually 5432. | ||
#% required : no | ||
#%end | ||
|
||
#%option | ||
#% key: database | ||
#% type: string | ||
#% key_desc : name | ||
#% gisprompt: old_dbname,dbname,dbname | ||
#% label: Database | ||
#% description: Database name | ||
#% required : yes | ||
#%end | ||
|
||
# AFAIK scheme is not supported well by OGR | ||
##%option | ||
##% key: schema | ||
##% type: string | ||
##% label: Schema | ||
##% description: Database schema. | ||
##% required : no | ||
##%end | ||
|
||
#%option | ||
#% key: user | ||
#% type: string | ||
#% label: User | ||
#% description: Connect to the database as the user username instead of the default. | ||
#% required : no | ||
#%end | ||
|
||
#%option | ||
#% key: password | ||
#% type: string | ||
#% label: Password | ||
#% description: Password will be stored in file! | ||
#% required : no | ||
#%end | ||
|
||
import sys | ||
import os | ||
import string | ||
try: | ||
import grass | ||
except: | ||
raise Exception ("Cannot find 'grass' Python module. Python is supported by GRASS from version 6.4" ) | ||
|
||
def main(): | ||
input = options['input'] | ||
layer = options['layer'] | ||
type = options['type'] | ||
olayer = options['olayer'] | ||
host = options['host'] | ||
port = options['port'] | ||
database = options['database'] | ||
#schema = options['schema'] | ||
user = options['user'] | ||
password = options['password'] | ||
|
||
# Construct dsn string | ||
dsn = "PG:dbname=" + database | ||
if host: dsn += " host=" + host | ||
if port: dsn += " port=" + port | ||
if user: dsn += " user=" + user | ||
if password: dsn += " password=" + password | ||
|
||
if grass.run_command('v.out.ogr', input=input, layer=layer, type=type, format="PostgreSQL", dsn=dsn, olayer=olayer ) != 0: | ||
grass.fatal("Cannot export vector to database.") | ||
|
||
if __name__ == "__main__": | ||
options, flags = grass.parser() | ||
main() |