[Thuban-commits] r2850 - in trunk/thuban: Extensions/importMP Thuban

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Jun 25 07:16:09 CEST 2008


Author: elachuni
Date: 2008-06-25 07:16:09 +0200 (Wed, 25 Jun 2008)
New Revision: 2850

Added:
   trunk/thuban/Extensions/importMP/README
Modified:
   trunk/thuban/Extensions/importMP/importMP.py
   trunk/thuban/Extensions/importMP/pfm.py
   trunk/thuban/Thuban/thuban_cfg.py
Log:
Several small documentation and style improvements.



Added: trunk/thuban/Extensions/importMP/README
===================================================================
--- trunk/thuban/Extensions/importMP/README	2008-06-25 03:58:27 UTC (rev 2849)
+++ trunk/thuban/Extensions/importMP/README	2008-06-25 05:16:09 UTC (rev 2850)
@@ -0,0 +1,11 @@
+This extension imports Polish Map Files, the format used by Garmin GPS
+receivers.
+
+There's quite a complete description of the format here
+http://www.cgpsmapper.com/download/cGPSmapper-UsrMan-v02.4.pdf
+
+The extension works by first creating shapefiles that represent the data in the
+MP file and then loading the shapefiles in to thuban, so it effectively works
+like a MP to Shapefile converter, also.
+
+

Modified: trunk/thuban/Extensions/importMP/importMP.py
===================================================================
--- trunk/thuban/Extensions/importMP/importMP.py	2008-06-25 03:58:27 UTC (rev 2849)
+++ trunk/thuban/Extensions/importMP/importMP.py	2008-06-25 05:16:09 UTC (rev 2850)
@@ -1,3 +1,13 @@
+# Copyright (c) 2008 by Intevation GmbH
+# Authors:
+# Anthony Lenton <anthony at except.com.ar>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with Thuban for details.
+
+""" A Polish Map File parser.  This module contains the UI and shapefile
+    saving code . """
+
 import os
 import wx
 
@@ -8,7 +18,8 @@
     from Thuban.UI import internal_from_wxstring
 
 from Thuban.Model.layer import Layer
-from Thuban.Model.classification import Classification, ClassGroupProperties, ClassGroupSingleton
+from Thuban.Model.classification import Classification, ClassGroupProperties
+from Thuban.Model.classification import ClassGroupSingleton
 from Thuban.Model.color import Color
 import shapelib
 import dbflib
@@ -29,7 +40,8 @@
     poi_dbf = dbflib.open(poi_dbf_filename, 'r+b')
     i = 0
     for poi in parser.pois:
-        obj = shapelib.SHPObject(shapelib.SHPT_POINT, i, [[(poi['long'], poi['lat'])]])
+        obj = shapelib.SHPObject(shapelib.SHPT_POINT, i,
+                                 [[(poi['long'], poi['lat'])]])
         poi_shp.write_object(-1, obj)
         poi_dbf.write_record(i, { 'Label': poi.get('Label', '') })
         i += 1
@@ -48,7 +60,8 @@
     for poly in parser.polygons:
         if poly['Type'].lower() == '0x4b': # Skip background
             continue
-        obj = shapelib.SHPObject(shapelib.SHPT_POLYGON, i, [zip (poly['long'], poly['lat'])])
+        obj = shapelib.SHPObject(shapelib.SHPT_POLYGON, i,
+                                 [zip (poly['long'], poly['lat'])])
         polygon_shp.write_object(-1, obj)
         polygon_dbf.write_record(i, {'Label': poly.get('Label', ''),
                                      'Type': poly.get('parsedType', '')})
@@ -67,10 +80,11 @@
     i = 0
     for poly in parser.polygons:
         if poly['Type'].lower() == '0x4b': # Process background
-            obj = shapelib.SHPObject(shapelib.SHPT_POLYGON, i, [zip (poly['long'], poly['lat'])])
+            obj = shapelib.SHPObject(shapelib.SHPT_POLYGON, i,
+                                     [zip (poly['long'], poly['lat'])])
             bg_shp.write_object(-1, obj)
             bg_dbf.write_record(i, {'Label': poly.get('Label', ''),
-                                      'Type': poly.get('Type', '')})
+                                    'Type': poly.get('Type', '')})
             i += 1
     del bg_shp
     del bg_dbf
@@ -85,16 +99,19 @@
     road_dbf = dbflib.open(road_dbf_filename, 'r+b')
     i = 0
     for poly in parser.polylines:
-            obj = shapelib.SHPObject(shapelib.SHPT_ARC, i, [zip (poly['long'], poly['lat'])])
-            road_shp.write_object(-1, obj)
-            road_dbf.write_record(i, {'Label': poly.get('Label', ''),
-                                      'Type': poly.get('parsedType', '')})
-            i += 1
+        obj = shapelib.SHPObject(shapelib.SHPT_ARC,
+                                 i, [zip (poly['long'], poly['lat'])])
+        road_shp.write_object(-1, obj)
+        road_dbf.write_record(i, {'Label': poly.get('Label', ''),
+                                  'Type': poly.get('parsedType', '')})
+        i += 1
     del road_shp
     del road_dbf
     return parser
 
 def getPolygonClassification(polygons):
+    """ Returns a Classification with the needed ClassGroups to describe the
+        provided polygons """
     clazz = Classification()
     waterProps = ClassGroupProperties()
     waterProps.SetFill (Color (0.7, 0.7, 1))
@@ -139,6 +156,8 @@
     return clazz
 
 def getPolylineClassification(polylines):
+    """ Returns a Classification with the needed ClassGroups to describe the
+        provided polylines """
     clazz = Classification()
     waterProps = ClassGroupProperties()
     waterProps.SetLineColor (Color (0.5, 0.5, 0.8))
@@ -165,7 +184,7 @@
                  'Major Highway-thick': majorProps,
                  'Principal Highway-medium': majorProps, 'River': waterProps,
                  'International Boundary': boundProps,
-                 'County Boundary': boundProps, 'Political Boundary': boundProps,
+                 'County Boundary': boundProps, 'Political Boundary':boundProps,
                  'Ferry': waterProps, 'Bridge': roadProps, 'Road': roadProps,
                  'Stream-thin': waterProps, 'Track/Trail': earthProps,
                  'Railroad': railProps, 'Unpaved Road-thin': earthProps,
@@ -181,6 +200,8 @@
     return clazz
 
 def getBackgroundClassification():
+    """ Returns a Classification with a ClassGroup for the
+        background polygon """
     clazz = Classification()
     bgProps = ClassGroupProperties()
     bgProps.SetFill (Color (1, 1, 0.9))
@@ -273,8 +294,8 @@
         context.mainwindow.canvas.FitMapToWindow()
 
 # register the new command
-registry.Add(Command('import-mp', _("(experimental) ")+_('Import PFM-file'), import_mp_dialog,
-                         helptext = _('Import a Polish Map File')))
+registry.Add(Command('import-mp', _("(experimental) ") + _('Import PFM-file'),
+                     import_mp_dialog, helptext=_('Import a Polish Map File')))
 
 # find the extension menu (create it anew if not found)
 extensions_menu = main_menu.FindOrInsertMenu('extensions',

Modified: trunk/thuban/Extensions/importMP/pfm.py
===================================================================
--- trunk/thuban/Extensions/importMP/pfm.py	2008-06-25 03:58:27 UTC (rev 2849)
+++ trunk/thuban/Extensions/importMP/pfm.py	2008-06-25 05:16:09 UTC (rev 2850)
@@ -5,7 +5,8 @@
 # This program is free software under the GPL (>=v2)
 # Read the file COPYING coming with Thuban for details.
 
-""" A Polish Map File parser """
+""" A Polish Map File parser.  This module contains the MPParser class, 
+    that does the real weight lifting for the importMP module. """
 
 import re
 
@@ -18,6 +19,7 @@
     def __repr__(self):
         return "Line %d: %s" % (self.lineNumber, repr(self.reason))
 
+# These dictionaries should probably be moved in to a separate file
 polylineTypes = {'0x01': 'Major Highway-thick',
                  '0x02': 'Principal Highway-thick',
                  '0x03': 'Principal Highway-medium',
@@ -216,6 +218,11 @@
                 '0x0704': 'Fishing Hot Spots chart'}
 
 class MPParser(object):
+    """ Polish Map File parser.  The main method is 'parse', which
+        receives a file object as its single argument.  The results of
+        the parsing can then be retrieved via 'pois', 'polygons', 'polylines',
+        and other attributes.
+    """
     fields = {'poi': ['Data0', 'Label', 'Origin0'],
               'rgn10': ['Data0', 'Label', 'Origin0'],
               'rgn20': ['Data0', 'Label', 'Origin0'],
@@ -233,6 +240,11 @@
         self.mapName = ""
 
     def parse (self, fp):
+        """ Parse a map file. 'fp' should be a readable file object.
+            After parsing the results can be accessed using 'pois', 'polylines',
+            'polygons', and other attributes.
+            Returns a dictionary with the results of the parsing, but this can
+            be most often discarded directly """
         def sectionBounder (line):
             return line[0] == '[' and line[-1] == ']'
         def sectionEnd (line):

Modified: trunk/thuban/Thuban/thuban_cfg.py
===================================================================
--- trunk/thuban/Thuban/thuban_cfg.py	2008-06-25 03:58:27 UTC (rev 2849)
+++ trunk/thuban/Thuban/thuban_cfg.py	2008-06-25 05:16:09 UTC (rev 2850)
@@ -30,6 +30,11 @@
     print x
 
 try:
+    import Extensions.importMP
+except Exception, x:
+    print x
+
+try:
     import Extensions.mouseposition
 except Exception, x:
     print x



More information about the Thuban-commits mailing list