Exemple #1
0
def import_location(loc_code, wkt):
    """ Import the given outline for the given location code.
    """
    outline = GEOSGeometry(wkt)

    if outline.geom_type == "MultiPolygon":
        mpoly = outline
    elif outline.geom_type == "Polygon":
        # Wrap the polygon into a MultiPolygon so we can save it into the
        # database.
        mpoly = MultiPolygon([outline])

    try:
        location = Location.objects.get(code=loc_code)
    except Location.DoesNotExist:
        print "...no such location!"
        return

    try:
        outline = Outline.objects.get(location=location)
    except Outline.DoesNotExist:
        # We don't have an outline for this location -> add one.
        outline = Outline()
        outline.location = location

    outline.outline = mpoly
    outline.save()