예제 #1
0
    def test_json_to_result(self):
        geocoder = QgsNominatimGeocoder()

        json = {
            "place_id": 157298780,
            "licence":
            "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
            "osm_type": "way",
            "osm_id": 264390219,
            "boundingbox": ["46.887", "46.889", "-71.201", "-71.199"],
            "lat": "46.888",
            "lon": "-71.200",
            "display_name":
            "École Primaire La Ribambelle, 500, Rue Anick, Saint-Michel, Beauport, Quebec City, Québec (Agglomération), Capitale-Nationale, Quebec, G1C 4X5, Canada",
            "class": "amenity",
            "type": "school",
            "importance": 0.201,
            "icon":
            "https://nominatim.qgis.org/ui/mapicons//education_school.p.20.png",
            "address": {
                "amenity": "École Primaire La Ribambelle",
                "house_number": "500",
                "road": "Rue Anick",
                "suburb": "Saint-Michel",
                "city_district": "Beauport",
                "city": "Quebec City",
                "county": "Québec (Agglomération)",
                "region": "Capitale-Nationale",
                "state": "Quebec",
                "postcode": "G1C 4X5",
                "country": "Canada",
                "country_code": "ca"
            }
        }

        res = geocoder.jsonToResult(json)
        self.assertEqual(
            res.identifier(),
            'École Primaire La Ribambelle, 500, Rue Anick, Saint-Michel, Beauport, Quebec City, Québec (Agglomération), Capitale-Nationale, Quebec, G1C 4X5, Canada'
        )
        self.assertEqual(res.geometry().asWkt(1), 'Point (-71.2 46.9)')
        self.assertEqual(
            res.additionalAttributes(), {
                'state': 'Quebec',
                'city': 'Quebec City',
                'country': 'Canada',
                'display_name':
                'École Primaire La Ribambelle, 500, Rue Anick, Saint-Michel, Beauport, Quebec City, Québec (Agglomération), Capitale-Nationale, Quebec, G1C 4X5, Canada',
                'city_district': 'Beauport',
                'place_id': '157298780',
                'postcode': 'G1C 4X5',
                'road': 'Rue Anick',
                'osm_type': 'way',
                'type': 'school',
                'class': 'amenity'
            })
        self.assertEqual(res.viewport(),
                         QgsRectangle(-71.201, 46.887, -71.199, 46.889))
        self.assertEqual(res.group(), 'Quebec')
예제 #2
0
    def test_basic(self):
        """
        Basic tests
        """
        geocoder = QgsNominatimGeocoder()

        self.assertFalse(geocoder.countryCodes())
        geocoder.setCountryCodes('ca,km')
        self.assertEqual(geocoder.countryCodes(), 'ca,km')
        self.assertEqual(geocoder.requestUrl('20 green st, twaddlingham').toString(), 'https://nominatim.openstreetmap.org/search?format=json&addressdetails=1&countrycodes=ca,km&q=20 green st, twaddlingham')

        geocoder.setEndpoint('https://my.server/search')
        self.assertEqual(geocoder.requestUrl('20 green st, twaddlingham').toString(), 'https://my.server/search?format=json&addressdetails=1&countrycodes=ca,km&q=20 green st, twaddlingham')
예제 #3
0
    def test_url(self):
        geocoder = QgsNominatimGeocoder('')
        self.assertEqual(geocoder.requestUrl('20 green st, twaddlingham', QgsRectangle(3, 5, 6, 8)).toString(),
                         'https://nominatim.openstreetmap.org/search?format=json&addressdetails=1&viewbox=3,5,6,8&q=20 green st, twaddlingham')

        geocoder = QgsNominatimGeocoder(countryCodes='ca,km', endpoint='https://my.server/search')
        self.assertEqual(geocoder.requestUrl('20 green st, twaddlingham', QgsRectangle(3, 5, 6, 8)).toString(),
                         'https://my.server/search?format=json&addressdetails=1&viewbox=3,5,6,8&countrycodes=ca,km&q=20 green st, twaddlingham')