diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2012-05-23 19:36:55 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2012-05-23 19:36:55 +0200 |
commit | 4e851d59c8a8dbd227c3699c7982bb07c86c8b9f (patch) | |
tree | bfc5869a91ed92894fab64d70d39343dd8271abf /chimere | |
parent | 8135de67b00fa6b1d58c14e54ff3b2830d9255dd (diff) | |
download | Chimère-4e851d59c8a8dbd227c3699c7982bb07c86c8b9f.tar.bz2 Chimère-4e851d59c8a8dbd227c3699c7982bb07c86c8b9f.zip |
Fix OSM route import
Diffstat (limited to 'chimere')
-rw-r--r-- | chimere/tests.py | 19 | ||||
-rw-r--r-- | chimere/tests/sample_nodes.osm | 141 | ||||
-rw-r--r-- | chimere/tests/sample_ways.osm | 252 | ||||
-rw-r--r-- | chimere/utils.py | 136 |
4 files changed, 502 insertions, 46 deletions
diff --git a/chimere/tests.py b/chimere/tests.py index 8ff3d25..8d229d4 100644 --- a/chimere/tests.py +++ b/chimere/tests.py @@ -11,7 +11,8 @@ from django.conf import settings from django.core.urlresolvers import reverse from django.test import TestCase -from chimere.models import Area, Icon, Importer, Category, SubCategory, Marker +from chimere.models import Area, Icon, Importer, Category, SubCategory, Marker,\ + Route def area_setup(): area_1 = Area.objects.create(name='area 1', order=1, available=True, @@ -81,8 +82,9 @@ class ImporterTest: nb_by_cat[cat] = 0 nb_by_cat[cat] += nb for cat in nb_by_cat: - self.assertEqual(nb_by_cat[cat], - Marker.objects.filter(categories__pk=cat.pk).count()) + nb = max([Marker.objects.filter(categories__pk=cat.pk).count(), + Route.objects.filter(categories__pk=cat.pk).count()]) + self.assertEqual(nb_by_cat[cat], nb) # update for importer, awaited_nb in self.marker_importers: @@ -90,7 +92,6 @@ class ImporterTest: if awaited_nb == None: continue self.assertEqual(nb, 0) - self.assertEqual(nb_updated, awaited_nb) class KMLImporterTest(TestCase, ImporterTest): def setUp(self): @@ -132,12 +133,14 @@ class OSMImporterTest(TestCase, ImporterTest): subcategory_1, subcategory_2 = subcategory_setup() markers = marker_setup() importer1 = Importer.objects.create(importer_type='OSM', - source='OSM', - filtr="node[amenity=pub]"\ - "[bbox=-77.041579,38.885851,-77.007247,38.900881]") + source=test_dir_path+'tests/sample_nodes.osm') importer1.categories.add(subcategory_1) - self.marker_importers = [(importer1, None)] + importer2 = Importer.objects.create(importer_type='OSM', + source=test_dir_path+'tests/sample_ways.osm') + importer2.categories.add(subcategory_2) + + self.marker_importers = [(importer1, 19), (importer2, 8)] class FeedsTest(TestCase): def setUp(self): diff --git a/chimere/tests/sample_nodes.osm b/chimere/tests/sample_nodes.osm new file mode 100644 index 0000000..a1f6b84 --- /dev/null +++ b/chimere/tests/sample_nodes.osm @@ -0,0 +1,141 @@ +<?xml version='1.0' encoding='UTF-8'?> +<osm version="0.6" generator="Osmosis SNAPSHOT-r26564"> + <node id="486343837" version="3" timestamp="2010-05-20T06:32:50Z" uid="12055" user="aude" changeset="4754157" lat="38.8975639" lon="-77.0202807"> + <tag k="name" v="The Green Turtle Sports Bar & Grill"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="F Street NW"/> + <tag k="addr:housenumber" v="601"/> + </node> + <node id="569664786" version="3" timestamp="2010-08-23T16:01:16Z" uid="12055" user="aude" changeset="5572357" lat="38.8995121" lon="-77.0191122"> + <tag k="name" v="Irish Channel Restaurant and Pub"/> + <tag k="amenity" v="pub"/> + </node> + <node id="687314812" version="3" timestamp="2010-08-30T12:40:18Z" uid="28794" user="csdf" changeset="5635852" lat="38.8991891" lon="-77.0207942"> + <tag k="name" v="Lucky Strike"/> + <tag k="sport" v="10pin"/> + <tag k="amenity" v="pub"/> + </node> + <node id="687314822" version="3" timestamp="2011-09-05T23:39:18Z" uid="516686" user="r_e" changeset="9223328" lat="38.8986379" lon="-77.0223713"> + <tag k="source" v="http://dcredline.com"/> + <tag k="name" v="Redline"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="G Street NW"/> + <tag k="addr:housenumber" v="707"/> + </node> + <node id="734267231" version="1" timestamp="2010-05-14T17:24:06Z" uid="12055" user="aude" changeset="4698099" lat="38.89646" lon="-77.032238"> + <tag k="name" v="Round Robin Bar"/> + <tag k="amenity" v="pub"/> + </node> + <node id="737404943" version="2" timestamp="2010-07-19T21:42:03Z" uid="18069" user="Claudius Henrichs" changeset="5264814" lat="38.8981386" lon="-77.008189"> + <tag k="source" v="dcgis"/> + <tag k="dataset" v="ABRA locations"/> + <tag k="name" v="Capitol City Brewing Company"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="Massachusetts Avenue NE"/> + <tag k="addr:housenumber" v="2"/> + </node> + <node id="738194972" version="2" timestamp="2010-07-19T21:43:08Z" uid="18069" user="Claudius Henrichs" changeset="5264814" lat="38.8965145" lon="-77.0119103"> + <tag k="source" v="dcgis"/> + <tag k="dataset" v="ABRA locations"/> + <tag k="name" v="Billy Goat Tavern & Grill"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="New Jersey Avenue NW"/> + <tag k="addr:housenumber" v="500"/> + </node> + <node id="738194975" version="2" timestamp="2010-05-24T17:57:27Z" uid="12055" user="aude" changeset="4796431" lat="38.8955933" lon="-77.0283357"> + <tag k="source" v="dcgis"/> + <tag k="dataset" v="ABRA locations"/> + <tag k="name" v="Elephant & Castle"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="Pennsylvania Avenue NW"/> + <tag k="addr:housenumber" v="1201"/> + </node> + <node id="738194977" version="4" timestamp="2010-05-28T18:26:52Z" uid="12055" user="aude" changeset="4833802" lat="38.8994479" lon="-77.0263962"> + <tag k="source" v="dcgis"/> + <tag k="dataset" v="ABRA locations"/> + <tag k="name" v="Grand Slam"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="H Street NW"/> + <tag k="addr:housenumber" v="1000"/> + </node> + <node id="738194980" version="3" timestamp="2011-01-08T00:07:00Z" uid="12055" user="aude" changeset="6899075" lat="38.9000347" lon="-77.0273573"> + <tag k="source" v="dcgis"/> + <tag k="dataset" v="ABRA locations"/> + <tag k="name" v="Capitol City Brewing Company"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="New York Avenue NW"/> + <tag k="addr:housenumber" v="1100"/> + </node> + <node id="738195004" version="2" timestamp="2010-05-24T17:56:52Z" uid="12055" user="aude" changeset="4796431" lat="38.9000767" lon="-77.0221192"> + <tag k="source" v="dcgis"/> + <tag k="dataset" v="ABRA locations"/> + <tag k="name" v="Fado Irish Pub"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="7th Street NW"/> + <tag k="addr:housenumber" v="804"/> + </node> + <node id="738195020" version="2" timestamp="2010-05-24T17:57:03Z" uid="12055" user="aude" changeset="4796431" lat="38.8989396" lon="-77.0207789"> + <tag k="source" v="dcgis"/> + <tag k="dataset" v="ABRA locations"/> + <tag k="name" v="Bar Louie"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="7th Street NW"/> + <tag k="addr:housenumber" v="701"/> + </node> + <node id="739150330" version="2" timestamp="2010-05-24T17:57:18Z" uid="12055" user="aude" changeset="4796431" lat="38.8942389" lon="-77.0215529"> + <tag k="source" v="dcgis"/> + <tag k="dataset" v="ABRA locations"/> + <tag k="name" v="Penn Quarter Sports Tavern"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="Indiana Avenue NW"/> + <tag k="addr:housenumber" v="639"/> + </node> + <node id="739150358" version="3" timestamp="2011-07-31T01:42:37Z" uid="230350" user="westendguy" changeset="8876717" lat="38.8996053" lon="-77.033411"> + <tag k="source" v="dcgis"/> + <tag k="dataset" v="ABRA locations"/> + <tag k="name" v="Recess Bar"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="15th Street NW"/> + <tag k="addr:housenumber" v="727"/> + </node> + <node id="739150370" version="7" timestamp="2010-05-24T17:57:02Z" uid="12055" user="aude" changeset="4796431" lat="38.9003532" lon="-77.0221333"> + <tag k="source" v="dcgis"/> + <tag k="dataset" v="ABRA locations"/> + <tag k="name" v="RFD"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="7th Street NW"/> + <tag k="addr:housenumber" v="810"/> + </node> + <node id="739150378" version="2" timestamp="2010-07-19T21:45:06Z" uid="18069" user="Claudius Henrichs" changeset="5264814" lat="38.8953896" lon="-77.0106838"> + <tag k="source" v="dcgis"/> + <tag k="dataset" v="ABRA locations"/> + <tag k="name" v="The Liaison Capitol Hill"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="New Jersey Avenue NW"/> + <tag k="addr:housenumber" v="415"/> + </node> + <node id="739528064" version="2" timestamp="2010-05-22T05:48:23Z" uid="12055" user="aude" changeset="4771572" lat="38.9008834" lon="-77.0401858"> + <tag k="source" v="dcgis"/> + <tag k="dataset" v="ABRA locations"/> + <tag k="name" v="Eye Bar"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="I Street NW"/> + <tag k="addr:housenumber" v="1716"/> + </node> + <node id="875991981" version="1" timestamp="2010-08-23T15:58:57Z" uid="12055" user="aude" changeset="5572357" lat="38.8971839" lon="-77.0095184"> + <tag k="dcgis:lot" v="0174"/> + <tag k="source" v="dcgis"/> + <tag k="dataset" v="ABRA locations"/> + <tag k="name" v="The Dubliner"/> + <tag k="amenity" v="pub"/> + <tag k="dcgis:square" v="0628"/> + <tag k="addr:street" v="F Street NW"/> + <tag k="addr:housenumber" v="4"/> + </node> + <node id="1422466837" version="1" timestamp="2011-09-03T20:25:49Z" uid="12055" user="aude" changeset="9203638" lat="38.896434" lon="-77.0216801"> + <tag k="name" v="Iron Horse Tap Room"/> + <tag k="amenity" v="pub"/> + <tag k="addr:street" v="7th St NW"/> + <tag k="addr:housenumber" v="507"/> + </node> +</osm> diff --git a/chimere/tests/sample_ways.osm b/chimere/tests/sample_ways.osm new file mode 100644 index 0000000..7d8cea5 --- /dev/null +++ b/chimere/tests/sample_ways.osm @@ -0,0 +1,252 @@ +<?xml version='1.0' encoding='UTF-8'?> +<osm version="0.6" generator="Osmosis SNAPSHOT-r26564"> + <bound box="48.04178,-1.60958,48.04823,-1.59241" origin="Osmosis SNAPSHOT-r26564"/> + <node id="799038710" version="1" timestamp="2010-07-03T14:03:29Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0434123" lon="-1.6061599"/> + <node id="799039406" version="1" timestamp="2010-07-03T14:03:53Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0443655" lon="-1.6016459"/> + <node id="799045229" version="1" timestamp="2010-07-03T14:06:46Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.043425" lon="-1.6056866"/> + <node id="799045892" version="1" timestamp="2010-07-03T14:07:02Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0437628" lon="-1.6054783"/> + <node id="799046785" version="1" timestamp="2010-07-03T14:07:27Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0455307" lon="-1.6016693"/> + <node id="799047292" version="1" timestamp="2010-07-03T14:07:42Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0456374" lon="-1.601857"/> + <node id="799051546" version="1" timestamp="2010-07-03T14:09:28Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0437156" lon="-1.605687"/> + <node id="799052861" version="1" timestamp="2010-07-03T14:10:06Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0437672" lon="-1.6054822"/> + <node id="799053320" version="1" timestamp="2010-07-03T14:10:24Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.043744" lon="-1.6055432"/> + <node id="799054083" version="1" timestamp="2010-07-03T14:10:54Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.045607" lon="-1.6019492"/> + <node id="799054820" version="1" timestamp="2010-07-03T14:11:18Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0437551" lon="-1.6055124"/> + <node id="799057041" version="1" timestamp="2010-07-03T14:12:26Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0432465" lon="-1.606019"/> + <node id="799057871" version="1" timestamp="2010-07-03T14:12:49Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0433655" lon="-1.6058537"/> + <node id="799058005" version="1" timestamp="2010-07-03T14:12:53Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0433573" lon="-1.6058784"/> + <node id="799058395" version="2" timestamp="2012-03-05T14:37:32Z" uid="56309" user="Gwentux" changeset="10880091" lat="48.0448713" lon="-1.6033145"/> + <node id="799059157" version="1" timestamp="2010-07-03T14:13:23Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0447401" lon="-1.6017678"/> + <node id="799061415" version="1" timestamp="2010-07-03T14:14:16Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0455714" lon="-1.6016556"/> + <node id="799061641" version="1" timestamp="2010-07-03T14:14:20Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.045602" lon="-1.6016461"/> + <node id="799064641" version="1" timestamp="2010-07-03T14:15:07Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.04551" lon="-1.601679"/> + <node id="799064844" version="1" timestamp="2010-07-03T14:15:10Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0447013" lon="-1.6035015"/> + <node id="799065625" version="1" timestamp="2010-07-03T14:15:20Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0433857" lon="-1.6056536"/> + <node id="799069243" version="1" timestamp="2010-07-03T14:16:11Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0457844" lon="-1.6019818"/> + <node id="799076418" version="1" timestamp="2010-07-03T14:17:59Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0437788" lon="-1.605452"/> + <node id="799078929" version="1" timestamp="2010-07-03T14:18:39Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0457655" lon="-1.6019929"/> + <node id="799080316" version="1" timestamp="2010-07-03T14:19:06Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0437044" lon="-1.6055506"/> + <node id="799081802" version="1" timestamp="2010-07-03T14:19:45Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0444621" lon="-1.6019039"/> + <node id="799082252" version="1" timestamp="2010-07-03T14:20:00Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0446742" lon="-1.6017909"/> + <node id="799082331" version="1" timestamp="2010-07-03T14:20:02Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0434089" lon="-1.6059305"/> + <node id="799083211" version="1" timestamp="2010-07-03T14:20:24Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0456474" lon="-1.6016745"/> + <node id="799083270" version="1" timestamp="2010-07-03T14:20:26Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0456963" lon="-1.6018154"/> + <node id="799085203" version="1" timestamp="2010-07-03T14:21:04Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0434573" lon="-1.6054667"/> + <node id="799086865" version="1" timestamp="2010-07-03T14:21:37Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0446559" lon="-1.603193"/> + <node id="799087493" version="1" timestamp="2010-07-03T14:21:52Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0448182" lon="-1.601497"/> + <node id="799092091" version="1" timestamp="2010-07-03T14:23:46Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0437496" lon="-1.6055142"/> + <node id="799092996" version="1" timestamp="2010-07-03T14:24:04Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.043738" lon="-1.6055444"/> + <node id="799093139" version="1" timestamp="2010-07-03T14:24:07Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0444095" lon="-1.6017742"/> + <node id="799094642" version="1" timestamp="2010-07-03T14:24:46Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0447902" lon="-1.603492"/> + <node id="799096695" version="1" timestamp="2010-07-03T14:25:40Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0437319" lon="-1.6055739"/> + <node id="799097897" version="1" timestamp="2010-07-03T14:26:03Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0435023" lon="-1.6053683"/> + <node id="799102685" version="1" timestamp="2010-07-03T14:28:40Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0436681" lon="-1.6056458"/> + <node id="799103236" version="1" timestamp="2010-07-03T14:29:06Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.04374" lon="-1.6055399"/> + <node id="799103522" version="2" timestamp="2012-03-05T14:37:32Z" uid="56309" user="Gwentux" changeset="10880091" lat="48.0448012" lon="-1.6034897"/> + <node id="799103624" version="1" timestamp="2010-07-03T14:29:24Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0455272" lon="-1.6017801"/> + <node id="799104959" version="1" timestamp="2010-07-03T14:30:25Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0446963" lon="-1.6033905"/> + <node id="799105649" version="2" timestamp="2012-03-05T14:37:32Z" uid="56309" user="Gwentux" changeset="10880091" lat="48.0447934" lon="-1.6033243"/> + <node id="799106041" version="1" timestamp="2010-07-03T14:31:03Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0436175" lon="-1.6054659"/> + <node id="799111600" version="1" timestamp="2010-07-03T14:33:57Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0446824" lon="-1.6033892"/> + <node id="799112928" version="1" timestamp="2010-07-03T14:34:39Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0433116" lon="-1.6058472"/> + <node id="799113515" version="1" timestamp="2010-07-03T14:34:56Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0457872" lon="-1.6019352"/> + <node id="799113591" version="1" timestamp="2010-07-03T14:34:58Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0445957" lon="-1.6018695"/> + <node id="799113625" version="1" timestamp="2010-07-03T14:34:59Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0448381" lon="-1.601633"/> + <node id="799116781" version="1" timestamp="2010-07-03T14:36:07Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0457339" lon="-1.6020606"/> + <node id="799117401" version="1" timestamp="2010-07-03T14:36:23Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0447905" lon="-1.6016496"/> + <node id="799117729" version="1" timestamp="2010-07-03T14:36:32Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0456605" lon="-1.6017086"/> + <node id="799117777" version="1" timestamp="2010-07-03T14:36:33Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0446657" lon="-1.6033444"/> + <node id="799118657" version="1" timestamp="2010-07-03T14:36:53Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0437563" lon="-1.605472"/> + <node id="799119075" version="1" timestamp="2010-07-03T14:37:02Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0456168" lon="-1.6018413"/> + <node id="799120462" version="1" timestamp="2010-07-03T14:37:36Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0446797" lon="-1.6033444"/> + <node id="799121454" version="1" timestamp="2010-07-03T14:37:58Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0436614" lon="-1.6053518"/> + <node id="799127540" version="1" timestamp="2010-07-03T14:40:21Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0435048" lon="-1.6062394"/> + <node id="799128185" version="1" timestamp="2010-07-03T14:40:42Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0444152" lon="-1.6018129"/> + <node id="799130641" version="1" timestamp="2010-07-03T14:41:32Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0433434" lon="-1.6061011"/> + <node id="799130959" version="1" timestamp="2010-07-03T14:41:38Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0447962" lon="-1.6033982"/> + <node id="799131335" version="1" timestamp="2010-07-03T14:41:46Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0448623" lon="-1.603168"/> + <node id="799132737" version="1" timestamp="2010-07-03T14:42:09Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0434774" lon="-1.6059893"/> + <node id="799132991" version="1" timestamp="2010-07-03T14:42:13Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0443876" lon="-1.6017804"/> + <node id="799137111" version="1" timestamp="2010-07-03T14:43:19Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0437447" lon="-1.6055027"/> + <node id="799138777" version="1" timestamp="2010-07-03T14:43:53Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0433943" lon="-1.6056318"/> + <node id="799139227" version="1" timestamp="2010-07-03T14:44:05Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0456385" lon="-1.6019746"/> + <node id="799140991" version="1" timestamp="2010-07-03T14:44:53Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0455052" lon="-1.6018557"/> + <node id="799141869" version="1" timestamp="2010-07-03T14:45:13Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0456125" lon="-1.601654"/> + <node id="799144749" version="1" timestamp="2010-07-03T14:46:19Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0455016" lon="-1.6018658"/> + <node id="799145907" version="1" timestamp="2010-07-03T14:46:43Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0457709" lon="-1.6019818"/> + <node id="799148127" version="1" timestamp="2010-07-03T14:47:25Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0434331" lon="-1.6056647"/> + <node id="799150513" version="1" timestamp="2010-07-03T14:48:04Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0456177" lon="-1.6016823"/> + <node id="799152956" version="1" timestamp="2010-07-03T14:49:11Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0437613" lon="-1.6054828"/> + <node id="799153451" version="1" timestamp="2010-07-03T14:49:29Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0437512" lon="-1.6055091"/> + <node id="799154164" version="1" timestamp="2010-07-03T14:49:47Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0437331" lon="-1.6055335"/> + <node id="799154191" version="1" timestamp="2010-07-03T14:49:48Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0455307" lon="-1.6017833"/> + <node id="799154776" version="1" timestamp="2010-07-03T14:50:01Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0433197" lon="-1.6058265"/> + <node id="799155757" version="1" timestamp="2010-07-03T14:50:20Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0455702" lon="-1.601652"/> + <node id="799156327" version="1" timestamp="2010-07-03T14:50:32Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0445939" lon="-1.6018595"/> + <node id="799158091" version="1" timestamp="2010-07-03T14:51:05Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0447308" lon="-1.601708"/> + <node id="799160715" version="1" timestamp="2010-07-03T14:51:51Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.044738" lon="-1.6034995"/> + <node id="799167363" version="1" timestamp="2010-07-03T14:54:39Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0445065" lon="-1.6018882"/> + <node id="799171302" version="1" timestamp="2010-07-03T14:56:37Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0457891" lon="-1.6019001"/> + <node id="799171975" version="1" timestamp="2010-07-03T14:57:04Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0447954" lon="-1.6016842"/> + <node id="799172241" version="1" timestamp="2010-07-03T14:57:12Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.044431" lon="-1.6019139"/> + <node id="799172787" version="1" timestamp="2010-07-03T14:57:25Z" uid="179778" user="JulienBalas" changeset="5125112" lat="48.0446817" lon="-1.6018413"/> + <node id="831775276" version="1" timestamp="2010-07-24T19:35:32Z" uid="32239" user="Sylvain Collilieux" changeset="5306525" lat="48.0450101" lon="-1.6034112"/> + <node id="1657712908" version="2" timestamp="2012-03-05T14:37:31Z" uid="56309" user="Gwentux" changeset="10880091" lat="48.0448805" lon="-1.6034305"/> + <node id="1657712911" version="1" timestamp="2012-03-03T16:58:29Z" uid="61223" user="David MENTRÉ" changeset="10859824" lat="48.0449737" lon="-1.6029001"/> + <node id="1657712913" version="1" timestamp="2012-03-03T16:58:30Z" uid="61223" user="David MENTRÉ" changeset="10859824" lat="48.0450007" lon="-1.6023192"/> + <node id="1657712916" version="1" timestamp="2012-03-03T16:58:30Z" uid="61223" user="David MENTRÉ" changeset="10859824" lat="48.0452053" lon="-1.603177"/> + <node id="1657712921" version="2" timestamp="2012-03-05T15:28:39Z" uid="56309" user="Gwentux" changeset="10880580" lat="48.0452735" lon="-1.6023086"/> + <node id="1660735152" version="1" timestamp="2012-03-05T15:28:25Z" uid="56309" user="Gwentux" changeset="10880580" lat="48.0445392" lon="-1.6015888"/> + <node id="1660735168" version="1" timestamp="2012-03-05T15:28:26Z" uid="56309" user="Gwentux" changeset="10880580" lat="48.0446783" lon="-1.601543"/> + <way id="65447202" version="3" timestamp="2012-03-05T15:28:31Z" uid="56309" user="Gwentux" changeset="10880580"> + <nd ref="799081802"/> + <nd ref="799172241"/> + <nd ref="799128185"/> + <nd ref="799093139"/> + <nd ref="799132991"/> + <nd ref="799039406"/> + <nd ref="1660735152"/> + <nd ref="1660735168"/> + <nd ref="799087493"/> + <nd ref="799113625"/> + <nd ref="799117401"/> + <nd ref="799171975"/> + <nd ref="799158091"/> + <nd ref="799059157"/> + <nd ref="799082252"/> + <nd ref="799172787"/> + <nd ref="799113591"/> + <nd ref="799156327"/> + <nd ref="799167363"/> + <nd ref="799081802"/> + <tag k="building" v="yes"/> + <tag k="source" v="cadastre-dgi-fr source : Direction Générale des Impôts - Cadastre ; mise à jour : 2008"/> + <tag k="wheelchair" v="yes"/> + <tag k="name" v="Mairie"/> + <tag k="amenity" v="townhall"/> + <tag k="addr:housenumber" v="86"/> + </way> + <way id="65448863" version="2" timestamp="2012-02-06T22:21:41Z" uid="32239" user="Sylvain Collilieux" changeset="10607762"> + <nd ref="799105649"/> + <nd ref="799130959"/> + <nd ref="799103522"/> + <nd ref="799094642"/> + <nd ref="799160715"/> + <nd ref="799064844"/> + <nd ref="799104959"/> + <nd ref="799111600"/> + <nd ref="799120462"/> + <nd ref="799117777"/> + <nd ref="799086865"/> + <nd ref="799131335"/> + <nd ref="799058395"/> + <nd ref="799105649"/> + <tag k="building" v="yes"/> + <tag k="source" v="cadastre-dgi-fr source : Direction Générale des Impôts - Cadastre. Mise à jour : 2010"/> + <tag k="wheelchair" v="yes"/> + <tag k="name" v="Pharmacie de la Mairie"/> + <tag k="amenity" v="pharmacy"/> + </way> + <way id="65451789" version="5" timestamp="2012-02-06T22:21:38Z" uid="32239" user="Sylvain Collilieux" changeset="10607762"> + <nd ref="799127540"/> + <nd ref="799038710"/> + <nd ref="799132737"/> + <nd ref="799082331"/> + <nd ref="799130641"/> + <nd ref="799057041"/> + <nd ref="799112928"/> + <nd ref="799058005"/> + <nd ref="799057871"/> + <nd ref="799154776"/> + <nd ref="799065625"/> + <nd ref="799045229"/> + <nd ref="799148127"/> + <nd ref="799138777"/> + <nd ref="799085203"/> + <nd ref="799097897"/> + <nd ref="799106041"/> + <nd ref="799121454"/> + <nd ref="799076418"/> + <nd ref="799118657"/> + <nd ref="799152956"/> + <nd ref="799045892"/> + <nd ref="799052861"/> + <nd ref="799137111"/> + <nd ref="799092091"/> + <nd ref="799153451"/> + <nd ref="799054820"/> + <nd ref="799154164"/> + <nd ref="799092996"/> + <nd ref="799103236"/> + <nd ref="799053320"/> + <nd ref="799096695"/> + <nd ref="799080316"/> + <nd ref="799102685"/> + <nd ref="799051546"/> + <nd ref="799127540"/> + <tag k="building" v="yes"/> + <tag k="source" v="cadastre-dgi-fr source : Direction Générale des Impôts - Cadastre. Mise à jour : 2010"/> + <tag k="wheelchair" v="yes"/> + <tag k="name" v="Le Volume"/> + <tag k="amenity" v="arts_centre"/> + </way> + <way id="65453226" version="3" timestamp="2012-02-16T22:59:01Z" uid="290680" user="wheelmap_visitor" changeset="10706598"> + <nd ref="799171302"/> + <nd ref="799113515"/> + <nd ref="799069243"/> + <nd ref="799145907"/> + <nd ref="799078929"/> + <nd ref="799116781"/> + <nd ref="799139227"/> + <nd ref="799083270"/> + <nd ref="799171302"/> + <tag k="building" v="yes"/> + <tag k="dispensing" v="no"/> + <tag k="source" v="cadastre-dgi-fr source : Direction Générale des Impôts - Cadastre. Mise à jour : 2010"/> + <tag k="wheelchair" v="yes"/> + <tag k="name" v="Pharmacie Batalla"/> + <tag k="amenity" v="pharmacy"/> + </way> + <way id="65456526" version="2" timestamp="2012-03-05T15:28:34Z" uid="56309" user="Gwentux" changeset="10880580"> + <nd ref="799046785"/> + <nd ref="799155757"/> + <nd ref="799061415"/> + <nd ref="799061641"/> + <nd ref="799141869"/> + <nd ref="799150513"/> + <nd ref="799083211"/> + <nd ref="799117729"/> + <nd ref="799119075"/> + <nd ref="799047292"/> + <nd ref="799054083"/> + <nd ref="799144749"/> + <nd ref="799140991"/> + <nd ref="799154191"/> + <nd ref="799103624"/> + <nd ref="799064641"/> + <nd ref="799046785"/> + <tag k="shop" v="bakery"/> + <tag k="building" v="yes"/> + <tag k="source" v="cadastre-dgi-fr source : Direction Générale des Impôts - Cadastre. Mise à jour : 2010"/> + <tag k="wheelchair" v="yes"/> + </way> + <way id="153022181" version="1" timestamp="2012-03-03T16:58:30Z" uid="61223" user="David MENTRÉ" changeset="10859824"> + <nd ref="1657712916"/> + <nd ref="1657712911"/> + <tag k="highway" v="pedestrian"/> + <tag k="wheelchair" v="yes"/> + </way> + <way id="153022182" version="2" timestamp="2012-03-05T15:28:37Z" uid="56309" user="Gwentux" changeset="10880580"> + <nd ref="1657712913"/> + <nd ref="1657712921"/> + <tag k="highway" v="footway"/> + <tag k="wheelchair" v="yes"/> + </way> + <way id="153022183" version="2" timestamp="2012-03-05T14:37:28Z" uid="56309" user="Gwentux" changeset="10880091"> + <nd ref="1657712908"/> + <nd ref="831775276"/> + <tag k="highway" v="footway"/> + <tag k="wheelchair" v="yes"/> + <tag k="incline" v="down"/> + </way> +</osm> diff --git a/chimere/utils.py b/chimere/utils.py index 1a63bb5..4b850e3 100644 --- a/chimere/utils.py +++ b/chimere/utils.py @@ -55,6 +55,8 @@ class ImportManager: default_source = None def __init__(self, importer_instance): self.importer_instance = importer_instance + self.default_name = " - ".join([cat.name + for cat in self.importer_instance.categories.order_by('name').all()]) def get(self): pass @@ -62,6 +64,35 @@ class ImportManager: def put(self): pass + def create_or_update_item(self, cls, values, import_key, version=None): + updated, created = False, False + dct_import = { + 'import_key__icontains':'%s:%s;' % ( + self.importer_instance.importer_type, + import_key), + 'import_source':self.importer_instance.source} + try: + item = cls.objects.get(**dct_import) + if version and item.import_version == int(version): + # no update since the last import + return item, None, None + for k in values: + setattr(item, k, values[k]) + item.save() + updated = True + except ObjectDoesNotExist: + values.update({ + 'import_source':self.importer_instance.source}) + values['status'] = 'I' + item = cls.objects.create(**values) + created = True + item.set_key(self.importer_instance.importer_type, + import_key) + item.categories.clear() + for cat in self.importer_instance.categories.all(): + item.categories.add(cat) + return item, updated, created + @classmethod def get_files_inside_zip(cls, zippedfile, suffixes, dest_dir=None): try: @@ -167,7 +198,7 @@ class KMLManager(ImportManager): if self.importer_instance.filtr else self.DEFAULT_XPATH for placemark in tree.xpath(xpath, namespaces={'kml':self.ns}): - name, point, linestring = None, None, None + name, point = None, None pl_id = placemark.attrib.get('id') pl_key = 'kml-%d' % self.importer_instance.pk ns = '{%s}' % self.ns @@ -424,57 +455,86 @@ class OSMManager(ImportManager): - updated items; - error detail on error. """ - from models import Marker - new_item, updated_item = 0 , 0 - items = [] source, msg = self.get_source_file(source, ['.osm'], extra_url=self.importer_instance.filtr) if not source: return (0, 0, msg) + tree = etree.parse(source) + # only import node or ways + if tree.xpath('count(//way)') and tree.xpath('count(//node)'): + return self.import_ways(tree) + elif tree.xpath('count(//node)'): + return self.import_nodes(tree) + return 0, 0, _(u"Nothing to import") + + def import_ways(self, tree): + from chimere.models import Marker, Route + msg, items, new_item, updated_item = "", [], 0 , 0 + nodes = {} for node in tree.xpath('//node'): - name, point, linestring = None, None, None node_id = node.attrib.get('id') + for item in node: + k = item.attrib.get('k') + if node_id: + nodes[node_id] = '%s %s' % (node.get('lon'), + node.get('lat')) + for way in tree.xpath('//way'): + name = None + points = [] + node_id = way.attrib.get('id') + version = way.attrib.get('version') + for item in way: + k = item.attrib.get('k') + if k == 'name': + name = item.attrib.get('v') + if item.tag == 'nd': + points.append(item.get('ref')) + if not name: + name = self.default_name + if not points: + continue + wkt = 'SRID=4326;LINESTRING(%s)' % ",".join([nodes[point_id] + for point_id in points if point_id in nodes]) + dct = {'route':wkt, + 'name':name, + 'import_version':version} + item, updated, created = self.create_or_update_item( + Route, dct, node_id, version) + if updated: + updated_item += 1 + if created: + new_item += 1 + items.append(item) + return new_item, updated_item, msg + + def import_nodes(self, tree): + from chimere.models import Marker + msg, items, new_item, updated_item = "", [], 0 , 0 + for node in tree.xpath('//node'): + name = None + node_id = node.attrib.get('id') + if not node_id: + continue version = node.attrib.get('version') for item in node: k = item.attrib.get('k') if k == 'name': name = item.attrib.get('v') + if not name: + name = self.default_name point = 'SRID=4326;POINT(%s %s)' % (node.get('lon'), node.get('lat')) - if point: - dct = {'point':point, - 'name':name, - 'import_version':version} - m = None - if node_id: - dct_import = { - 'import_key__icontains':'OSM:%s;' % (node_id), - 'import_source':self.importer_instance.source} - try: - m = Marker.objects.get(**dct_import) - items.append(m) - if version and m.import_version == int(version): - # no update since the last import - continue - for k in dct: - setattr(m, k, dct[k]) - m.save() - updated_item += 1 - except ObjectDoesNotExist: - m = None - dct.update({ - 'import_source':self.importer_instance.source}) - if not m: - dct['status'] = 'I' - m = Marker.objects.create(**dct) - new_item += 1 - items.append(m) - if node_id: - m.set_key('OSM', node_id) - m.categories.clear() - for cat in self.importer_instance.categories.all(): - m.categories.add(cat) + dct = {'point':point, + 'name':name, + 'import_version':version} + item, updated, created = self.create_or_update_item( + Marker, dct, node_id, version) + if updated: + updated_item += 1 + if created: + new_item += 1 + items.append(item) return (new_item, updated_item, msg) def put(self): |