maposmatic-dev
[Top][All Lists]
Advanced

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

[Maposmatic-dev] [PATCH] don't ever try to lookup non-admin boundaries i


From: David Decotigny
Subject: [Maposmatic-dev] [PATCH] don't ever try to lookup non-admin boundaries in the DB
Date: Mon, 21 Dec 2009 01:06:39 +0100

---
 www/maposmatic/nominatim.py |   36 +++++++++++++++++++++---------------
 1 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/www/maposmatic/nominatim.py b/www/maposmatic/nominatim.py
index 133cab5..168f2c6 100644
--- a/www/maposmatic/nominatim.py
+++ b/www/maposmatic/nominatim.py
@@ -122,6 +122,9 @@ def _retrieve_missing_data_from_GIS(entries):
     try:
         cursor = conn.cursor()
         for entry in entries:
+            # Should we try to lookup the id in the OSM DB ?
+            lookup_OSM = False
+
             # Highest priority index = last in the output
             entry_priority = 1000
 
@@ -130,6 +133,7 @@ def _retrieve_missing_data_from_GIS(entries):
                 if entry.get("type") == "administrative":
                     entry_priority = 10
                     admin_boundary_names.add(entry.get("display_name", 42))
+                    lookup_OSM = True
                 else:
                     # Just don't try to lookup any additional
                     # information from OSM when the nominatim entry is
@@ -145,21 +149,23 @@ def _retrieve_missing_data_from_GIS(entries):
                 # We ignore all the other classes
                 continue
 
-            for table_name in ("polygon", "line"):
-                # Lookup the polygon/line table for both osm_id and
-                # the opposite of osm_id
-                cursor.execute("""select osm_id, admin_level
-                                  from planet_osm_%s
-                                  where osm_id in (%s,-%s)""" \
-                                   % (table_name,
-                                      entry["osm_id"],entry["osm_id"]))
-                result = tuple(set(cursor.fetchall()))
-                if len(result) == 1:
-                    entry["ocitysmap_params"] = dict(table=table_name,
-                                                     id=result[0][0],
-                                                     admin_level=result[0][1])
-                    entry_priority = 0 # Make these first in list
-                    break
+            # Try to lookup in the OSM DB, when needed
+            if lookup_OSM:
+                for table_name in ("polygon", "line"):
+                    # Lookup the polygon/line table for both osm_id and
+                    # the opposite of osm_id
+                    cursor.execute("""select osm_id, admin_level
+                                      from planet_osm_%s
+                                      where osm_id in (%s,-%s)""" \
+                                       % (table_name,
+                                          entry["osm_id"],entry["osm_id"]))
+                    result = tuple(set(cursor.fetchall()))
+                    if len(result) == 1:
+                        entry["ocitysmap_params"] = dict(table=table_name,
+                                                         id=result[0][0],
+                                                         
admin_level=result[0][1])
+                        entry_priority = 0 # Make these first in list
+                        break
 
             # Register this entry for the results
             unsorted_entries.append((entry_priority, entry))
-- 
1.6.3.3





reply via email to

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