-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_rsgtools.py
89 lines (70 loc) · 3.02 KB
/
test_rsgtools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
Test geoutils-rsg package.
"""
import os
import pandas as pd
import time
from rsgtools.vector_ops.create_grid_boundary import generate_grid_boundary
from rsgtools.raster_ops.clip_raster import clip_raster_by_extent
from rsgtools.vector_ops.find_nearest_point import get_nearest_point
from rsgtools.vector_ops.geometry_ops import CreateObjectID, CreateGroupID, GenerateHydroID
from rsgtools.vector_ops.create_crosssection_line import generate_river_xscl
from rsgtools.vector_ops.merge_vector_files import merge_shapefiles
from rsgtools.vector_ops.wkt_ops import WktUtils
from rsgtools.raster_ops.mosaic_large_geotiffs import mosaic_raster
from rsgtools import project_dir
def test_ClipRaster():
# clip raster
inRaster = os.path.join(project_dir, "notebooks/data/raster/SRTM_DEM.tif")
inPolygon = os.path.join(
project_dir, "notebooks/data/vector/clip_boundary.shp")
out_raster = os.path.join(project_dir, "tests/results/clip_test.tif")
clip_raster_by_extent(inRaster, inPolygon, out_raster)
def test_ClosestPoints():
infc = os.path.join(
project_dir, "notebooks/data/vector/sample_drainage_lines.shp")
# get nearest point
point = [84.4874, 18.8998]
nearest_pnt = get_nearest_point(point, infc)
def test_OverlapArea():
op = WktUtils()
inwkts = os.path.join(project_dir, "notebooks/data/vector/sample_wkts.csv")
# get overlap area
wkt_df = pd.read_csv(inwkts)
poly_overlap_nodes = op.extract_overlap_polygon(
wkt_df['WKT'][0], wkt_df['WKT'][1])
print(poly_overlap_nodes)
def test_GenerateIDs():
# inputs
infc = os.path.join(
project_dir, "notebooks/data/vector/sample_drainage_lines.shp")
# create line object id
CreateObjectID(infc, fieldname="OBJECTID")
# create line-connected group id
CreateGroupID(infc, fieldname="GROUPID")
# generate river line hydroid
GenerateHydroID(infc, groupid="GROUPID", outfield="HYDROID")
def test_GenerateXSCLs():
infc = os.path.join(
project_dir, "notebooks/data/vector/sample_drainage_lines.shp")
# generate perpendicular line at specific interval
outfc = os.path.join(project_dir, "tests/results/out_cross_section.shp")
generate_river_xscl(infc, outfc, "UID", 1000, 250)
def test_MergeShapefiles():
# merge vector files
filedir = os.path.join(project_dir, "notebooks/data/vector")
outfile = os.path.join(project_dir, "tests/results/merge_lines.shp")
merge_shapefiles(filedir, outfile, geometry_type='Line')
def test_MosaicGeotiffs():
t0 = time.time()
tiff_data_path = os.path.join(
project_dir, "notebooks/data/raster/geotiff_tiles")
mosaic_outfile = os.path.join(
project_dir, "tests/results/mosaic_tiles.tif")
mosaic_raster(tiff_data_path, mosaic_outfile)
def test_Point2Grid():
# point to grid conversion
inpoints = os.path.join(
project_dir, "notebooks/data/vector/sample_grid_points.shp")
outgrid = os.path.join(project_dir, "tests/results/point_to_grid.shp")
generate_grid_boundary(inpoints, 5000, outgrid)