def body(self, lib_object: JSON, body: Body) -> Body: body.short_name = self.utils.normalize_body_name(body.short_name) body.ags = lib_object.get("ags") if body.ags: body.ags = body.ags.replace(" ", "") if len(body.ags or "") > 8: # Special case for https://ris.krefeld.de/webservice/oparl/v1/body/1 if body.ags[8:] == "0" * len(body.ags[8:]): body.ags = body.ags[:8] else: raise RuntimeError( "The Amtliche Gemeindeschlüssel of {} is longer than 8 characters: '{}'".format( body, body.ags ) ) # We don't really need the location because we have our own outline # importing logic and don't need the city, but we import it for comprehensiveness location = self.retrieve(Location, lib_object.get("location"), body.oparl_id) if location and location.geometry: if location.geometry["type"] == "Point": body.center = location body.outline = None elif location.geometry["type"] == "Polygon": logger.warning("Overriding outline of Body with api version") body.center = None body.outline = location else: logger.warning( "Location object is of type {}, which is neither 'Point' nor 'Polygon'." "Skipping this location.".format(location.geometry["type"]) ) return body
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()
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()