10 |
# $Id$ |
# $Id$ |
11 |
|
|
12 |
# Needed wx-toolkit classes |
# Needed wx-toolkit classes |
13 |
|
#from wxPython.wx import * |
14 |
from wxPython.wx import wxFileDialog, wxOPEN, wxMULTIPLE, wxID_OK, \ |
from wxPython.wx import wxFileDialog, wxOPEN, wxMULTIPLE, wxID_OK, \ |
15 |
wxOK, wxICON_HAND |
wxOK, wxICON_HAND |
16 |
|
|
27 |
from Extensions.ogr import ogrshapes, ogrdialog |
from Extensions.ogr import ogrshapes, ogrdialog |
28 |
from Extensions.ogr.ogrdialog import ChooseOGRDBTableDialog |
from Extensions.ogr.ogrdialog import ChooseOGRDBTableDialog |
29 |
|
|
30 |
|
from Thuban.UI.menu import Menu |
31 |
|
|
32 |
def open_with_ogr(context): |
def open_with_ogr(context): |
33 |
'''Open a file supported by ogr. |
'''Open a file supported by ogr. |
34 |
''' |
''' |
52 |
layername = layerDlg.GetLayer() |
layername = layerDlg.GetLayer() |
53 |
try: |
try: |
54 |
session = context.application.Session() |
session = context.application.Session() |
55 |
store = ogrshapes.OGRShapeStore(session, filename, layername) |
store = ogrshapes.OGRShapeStore(filename, layername) |
56 |
session.AddShapeStore(store) |
session.AddShapeStore(store) |
57 |
except: |
except: |
58 |
# the layer couldn't be opened |
# the layer couldn't be opened |
90 |
|
|
91 |
canvas = context.mainwindow.canvas |
canvas = context.mainwindow.canvas |
92 |
map = canvas.Map() |
map = canvas.Map() |
93 |
|
|
94 |
session = context.application.Session() |
session = context.application.Session() |
95 |
dlg = ChooseOGRDBTableDialog(canvas, session) |
dlg = ChooseOGRDBTableDialog(canvas, session) |
96 |
|
|
101 |
filename = ('PG: host=%s user=%s dbname=%s port=%s' |
filename = ('PG: host=%s user=%s dbname=%s port=%s' |
102 |
%(dbconn.host, dbconn.user, dbconn.dbname, dbconn.port)) |
%(dbconn.host, dbconn.user, dbconn.dbname, dbconn.port)) |
103 |
|
|
104 |
store = ogrshapes.OGRShapeStore(session, filename, dbtable) |
store = ogrshapes.OGRShapeStore(filename, dbtable) |
105 |
session.AddShapeStore(store) |
session.AddShapeStore(store) |
106 |
|
|
107 |
layer = Layer(dbtable, store) |
layer = Layer(dbtable, store) |
127 |
# See Thuban/UI/menu.py for the API of the Menu class |
# See Thuban/UI/menu.py for the API of the Menu class |
128 |
from Thuban.UI.mainwindow import main_menu |
from Thuban.UI.mainwindow import main_menu |
129 |
|
|
130 |
|
|
131 |
|
# find the map menu (create it a new if not found) |
132 |
|
map_menu = main_menu.FindOrInsertMenu('map', _('Map')) |
133 |
|
ogr_menu = Menu("ogr", _("Open layer via OGR"),[]) |
134 |
|
|
135 |
|
|
136 |
# create new commands and register them |
# create new commands and register them |
137 |
registry.Add(Command('open_ogr_files', 'Open an ogr-file', open_with_ogr, |
registry.Add(Command('open_ogr_files', 'Open an ogr-file', open_with_ogr, |
138 |
helptext = 'Open a file supported from ogr')) |
helptext = 'Open a file supported from ogr')) |
139 |
|
|
140 |
# find the ogr menu (create it a new if not found) |
registry.Add(Command('select_file_format', 'Select a file format', |
|
ogr_menu = main_menu.FindOrInsertMenu('ogr', _('OGR')) |
|
|
registry.Add(Command('select_file_format', 'Select a file format', |
|
141 |
select_file_format, |
select_file_format, |
142 |
helptext = "Select a file format supported from ogr")) |
helptext = "Select a file format supported from ogr")) |
143 |
|
|
146 |
helptext = "Open a layer from a database, e.g. PostGIS")) |
helptext = "Open a layer from a database, e.g. PostGIS")) |
147 |
|
|
148 |
# finally bind the new command with an entry in the extensions menu |
# finally bind the new command with an entry in the extensions menu |
149 |
ogr_menu.InsertItem('open_ogr_files') |
ogr_menu.InsertItem("open_ogr_files") |
150 |
ogr_menu.InsertItem('select_file_format') |
ogr_menu.InsertItem('select_file_format') |
151 |
ogr_menu.InsertItem('open_db') |
ogr_menu.InsertItem('open_db') |
152 |
|
|
153 |
|
# Add ogr menu to map menu |
154 |
|
map_menu.InsertItem(ogr_menu, after = "rasterlayer_add") |
155 |
|
|