New list_areas function
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 17 Apr 2011 09:34:49 +0000 (09:34 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 17 Apr 2011 09:34:49 +0000 (09:34 +0000)
bin/area.py

index b0d8fbaf8cc8a0b0c43c613b7e577242edc56934..fc5324c9ec3801d6cc46095dcef77e3b9b35e1e1 100644 (file)
@@ -9,10 +9,13 @@ FIXME: It should works using polar coordinated, but now works in 2D.
 
 from __future__ import division
 
-__all__ = [ 'Area', 'load_area_from_kml_polygon' ]
+__all__ = [ 'Area', 'load_area_from_kml_polygon', 'list_areas' ]
 
+import os
 import re
 
+AREA_DIR = u'/var/lib/ais/areas/'
+
 class Area:
     """
     That class defines an area (on the Earth)
@@ -113,9 +116,23 @@ def load_area_from_kml_polygon(filename, reverse=False):
     assert area.check(), 'Polygon should be counter-clockwise and convex.'
     return area
 
+
+def list_areas():
+    """
+    return a list of areas as tupples:
+    [(nicename, fullpath), ...]
+    """
+    results = []
+    for filename in os.listdir(AREA_DIR):
+        if not filename.endswith(u'.kml'):
+            continue # ignore non-kml files
+        results.append((filename[:-4], AREA_DIR+filename))
+    return results
+    
 if __name__ == '__main__':
+    print list_areas()
+    pelagos = load_area_from_kml_polygon('/var/lib/ais/areas/pelagos.kml')
     # counter clock-wise : Positive
-    pelagos = load_area_from_kml_polygon_2('/var/lib/ais/areas/pelagos.kml')
     #pelagos = Area([
     #    (42.91, 12.5),
     #    (45.3612930132714, 10.01843703552244),