1 |
# Copyright (c) 2004 by Intevation GmbH |
# Copyright (c) 2004,2006 by Intevation GmbH vim:encoding=latin-1: |
2 |
# Authors: |
# Authors: |
3 |
# Nina H�ffmeyer <[email protected]> |
# Nina Hüffmeyer <[email protected]> |
4 |
# |
# |
5 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
6 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
9 |
# $Source$ |
# $Source$ |
10 |
# $Id$ |
# $Id$ |
11 |
|
|
12 |
# Needed wx-toolkit classes |
# Needed wx.-toolkit classes |
13 |
from wxPython.wx import wxFileDialog, wxOPEN, wxMULTIPLE, wxID_OK |
import wx |
14 |
|
|
15 |
# We need os.path |
# We need os.path |
16 |
import os |
import os |
34 |
map = canvas.Map() |
map = canvas.Map() |
35 |
|
|
36 |
# Get the file to be opened |
# Get the file to be opened |
37 |
dlg = wxFileDialog(canvas, _("Select a data file"), |
dlg = wx.FileDialog(canvas, _("Select a data file"), |
38 |
context.application.Path("data"), "", |
context.application.Path("data"), "", |
39 |
_("Shapefiles (*.shp)") + "|*.shp|" + |
_("Shapefiles (*.shp)") + "|*.shp|" + |
40 |
_("GML files (*.gml)") + "|*.gml|" + |
_("GML files (*.gml)") + "|*.gml|" + |
42 |
_("DGN files (*.dgn)") + "|*.dgn|" + |
_("DGN files (*.dgn)") + "|*.dgn|" + |
43 |
_("CSV files (*.csv)") + "|*.csv|" + |
_("CSV files (*.csv)") + "|*.csv|" + |
44 |
_("All Files (*.*)") + "|*.*|", |
_("All Files (*.*)") + "|*.*|", |
45 |
wxOPEN | wxMULTIPLE) |
wx.OPEN | wx.MULTIPLE) |
46 |
|
|
47 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
48 |
filenames = dlg.GetPaths() |
filenames = dlg.GetPaths() |
49 |
for filename in filenames: |
for filename in filenames: |
50 |
title = os.path.splitext(os.path.basename(filename))[0] |
title = os.path.splitext(os.path.basename(filename))[0] |
51 |
has_layers = map.HasLayers() |
has_layers = map.HasLayers() |
52 |
layerDlg = ogrdialog.ChooseLayer(canvas, filename) |
layerDlg = ogrdialog.ChooseLayer(canvas, filename) |
53 |
if layerDlg.ShowModal() == wxID_OK: |
if layerDlg.ShowModal() == wx.ID_OK: |
54 |
layername = layerDlg.GetLayer() |
layername = layerDlg.GetLayer() |
55 |
try: |
try: |
56 |
session = context.application.Session() |
session = context.application.Session() |
57 |
store = OpenFileShapestore(session, filename, layername) |
store = OpenFileShapestore(context.mainwindow, session, |
58 |
|
filename, layername) |
59 |
session.AddShapeStore(store) |
session.AddShapeStore(store) |
60 |
except: |
except: |
61 |
# the layer couldn't be opened |
# the layer couldn't be opened |
62 |
context.mainwindow.RunMessageBox(("Add Layer"), |
context.mainwindow.RunMessageBox(_("Add Layer"), |
63 |
("Can't open the file '%s'.")%filename) |
_("Can't open the file '%s'.") % filename) |
64 |
else: |
else: |
65 |
if store is not None: |
if store is not None: |
66 |
layer = Layer(title, store) |
layer = Layer(title, store) |
84 |
|
|
85 |
dlg = ogrdialog.ChooseFileFormat(canvas, session) |
dlg = ogrdialog.ChooseFileFormat(canvas, session) |
86 |
|
|
87 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
88 |
pass |
pass |
89 |
dlg.Destroy() |
dlg.Destroy() |
90 |
|
|
98 |
session = context.application.Session() |
session = context.application.Session() |
99 |
dlg = ChooseOGRDBTableDialog(canvas, session) |
dlg = ChooseOGRDBTableDialog(canvas, session) |
100 |
|
|
101 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
102 |
dbconn, connString, dbtable, id_column = dlg.GetTable() |
dbconn, connString, dbtable, id_column = dlg.GetTable() |
103 |
try: |
try: |
104 |
store = OpenDBShapestore(session, dbconn, dbtable, id_column, |
store = OpenDBShapestore(session, dbconn, dbtable, id_column, |
126 |
session = context.application.Session() |
session = context.application.Session() |
127 |
dlg = ogrdialog.OGRConnectionDialog(canvas, session) |
dlg = ogrdialog.OGRConnectionDialog(canvas, session) |
128 |
|
|
129 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
130 |
dsname = dlg.GetDatasourceName() |
dsname = dlg.GetDatasourceName() |
131 |
|
|
132 |
layerDlg = ogrdialog.ChooseLayer(canvas, dsname) |
layerDlg = ogrdialog.ChooseLayer(canvas, dsname) |
133 |
if layerDlg.ShowModal() == wxID_OK: |
if layerDlg.ShowModal() == wx.ID_OK: |
134 |
layername = layerDlg.GetLayer() |
layername = layerDlg.GetLayer() |
135 |
try: |
try: |
136 |
store = ogrshapes.OGRShapeStore(session, dsname, layername) |
store = ogrshapes.OGRShapeStore(session, dsname, layername) |
149 |
canvas.FitMapToWindow() |
canvas.FitMapToWindow() |
150 |
dlg.Destroy() |
dlg.Destroy() |
151 |
|
|
152 |
def OpenFileShapestore(session, filename, layername): |
def OpenFileShapestore(mainwindow, session, filename, layername): |
153 |
"""Open a datasource and add the required layer. |
"""Open a datasource and add the required layer. |
154 |
""" |
""" |
155 |
try: |
try: |
156 |
store = ogrshapes.OGRShapeStore(session, filename, layername) |
store = ogrshapes.OGRFileShapeStore(session, filename, layername) |
157 |
return store |
return store |
158 |
except: |
except: |
159 |
# Some error occured while initializing the layer |
# Some error occured while initializing the layer |
160 |
context.mainwindow.RunMessageBox(_("Open datasource"), |
mainwindow.RunMessageBox(_("Open datasource"), |
161 |
_("Can't open the datasource '%s'") |
_("Can't open the datasource '%s'") |
162 |
% filename) |
% filename) |
163 |
else: |
return None |
|
return null |
|
164 |
|
|
165 |
def OpenDBShapestore(session, dbconn, layername, id_column, geo_column): |
def OpenDBShapestore(session, dbconn, layername, id_column, geo_column): |
166 |
"""Open a datasource and add the required layer. |
"""Open a datasource and add the required layer. |
199 |
|
|
200 |
|
|
201 |
# find the map menu (create a new if not found) |
# find the map menu (create a new if not found) |
202 |
map_menu = main_menu.FindOrInsertMenu('map', _('Map')) |
#map_menu = main_menu.FindOrInsertMenu('map', _('Map')) |
203 |
ogr_menu = Menu("ogr", _("Open layer via OGR"),[]) |
#ogr_menu = Menu("ogr", _("Open layer via OGR"),[]) |
204 |
|
# as long as there we are not stable, better add to "Extentions" marked "beta" |
205 |
|
map_menu = main_menu.FindOrInsertMenu('extensions', _('E&xtensions')) |
206 |
|
ogr_menu = Menu("ogr", _("(testing) Open layer via OGR"),[]) |
207 |
|
|
208 |
|
|
209 |
ogrsupport = ogrshapes.has_ogr_support() |
ogrsupport = ogrshapes.has_ogr_support() |
210 |
|
|