maposmatic-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Maposmatic-dev] [PATCH] Indexer: regroup street beginning with a digit


From: Étienne Loks
Subject: [Maposmatic-dev] [PATCH] Indexer: regroup street beginning with a digit into a single category
Date: Sun, 1 Apr 2012 02:36:40 +0200

---
 ocitysmap2/indexlib/commons.py |    2 ++
 ocitysmap2/indexlib/indexer.py |   13 +++++++++----
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/ocitysmap2/indexlib/commons.py b/ocitysmap2/indexlib/commons.py
index a91f0c1..6942577 100644
--- a/ocitysmap2/indexlib/commons.py
+++ b/ocitysmap2/indexlib/commons.py
@@ -37,6 +37,8 @@ class IndexDoesNotFitError(Exception):
     graphical area, even after trying smaller font sizes."""
     pass
 
+NUMBER_CATEGORY_NAME = '0-9'
+
 class IndexCategory:
     """
     The IndexCategory represents a set of index items that belong to the same
diff --git a/ocitysmap2/indexlib/indexer.py b/ocitysmap2/indexlib/indexer.py
index edd0d73..2702d2d 100644
--- a/ocitysmap2/indexlib/indexer.py
+++ b/ocitysmap2/indexlib/indexer.py
@@ -209,14 +209,19 @@ class StreetIndex:
 
         result = []
         current_category = None
+        NUMBER_LIST = [str(i) for i in xrange(10)]
         for street_name, linestring in sorted_sl:
-
             # Create new category if needed
             if (not current_category
                 or not self._i18n.first_letter_equal(street_name[0],
-                                                     current_category.name)):
-                current_category = commons.IndexCategory(
-                    self._i18n.upper_unaccent_string(street_name[0]))
+                                                     current_category.name)
+                or (current_category.name == commons.NUMBER_CATEGORY_NAME
+                    and not street_name[0] in NUMBER_LIST)):
+                if street_name[0] in NUMBER_LIST:
+                    cat_name = commons.NUMBER_CATEGORY_NAME
+                else:
+                    cat_name = self._i18n.upper_unaccent_string(street_name[0])
+                current_category = commons.IndexCategory(cat_name)
                 result.append(current_category)
 
             # Parse the WKT from the largest linestring in shape
-- 
1.7.9.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]