frank: thuban/Extensions/bboxdump __init__.py, 1.1, 1.2 bboxdump.py, 1.1, 1.2
cvs@intevation.de
cvs at intevation.de
Tue May 4 19:17:03 CEST 2004
Author: frank
Update of /thubanrepository/thuban/Extensions/bboxdump
In directory doto:/tmp/cvs-serv22494/Extensions/bboxdump
Modified Files:
__init__.py bboxdump.py
Log Message:
Extensions/bboxdump/__init__.py: Fixed string left over from
copying.
Extensions/bboxdump/bboxdump.py (bboxdump):
Use layer.ShapeStore().AllShapes() to loop over shapes instead of
xrange(layer.NumShapes()). Compile the bboxmessage from a list
of formatted outputs (string.join) instead of appending to the
message. Two progress bar dialogs to report progress on the sometimes
lenghty processing.
Index: __init__.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/bboxdump/__init__.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- __init__.py 22 Apr 2004 17:11:54 -0000 1.1
+++ __init__.py 4 May 2004 17:17:00 -0000 1.2
@@ -1,6 +1,6 @@
# Copyright (c) 2003 by Intevation GmbH
# Authors:
-# Jan-Oliver Wagner <jan at intevation.de>
+# Frank Koormann <frank at intevation.de>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with Thuban for details.
Index: bboxdump.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/bboxdump/bboxdump.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- bboxdump.py 22 Apr 2004 17:11:54 -0000 1.1
+++ bboxdump.py 4 May 2004 17:17:00 -0000 1.2
@@ -16,8 +16,8 @@
__version__ = '$Revision$'
import os, sys
+import string
-# only import GUI when not called as command line tool
from wxPython.wx import *
from wxPython.lib.dialogs import wxScrolledMessageDialog
@@ -29,6 +29,7 @@
import shapelib
import dbflib
+# Widget IDs
ID_FILENAME = 4001
ID_ATTRIBUTES = 4002
ID_SELFN = 4003
@@ -121,8 +122,7 @@
if bboxmessage:
dlg = wxScrolledMessageDialog(
self.parent, bboxmessage,
- _("Bounding Box Dump %s") % self.layer.Title()
- )
+ _("Bounding Box Dump %s") % self.layer.Title())
dlg.ShowModal()
def OnSelectFilename(self, event):
@@ -149,42 +149,74 @@
layer - Layer of shapes to be dumped
column - optional column to group shapes (else None)
filename - optional filename to dump into (else empty string, i.e. dump
- to stdio)
+ to message dialog)
"""
# Preparation
shapelist = {}
- bboxmessage = ""
+ bboxmessage = []
+ dlg= wxProgressDialog(_("Bounding Box Dump"),
+ _("Collecting shapes ..."),
+ layer.ShapeStore().NumShapes(),
+ None)
+
+ cnt = 0
+ step = int(layer.ShapeStore().NumShapes() / 100.0)
+ if step == 0:
+ step = 1
+
# Collect shape ids to be dumped
if column is None:
# A simple dump of shapes bbox is required
- for i in xrange(layer.NumShapes()):
+ for s in layer.ShapeStore().AllShapes():
+ i = s.ShapeID()
shapelist[i] = (i,)
+ if cnt % step == 0:
+ dlg.Update(cnt)
+ cnt = cnt + 1
else:
# group them by column ...
- for i in xrange(layer.NumShapes()):
+ for s in layer.ShapeStore().AllShapes():
+ i = s.ShapeID()
row = layer.ShapeStore().Table().ReadRowAsDict(i)
att = row[column.name]
if not shapelist.has_key(att):
shapelist[att] = []
shapelist[att].append(i)
+ if cnt % step == 0:
+ dlg.Update(cnt)
+ cnt = cnt + 1
+
+ dlg.Destroy()
+ dlg= wxProgressDialog(_("Bounding Box Dump"),
+ _("Dump bounding boxes of selected shapes ..."),
+ len(shapelist),
+ None)
+ cnt = 0
+ step = int(len(shapelist) / 100.0)
+ if step == 0:
+ step = 1
# Dump them, sorted
keys = shapelist.keys()
keys.sort()
for key in keys:
bbox = layer.ShapesBoundingBox(shapelist[key])
- bboxmessage = bboxmessage + "%.3f,%.3f,%.3f,%.3f,%s\n" % (
- bbox[0],bbox[1],bbox[2],bbox[3],key)
+ bboxmessage.append("%.3f,%.3f,%.3f,%.3f,%s\n" % (
+ bbox[0], bbox[1], bbox[2], bbox[3], key))
+ if cnt % step == 0:
+ dlg.Update(cnt)
+ cnt = cnt + 1
+ dlg.Destroy()
# finally
if filename != '':
- bboxfile = file(filename,'w+')
- bboxfile.write(bboxmessage)
+ bboxfile = file(filename, 'w+')
+ bboxfile.write(string.join(bboxmessage))
bboxfile.close()
return None
else:
- return bboxmessage
+ return string.join(bboxmessage)
def LayerBBoxDump(context):
"""Menu Handler BBoxDump
@@ -196,7 +228,7 @@
dlg.ShowModal()
-# gns2shp executed as an extension to Thuban
+# bboxdump executed as an extension to Thuban
# register the new command
registry.Add(Command('bboxdump', _('BBox Dump'), LayerBBoxDump,
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)