Coverage for gws-app/gws/gis/gdalx/_test.py: 0%
24 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
1"""gdalx tests."""
3import os
5import gws
6import gws.test.util as u
7import gws.gis.gdalx as gdalx
8import gws.base.shape
9import gws.lib.datetimex as datetimex
10import gws.gis.crs
13def test_shp():
14 cols = dict(
15 c_date=gws.AttributeType.date,
16 c_float=gws.AttributeType.float,
17 c_int=gws.AttributeType.int,
18 c_str=gws.AttributeType.str,
19 )
21 recs_a = []
23 for i in range(1, 10):
24 rec = gws.FeatureRecord()
25 rec.attributes = dict(
26 c_date=datetimex.parse(f'2021-04-0{i}'),
27 c_float=i / 10,
28 c_int=i,
29 c_str=f'{i}-{i}-{i}',
30 )
31 rec.shape = gws.base.shape.from_xy(i * 1000, i * 2000, gws.gis.crs.get(25833))
32 recs_a.append(rec)
34 with u.temp_dir_in_base_dir() as d:
35 with gdalx.open_vector(f'{d}/shape.shp', 'w') as ds:
36 la = ds.create_layer(
37 '',
38 cols,
39 gws.GeometryType.point,
40 gws.gis.crs.get(25833)
41 )
42 la.insert(recs_a)
44 with gdalx.open_vector(f'{d}/shape.shp', 'r') as ds:
45 la = ds.layer(0)
46 recs_b = la.get_all()
48 assert [r.attributes for r in recs_a] == [r.attributes for r in recs_b]
49 assert [r.shape.to_ewkt() for r in recs_a] == [r.shape.to_ewkt() for r in recs_b]