nhueffme: thuban/Extensions/ogr ogrdialog.py, 1.1, 1.2 ogrshapes.py, 1.4, 1.5 ogrstart.py, 1.3, 1.4
cvs@intevation.de
cvs at intevation.de
Tue Feb 8 10:52:58 CET 2005
Author: nhueffme
Update of /thubanrepository/thuban/Extensions/ogr
In directory doto:/tmp/cvs-serv26858/Extensions/ogr
Modified Files:
ogrdialog.py ogrshapes.py ogrstart.py
Log Message:
Changed the GUI. OGR support can now be accessed via the Map menu.
Removed some print commands.
Index: ogrdialog.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/ogr/ogrdialog.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ogrdialog.py 31 Jan 2005 09:18:27 -0000 1.1
+++ ogrdialog.py 8 Feb 2005 09:52:56 -0000 1.2
@@ -186,7 +186,7 @@
datasource = ogr.Open(filename)
self.layer = []
- for i in range(datasource.GetLayerCount()):
+ for i in range(datasource.GetLayerCount()):
self.layer.append(datasource.GetLayer(i))
self.lb_drivers.Append(datasource.GetLayer(i).GetName())
if self.lb_drivers.GetCount() > 0:
@@ -307,8 +307,14 @@
i = self.lb_connections.GetSelection()
if i >= 0:
self.selected_conn = self.dbconns[i]
- self.tables = self.selected_conn.GeometryTables()
- self.lb_tables.Set(self.tables)
+ connString = ("PG: host=%s dbname=%s user=%s port=%s"
+ %(self.selected_conn.host, self.selected_conn.dbname,
+ self.selected_conn.user, self.selected_conn.port))
+ ds = ogr.Open(connString)
+ if ds:
+ for i in range(ds.GetLayerCount()):
+ self.tables.append(ds.GetLayer(i).GetName())
+ self.lb_tables.Set(self.tables)
def OnTableSelect(self, event):
i = self.lb_tables.GetSelection()
Index: ogrshapes.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/ogr/ogrshapes.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ogrshapes.py 26 Jan 2005 09:17:01 -0000 1.4
+++ ogrshapes.py 8 Feb 2005 09:52:56 -0000 1.5
@@ -26,7 +26,7 @@
from Thuban.Model.data import SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT
from Thuban.Model.data import RAW_PYTHON, RAW_SHAPEFILE, RAW_WKT
-SHAPETYPE_UNKNOWN = "unknown"
+SHAPETYPE_UNKNOWN = ogr.wkbUnknown
def has_ogr_support():
"""Return whether this Thuban instance supports ogr file formats
@@ -54,15 +54,16 @@
def __init__(self, ogrlayer, shapeid):
self.ogrlayer = ogrlayer
+ self.feature = self.ogrlayer.GetFeature(shapeid)
self.shapeid = shapeid
+ self.geom = self.feature.GetGeometryRef()
+ self.shapetype = self.geom.GetGeometryType()
def compute_bbox(self):
"""
Return the bounding box of the shape as a tuple (minx,miny,maxx,maxy)
"""
- shape = self.ogrlayer.GetFeature(self.shapeid)
- geom = shape.GetGeometryRef()
- minx, maxx, miny, maxy = geom.GetEnvelope()
+ minx, maxx, miny, maxy = self.geom.GetEnvelope()
return (minx, miny, maxx, maxy)
def ShapeID(self):
@@ -70,39 +71,35 @@
def Points(self):
"""Return the coordinates of the shape as a list of lists of pairs"""
- print "FID: %s" %(self.shapeid)
shape = []
#spatialFilter = self.ogrlayer.GetSpatialFilter()
-
-# if spatialFilter is not None:
- self.ogrlayer.SetSpatialFilter(None)
- # feature = self.ogrlayer.GetFeature(self.shapeid)
- # self.ogrlayer.SetSpatialFilter(spatialFilter)
- # else:
- feature = self.ogrlayer.GetFeature(self.shapeid)
-
- if feature is None:
- print "feature is none.........................."
- return shape.append([])
- geom = feature.GetGeometryRef()
- if geom is None:
- print "geom is none................................"
+ #if spatialFilter is not None:
+ #self.ogrlayer.SetSpatialFilter(None)
+ #feature = self.ogrlayer.GetFeature(self.shapeid)
+ #self.ogrlayer.SetSpatialFilter(spatialFilter)
+ #else:
+ #feature = self.ogrlayer.GetFeature(self.shapeid)
+
+ #if feature is None:
+ # return shape.append([])
+ #geom = feature.GetGeometryRef()
+
+ if self.geom is None:
return shape.append([])
# if geometry object is of type point or line
- if geom.GetGeometryCount() == 0:
+ if self.geom.GetGeometryCount() == 0:
points =[]
- for point in range(geom.GetPointCount()):
- x = geom.GetX(point)
- y = geom.GetY(point)
+ for point in range(self.geom.GetPointCount()):
+ x = self.geom.GetX(point)
+ y = self.geom.GetY(point)
points.append((x, y))
- print points
return [points]
# if geometry object is of type polygon or multipolygon
- for i in range(geom.GetGeometryCount()):
+ for i in range(self.geom.GetGeometryCount()):
points = []
- geometry = geom.GetGeometryRef(i)
+ geometry = self.geom.GetGeometryRef(i)
# if geometry object is polygon
if geometry.GetGeometryCount() == 0:
for point in range(geometry.GetPointCount()):
@@ -120,7 +117,6 @@
y = subgeom.GetY(point)
points.append((x, y))
shape.append(points)
- print shape
return shape
def RawData(self):
@@ -131,6 +127,9 @@
"""Return the ogrlayer object"""
return self.ogrlayer
+ def ShapeType(self):
+ return self.shapetype
+
class OGRShapeStore:
@@ -138,7 +137,7 @@
providing all methods Thuban needs.
"""
- def __init__(self, session, filename, layername):
+ def __init__(self, filename, layername, id_column = None):
# Make the filename absolute. The filename will be
# interpreted relative to that anyway, but when saving a
# session we need to compare absolute paths and it's usually
@@ -173,8 +172,8 @@
if self.shapetype is not ogr.wkbUnknown:
self.shapetype = ogrlib_shapetypes[self.shapetype]
#else:
- # this should be ogr.wkbUnknown, but Thuban does not know how
- # to handle an unknown shapetype (e.g. Session Tree)
+ # this should be ogr.wkbUnknown, but Thuban does not know how
+ # to handle an unknown shapetype (e.g. Session Tree)
#self.shapetype = ogrlib_shapetypes[ogr.wkbPoint]
def OGRLayer(self):
@@ -223,10 +222,6 @@
ogrlayer = self.ogrlayer
left, bottom, right, top = bbox
- print "features in bbox: "
- print ('Polygon((%s %s, %s %s, %s %s,%s %s, %s %s))'
- %(left, bottom, left, top, right, top,
- right, bottom, left, bottom))
# create a geometry which can be passed to the layer as spatial filter
bboxpolygon = ogr.CreateGeometryFromWkt(
('Polygon((%s %s, %s %s, %s %s,%s %s, %s %s))'
@@ -239,11 +234,12 @@
ogrlayer.ResetReading()
#ogrlayer.SetSpatialFilterRect(left, bottom, right, top)
ogrlayer.SetSpatialFilter(bboxpolygon)
+
numFeatures = ogrlayer.GetFeatureCount()
- print numFeatures
for feature in range(numFeatures):
nextFeature = ogrlayer.GetNextFeature()
yield cls(ogrlayer, nextFeature.GetFID())
+
ogrlayer.SetSpatialFilter(None)
bboxpolygon.Destroy()
@@ -271,6 +267,9 @@
"""Return None."""
return None
+ def Id_column(self):
+ """Return the id_column."""
+ return self.id_column
class OGRTable:
@@ -483,6 +482,10 @@
if lay is not None:
self.datasource.ReleaseResultSet(lay)
return result
+
+ def Id_column(self):
+ """Return the id_column."""
+ return self.id_column
class OGRColumn:
Index: ogrstart.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/ogr/ogrstart.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ogrstart.py 26 Jan 2005 09:17:01 -0000 1.3
+++ ogrstart.py 8 Feb 2005 09:52:56 -0000 1.4
@@ -10,6 +10,7 @@
# $Id$
# Needed wx-toolkit classes
+#from wxPython.wx import *
from wxPython.wx import wxFileDialog, wxOPEN, wxMULTIPLE, wxID_OK, \
wxOK, wxICON_HAND
@@ -26,6 +27,8 @@
from Extensions.ogr import ogrshapes, ogrdialog
from Extensions.ogr.ogrdialog import ChooseOGRDBTableDialog
+from Thuban.UI.menu import Menu
+
def open_with_ogr(context):
'''Open a file supported by ogr.
'''
@@ -49,7 +52,7 @@
layername = layerDlg.GetLayer()
try:
session = context.application.Session()
- store = ogrshapes.OGRShapeStore(session, filename, layername)
+ store = ogrshapes.OGRShapeStore(filename, layername)
session.AddShapeStore(store)
except:
# the layer couldn't be opened
@@ -87,7 +90,7 @@
canvas = context.mainwindow.canvas
map = canvas.Map()
-
+
session = context.application.Session()
dlg = ChooseOGRDBTableDialog(canvas, session)
@@ -98,7 +101,7 @@
filename = ('PG: host=%s user=%s dbname=%s port=%s'
%(dbconn.host, dbconn.user, dbconn.dbname, dbconn.port))
- store = ogrshapes.OGRShapeStore(session, filename, dbtable)
+ store = ogrshapes.OGRShapeStore(filename, dbtable)
session.AddShapeStore(store)
layer = Layer(dbtable, store)
@@ -124,13 +127,17 @@
# See Thuban/UI/menu.py for the API of the Menu class
from Thuban.UI.mainwindow import main_menu
+
+# find the map menu (create it a new if not found)
+map_menu = main_menu.FindOrInsertMenu('map', _('Map'))
+ogr_menu = Menu("ogr", _("Open layer via OGR"),[])
+
+
# create new commands and register them
registry.Add(Command('open_ogr_files', 'Open an ogr-file', open_with_ogr,
helptext = 'Open a file supported from ogr'))
-# find the ogr menu (create it a new if not found)
-ogr_menu = main_menu.FindOrInsertMenu('ogr', _('OGR'))
-registry.Add(Command('select_file_format', 'Select a file format',
+registry.Add(Command('select_file_format', 'Select a file format',
select_file_format,
helptext = "Select a file format supported from ogr"))
@@ -139,7 +146,10 @@
helptext = "Open a layer from a database, e.g. PostGIS"))
# finally bind the new command with an entry in the extensions menu
-ogr_menu.InsertItem('open_ogr_files')
+ogr_menu.InsertItem("open_ogr_files")
ogr_menu.InsertItem('select_file_format')
ogr_menu.InsertItem('open_db')
+
+# Add ogr menu to map menu
+map_menu.InsertItem(ogr_menu, after = "rasterlayer_add")
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)