コード例 #1
0
    def location(self, libobject: JSON, location: Location) -> Location:
        location.description = libobject.get("description")
        location.is_official = self.utils.official_geojson
        location.geometry = libobject.get("geojson", {}).get("geometry")

        location.street_address = libobject.get("streetAddress")
        location.room = libobject.get("room")
        location.postal_code = libobject.get("postalCode")
        location.locality = libobject.get("locality")

        if not location.description:
            description = ""
            if location.room:
                description += location.room + ", "
            if location.street_address:
                description += location.street_address + ", "
            if location.locality:
                if location.postal_code:
                    description += location.postal_code + " "
                description += location.locality
            location.description = description

        # If a street_address is present, we try to find the exact location on the map
        if location.street_address and not location.geometry:
            search_str = location.street_address + ", "
            if location.locality:
                if location.postal_code:
                    search_str += location.postal_code + " " + location.locality
            elif self.default_body:
                search_str += self.default_body.short_name
            search_str += " " + settings.GEOEXTRACT_SEARCH_COUNTRY

            location.geometry = geocode(search_str)

        return location
コード例 #2
0
def extract_locations(text, fallback_city=None):
    """
    :type text: str
    :type fallback_city: str
    :return: list of mainapp.models.Body
    """
    if not fallback_city:
        fallback_city = settings.GEOEXTRACT_DEFAULT_CITY

    found_locations = extract_found_locations(text)

    locations = []
    for found_location in found_locations:
        location_name = format_location_name(found_location)
        try:
            location = Location.objects.get(name=location_name)
            locations.append(location)
        except Location.DoesNotExist:
            geodata = get_geodata(found_location, fallback_city)

            location = Location()
            location.name = location_name
            location.short_name = location_name
            location.is_official = False
            location.osm_id = None  # @TODO
            if geodata:
                location.geometry = {
                    "type": "Point",
                    "coordinates": [geodata['lng'], geodata['lat']]
                }
            else:
                location.geometry = None
            location.save()

            bodies = detect_relevant_bodies(location)
            for body in bodies:
                location.bodies.add(body)

            locations.append(location)

    return locations
コード例 #3
0
def import_outline(body: Body, gemeindeschluessel: str):
    if not body.outline:
        outline = Location()
        outline.name = "Outline of " + body.name
        outline.short_name = body.short_name
        outline.is_official = False
    else:
        outline = body.outline

    logger.info("Importing outline from {}".format(gemeindeschluessel))

    query = query_template_outline.format(gemeindeschluessel)

    response = requests.post(overpass_api, data={"data": query})
    response.raise_for_status()
    geojson = convert_to_geojson(response.text)
    outline.geometry = geojson
    outline.save()

    body.outline = outline
    body.save()
コード例 #4
0
def import_outline(body, gemeindeschluessel):
    if not body.outline:
        outline = Location()
        outline.name = 'Outline of ' + body.name
        outline.short_name = body.short_name
        outline.is_official = False
    else:
        outline = body.outline

    logger.info("Importing outline from {}".format(gemeindeschluessel))

    query = query_template_outline.format(gemeindeschluessel)

    r = requests.post(overpass_api, data={'data': query})

    geojson = convert_to_geojson(r.text)
    outline.geometry = geojson
    outline.save()

    body.outline = outline
    body.save()
コード例 #5
0
def import_outline(body: Body, ags: Optional[str] = None):
    ags = ags or body.ags
    assert ags is not None

    logger.info("Importing outline from {}".format(ags))

    if not body.outline:
        outline = Location()
        outline.name = "Outline of " + body.name
        outline.short_name = body.short_name
        outline.is_official = False
    else:
        outline = body.outline

    query = format_template(query_template_outline, ags)

    response = requests.post(overpass_api, data={"data": query})
    response.raise_for_status()
    geojson = osm2geojson.json2geojson(response.text)
    outline.geometry = geojson
    outline.save()

    body.outline = outline
    body.save()