maposmatic-dev
[Top][All Lists]
Advanced

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

[Maposmatic-dev] [PATCH] Adding bounding box coords (SRS 4326)


From: Pierre Mauduit
Subject: [Maposmatic-dev] [PATCH] Adding bounding box coords (SRS 4326)
Date: Thu, 5 Aug 2010 00:46:55 +0200

This would allow us to check if the BBox of the current feature is too large ; 
this needs jQuery's update,
which should come with Thomas' patches
---
 www/maposmatic/nominatim.py |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/www/maposmatic/nominatim.py b/www/maposmatic/nominatim.py
index f4f8726..691b2bf 100644
--- a/www/maposmatic/nominatim.py
+++ b/www/maposmatic/nominatim.py
@@ -33,6 +33,7 @@ Simple API to query http://nominatim.openstreetmap.org
 Most of the credits should go to gthe Nominatim team.
 """
 
+import json
 import www.settings
 import psycopg2
 from urllib import urlencode
@@ -194,17 +195,25 @@ def _retrieve_missing_data_from_GIS(entries):
                 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, way_area
+                    cursor.execute("""select osm_id, admin_level, way_area,
+                                      
ST_AsGeoJSON(ST_Envelope(ST_Transform(way,
+                                      4326))) AS JsonBBox
                                       from planet_osm_%s
                                       where osm_id = -%s""" \
                                        % (table_name,entry["osm_id"]))
                     result = tuple(set(cursor.fetchall()))
                     if len(result) == 1:
-                        osm_id, admin_level, way_area = result[0]
+                        osm_id, admin_level, way_area, geojsonbbox = result[0]
+                        bbox = json.loads(geojsonbbox)
+                        minx = str(bbox['coordinates'][0][0][0])
+                        miny = str(bbox['coordinates'][0][0][1])
+                        maxx = str(bbox['coordinates'][0][2][0])
+                        maxy = str(bbox['coordinates'][0][1][1])
                         entry["ocitysmap_params"] \
                             = dict(table=table_name, id=osm_id,
                                    admin_level=admin_level,
-                                   way_area=way_area)
+                                   way_area=way_area, minx=minx, miny=miny,
+                                   maxx=maxx, maxy=maxy)
                         # Make these first in list, priviledging level 8
                         entry_rank = (ADMIN_LEVEL_RANKS.get(admin_level,9),
                                       -way_area)
-- 
1.7.1




reply via email to

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