[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Maposmatic-dev] [PATCH 03/13] Add a get_bbox_from_osm_id() helper
From: |
Thomas Petazzoni |
Subject: |
[Maposmatic-dev] [PATCH 03/13] Add a get_bbox_from_osm_id() helper |
Date: |
Thu, 5 Aug 2010 16:56:16 +0200 |
To implement the /papersize/ service, we need to get the bbox
associated to a given OSM id, so this commit adds a
get_bbox_from_osm_id() helper.
In fact, the code for this helper already existed in
check_osm_id(). So we've moved part of check_osm_id() into
get_bbox_from_osm_id(), which is now used by check_osm_id().
Signed-off-by: Thomas Petazzoni <address@hidden>
---
www/maposmatic/helpers.py | 25 +++++++++++++++----------
1 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/www/maposmatic/helpers.py b/www/maposmatic/helpers.py
index 060db7c..0f6fc04 100644
--- a/www/maposmatic/helpers.py
+++ b/www/maposmatic/helpers.py
@@ -31,11 +31,7 @@ from ocitysmap.coords import BoundingBox as OCMBoundingBox
from www.maposmatic.models import MapRenderingJob
import www.settings
-def check_osm_id(osm_id, table='polygon'):
- """Make sure that the supplied OSM Id is valid and can be accepted for
- rendering (bounding box not too large, etc.). Raise an exception in
- case of error."""
-
+def get_bbox_from_osm_id(osm_id, table='polygon'):
# If no GIS database is configured, bypass the city_exists check by
# returning True.
if not www.settings.has_gis_database():
@@ -63,14 +59,23 @@ def check_osm_id(osm_id, table='polygon'):
# Check bbox size
bbox = OCMBoundingBox.parse_wkt(envlp)
- (metric_size_lat, metric_size_long) = bbox.spheric_sizes()
- if metric_size_lat > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS or \
- metric_size_long > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS:
- raise ValueError("Area too large")
-
finally:
conn.close()
+ return bbox
+
+def check_osm_id(osm_id, table='polygon'):
+ """Make sure that the supplied OSM Id is valid and can be accepted for
+ rendering (bounding box not too large, etc.). Raise an exception in
+ case of error."""
+
+ bbox = get_bbox_from_osm_id(osm_id, table)
+ (metric_size_lat, metric_size_long) = bbox.spheric_sizes()
+ if metric_size_lat > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS or \
+ metric_size_long > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS:
+ raise ValueError("Area too large")
+
+
def rendering_already_exists_by_osmid(osmid):
"""Returns the ID of a rendering matching the given OpenStreetMap city ID
from the last 24 hours, or None if no rendering can be found matching this
--
1.7.0.4
- [Maposmatic-dev] [PATCH 01/13] Extend MapRenderingJob with stylesheet, papersize and layout, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 03/13] Add a get_bbox_from_osm_id() helper,
Thomas Petazzoni <=
- [Maposmatic-dev] [PATCH 11/13] Fix language selector to work on Chrome, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 07/13] Fix maptitle handling in MapRenderingJobForm, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 04/13] Add layout, stylesheet and papersize to MapRenderingForm, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 13/13] Improve the slippy map notifier usage to show when the area is too big, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 12/13] Move Ajax service to the /apis/ directory, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 10/13] Update licence years, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 02/13] Implement a skeleton /papersize/ service, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 06/13] Implement a brand new wizard for map creation, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 08/13] Add link and form to search maps on the front page, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 09/13] Add licence boilerplate in map_rendering_form.css, Thomas Petazzoni, 2010/08/05