Esempio n. 1
0
async def test_multilinestring_should_round(connection, expected):
    geom = MultiLineString(expected, srid=4326)
    await connection.execute(
        'INSERT INTO multilinestring_async (geom) '
        'VALUES ($1)', geom)
    geom = await connection.fetchval(
        'SELECT geom FROM multilinestring_async '
        'WHERE geom=$1',
        geom,
        column=0)
    assert geom.coords == expected
Esempio n. 2
0
async def get_relation(**tags):
    if "iso" in tags:
        tags["ISO3166-1:alpha2"] = tags.pop("iso")
    tags = "".join(f'["{k}"="{v}"]' for k, v in tags.items())
    path = Path("tmp/boundary")
    path.mkdir(parents=True, exist_ok=True)
    file_ = (
        tags.replace("/", "_")
        .replace("][", "_")
        .replace('"', "")
        .replace(":", "_")
        .replace("[", "")
        .replace("]", "")
        + ".json"
    )
    path = path / file_
    if not path.exists():
        print(f"Downloading {path}")
        params = {"data": f"[out:json];relation{tags};(._;>;);out body;"}
        try:
            resp = requests.get(OVERPASS, params=params)
            resp.raise_for_status()
        except requests.exceptions.ConnectionError:
            print(f"\nError: Network problem retrieving data")
            sys.exit(1)
        except requests.exceptions.HTTPError as err:
            print(f"\nHTTPError: {err}")
            sys.exit(1)
        data = resp.content
        with path.open("wb") as f:
            f.write(data)
        data = data.decode()
    else:
        with path.open() as f:
            data = f.read()
    try:
        relation = overpy.Result.from_json(json.loads(data)).relations[0]
    except IndexError:
        raise ValueError(f"Cannot find relation for {tags}")
    collection = []
    for member in relation.members:
        coords = []
        # Nepal disputed way without outer role:
        # http://www.openstreetmap.org/way/202061325
        if member.role != "outer" and member.ref != 202_061_325:
            continue
        way = member.resolve()
        for node in way.nodes:
            coords.append((float(node.lon), float(node.lat)))
        collection.append(LineString(coords))
    shape = await make_polygon(MultiLineString(collection))
    return shape
Esempio n. 3
0
 def getValues(self):
     """
     Geometry representing the values taken by the temporal value.
     """
     values = [seq.getValues for seq in self._sequenceList]
     points = [geo for geo in values if isinstance(geo, Point)]
     lines = [geo for geo in values if isinstance(geo, LineString)]
     if len(points) != 0 and len(points) != 0:
         return GeometryCollection(points + lines)
     if len(points) != 0 and len(points) == 0:
         return MultiPoint(points)
     if len(points) == 0 and len(points) != 0:
         return MultiLineString(lines)
Esempio n. 4
0
async def get_relation(conn, **tags):
    if 'iso' in tags:
        tags['ISO3166-1:alpha2'] = tags.pop('iso')
    tags = "".join(f'["{k}"="{v}"]' for k, v in tags.items())
    path = Path('tmp/boundary')
    path.mkdir(parents=True, exist_ok=True)
    file_ = tags.replace('/', '_').replace('][', '_').replace('"', '').replace(
        ':', '_').replace('[', '').replace(']', '') + '.json'
    path = path / file_
    if not path.exists():
        params = {'data': f'[out:json];relation{tags};(._;>;);out body;'}
        try:
            resp = requests.get(OVERPASS, params=params)
            resp.raise_for_status()
        except requests.exceptions.ConnectionError as err:
            print(f'\nError: Network problem retrieving data')
            sys.exit(1)
        except requests.exceptions.HTTPError as err:
            print(f'\nHTTPError: {err}')
            sys.exit(1)
        data = resp.content
        with path.open('wb') as f:
            f.write(data)
        data = data.decode()
    else:
        with path.open() as f:
            data = f.read()
    try:
        relation = overpy.Result.from_json(json.loads(data)).relations[0]
    except IndexError:
        raise ValueError(f'Cannot find relation for {tags}')
    collection = []
    for member in relation.members:
        coords = []
        # Nepal disputed way without outer role:
        # http://www.openstreetmap.org/way/202061325
        if member.role != 'outer' and member.ref != 202061325:
            continue
        way = member.resolve()
        for node in way.nodes:
            coords.append((float(node.lon), float(node.lat)))
        collection.append(LineString(coords))
    shape = await make_polygon(conn, MultiLineString(collection))
    return shape
Esempio n. 5
0
def test_multilinestring_should_round(cursor, expected):
    params = [MultiLineString(expected, srid=4326)]
    cursor.execute('INSERT INTO multilinestring (geom) VALUES (%s)', params)
    cursor.execute('SELECT geom FROM multilinestring WHERE geom=%s', params)
    geom = cursor.fetchone()[0]
    assert geom.coords == expected
Esempio n. 6
0
def test_multilinestring_get_item():
    multi = MultiLineString((((30, 10), (10, 30)), ((40, 10), (10, 40))))
    assert multi[0] == LineString(((30, 10), (10, 30)))
Esempio n. 7
0
def test_geom_should_compare_with_coords():
    assert (((30, 10), (10, 30)), ((40, 10), (10, 40))) == MultiLineString((((30, 10), (10, 30)), ((40, 10), (10, 40))))  # noqa
Esempio n. 8
0
def test_multilinestring_geojson():
    multi = MultiLineString((((30, 10), (10, 30)), ((40, 10), (10, 40))))
    assert multi.geojson == {
        "type": "MultiLineString",
        "coordinates": (((30, 10), (10, 30)), ((40, 10), (10, 40)))
    }