1
1
import os
2
- from pathlib import Path
3
2
4
3
import geopandas as gp
4
+ import pytest
5
5
from pam .operations .snap import run_facility_link_snapping , snap_facilities_to_network
6
6
from pam .read import read_matsim
7
7
8
- TEST_DATA_DIR = Path (__file__ ).parent / "test_data"
9
-
10
8
11
9
def test_add_snapping_adds_link_attribute (population_heh ):
12
- network = gp .read_file (os . path . join ( TEST_DATA_DIR , "test_link_geometry.geojson" ) )
10
+ network = gp .read_file (pytest . test_data_dir / "test_link_geometry.geojson" )
13
11
for _ , _ , person in population_heh .people ():
14
12
for act in person .activities :
15
13
assert act .location .link is None
@@ -19,13 +17,22 @@ def test_add_snapping_adds_link_attribute(population_heh):
19
17
for act in person .activities :
20
18
assert act .location .link is not None
21
19
20
+ # check that the link is indeed the nearest one
21
+ link_distance = (
22
+ network .set_index ("id" )
23
+ .loc [act .location .link , "geometry" ]
24
+ .distance (act .location .loc )
25
+ )
26
+ min_distance = network .distance (act .location .loc ).min ()
27
+ assert link_distance == min_distance
28
+
22
29
23
30
def test_links_resnapped (tmpdir ):
24
31
path_out = os .path .join (tmpdir , "pop_snapped.xml" )
25
32
run_facility_link_snapping (
26
- path_population_in = os . path . join ( TEST_DATA_DIR , "1.plans.xml" ) ,
33
+ path_population_in = pytest . test_data_dir / "1.plans.xml" ,
27
34
path_population_out = path_out ,
28
- path_network_geometry = os . path . join ( TEST_DATA_DIR , "test_link_geometry.geojson" ) ,
35
+ path_network_geometry = pytest . test_data_dir / "test_link_geometry.geojson" ,
29
36
)
30
37
assert os .path .exists (path_out )
31
38
pop_snapped = read_matsim (path_out )
0 commit comments