-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
f5ec8e0
commit 20c55b9
Showing
8 changed files
with
156 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,55 @@ | ||
import pyproj | ||
import pyproj.network | ||
from pyproj import CRS | ||
from pyproj.crs import CompoundCRS | ||
|
||
|
||
def create_crs_transformer(source_epsg: int, target_epsg: int) -> pyproj.Transformer: | ||
def create_crs_transformer(source_crs: CRS, target_crs: CRS) -> pyproj.Transformer: | ||
"""Create a coordinate transformer that transforms the coordinates from a source coordinate system to a target coordinate system. | ||
Args: | ||
source_epsg (int): The EPSG code of the source coordinate system. | ||
target_epsg (int): The EPSG code of the target coordinate system. | ||
source_crs (CRS): The source coordinate system. | ||
target_crs (CRS): The target coordinate system. | ||
Returns: | ||
pyproj.Transformer: The coordinate transformer | ||
""" | ||
pyproj.network.set_network_enabled(True) | ||
|
||
source_crs = pyproj.CRS.from_epsg(source_epsg) | ||
target_crs = pyproj.CRS.from_epsg(target_epsg) | ||
|
||
|
||
transformer = pyproj.Transformer.from_crs( | ||
crs_from=source_crs, crs_to=target_crs, always_xy=True | ||
) | ||
return transformer | ||
return transformer | ||
|
||
|
||
def create_crs(epsg: int) -> CRS: | ||
"""Create a coordinate system from the given EPSG code. | ||
Args: | ||
epsg (int): The EPSG code to create the coordinate system from. | ||
Returns: | ||
CRS: The created coordinate system. | ||
""" | ||
return CRS.from_epsg(epsg) | ||
|
||
|
||
def create_compound_crs(epsg_horizontal: int, epsg_vertical: int) -> CompoundCRS: | ||
"""Create a compound coordinate system from the given EPSG codes. | ||
Args: | ||
epsg_horizontal (int): EPSG code of the horizontal coordinate system.. | ||
epsg_vertical (int): EPSG code of the vertical coordinate system. | ||
Returns: | ||
CompoundCRS: The created compound coordinate system. | ||
""" | ||
crs_horizontal = create_crs(epsg_horizontal) | ||
crs_vertical = create_crs(epsg_vertical) | ||
|
||
compound_crs = CompoundCRS( | ||
name=f"{crs_horizontal.name} + {crs_vertical.name}", | ||
components=[crs_horizontal, crs_vertical], | ||
) | ||
|
||
return compound_crs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,44 @@ | ||
from netcdf_to_gltf_converter.preprocessing.crs import create_crs_transformer | ||
from pyproj import CRS | ||
from pyproj.crs import CompoundCRS | ||
|
||
from netcdf_to_gltf_converter.preprocessing.crs import (create_compound_crs, | ||
create_crs, | ||
create_crs_transformer) | ||
|
||
|
||
def test_create_crs_transformer(): | ||
transformer = create_crs_transformer(source_epsg=4979, target_epsg=7415) | ||
|
||
source_epsg = 4979 | ||
target_epsg = 7415 | ||
|
||
source_crs = create_crs(source_epsg) | ||
target_crs = create_crs(target_epsg) | ||
|
||
transformer = create_crs_transformer(source_crs, target_crs) | ||
|
||
assert transformer is not None | ||
assert transformer.is_network_enabled == True | ||
assert transformer.source_crs.name == 'WGS 84 (with axis order normalized for visualization)' | ||
assert transformer.target_crs.name == 'Amersfoort / RD New + NAP height' | ||
assert ( | ||
transformer.source_crs.name | ||
== "WGS 84 (with axis order normalized for visualization)" | ||
) | ||
assert transformer.target_crs.name == "Amersfoort / RD New + NAP height" | ||
|
||
|
||
def test_create_crs(): | ||
epsg = 7415 | ||
|
||
crs = create_crs(epsg) | ||
|
||
assert isinstance(crs, CRS) | ||
assert crs.name == "Amersfoort / RD New + NAP height" | ||
|
||
|
||
def test_create_compound_crs(): | ||
epsg_horizontal = 32617 | ||
epsg_vertical = 5703 | ||
|
||
crs = create_compound_crs(epsg_horizontal, epsg_vertical) | ||
|
||
assert isinstance(crs, CompoundCRS) | ||
assert crs.name == "WGS 84 / UTM zone 17N + NAVD88 height" | ||
assert crs.is_compound == True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from pyproj.crs import CompoundCRS | ||
|
||
from netcdf_to_gltf_converter.config import CrsTransformation | ||
|
||
|
||
class TestCrsTransformation: | ||
def test_construction_with_epsg_integers(self): | ||
source_epsg = 4979 | ||
target_epsg = 7415 | ||
|
||
crs_transformation = CrsTransformation( | ||
source_crs=source_epsg, target_crs=target_epsg | ||
) | ||
|
||
assert crs_transformation.source_crs.name == "WGS 84" | ||
assert crs_transformation.target_crs.name == "Amersfoort / RD New + NAP height" | ||
|
||
def test_construction_with_epsg_strings(self): | ||
source_epsg = "4979" | ||
target_epsg = "7415" | ||
|
||
crs_transformation = CrsTransformation( | ||
source_crs=source_epsg, target_crs=target_epsg | ||
) | ||
|
||
assert crs_transformation.source_crs.name == "WGS 84" | ||
assert crs_transformation.target_crs.name == "Amersfoort / RD New + NAP height" | ||
|
||
def test_construction_with_compound_epsg_strings(self): | ||
source_epsg = "4326+5773" | ||
target_epsg = "32617+5703" | ||
|
||
crs_transformation = CrsTransformation( | ||
source_crs=source_epsg, target_crs=target_epsg | ||
) | ||
|
||
assert crs_transformation.source_crs.name == "WGS 84 + EGM96 height" | ||
assert isinstance(crs_transformation.source_crs, CompoundCRS) | ||
assert ( | ||
crs_transformation.target_crs.name | ||
== "WGS 84 / UTM zone 17N + NAVD88 height" | ||
) | ||
assert isinstance(crs_transformation.target_crs, CompoundCRS) |