Skip to content

Commit 1bb061a

Browse files
committed
Allow 3d inputs in examples/proj4rs
1 parent e71df1a commit 1bb061a

File tree

8 files changed

+28
-19
lines changed

8 files changed

+28
-19
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ Cargo.lock
22

33
/target
44
.idea/
5+
6+
__pycache__

proj4rs-clib/Makefile.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ args = [
4747
]
4848

4949

50+
[tasks."python.build-dev"]
51+
command = "maturin"
52+
args = ["develop"]
53+
54+
5055
[tasks."python.lint-fix"]
5156
command = "ruff"
5257
args = [
@@ -65,4 +70,4 @@ args = ["python"]
6570
[tasks."python.test"]
6671
command = "pytest"
6772
args = [ "-v", "python/tests"]
68-
dependencies = ["python.lint", "python.typing"]
73+
dependencies = ["python.build-dev", "python.lint", "python.typing"]

proj4rs/examples/rsproj.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,20 @@ fn main() -> Result<()> {
5858
for line in stdin.lines() {
5959
let line = line.unwrap();
6060
let inputs = line.as_str().split_whitespace().collect::<Vec<_>>();
61-
if inputs.len() != 2 {
62-
eprintln!("Expecting: '<x> ,<y>' found: {}", line.as_str());
61+
if inputs.len() < 2 || inputs.len() > 3 {
62+
eprintln!("Expecting: '<x> ,<y> [,<z>]' found: {}", line.as_str());
6363
std::process::exit(1);
6464
}
6565

6666
let x: f64 = inputs[0].parse().map_err(from_parse_err)?;
6767
let y: f64 = inputs[1].parse().map_err(from_parse_err)?;
68+
let z: f64 = if inputs.len() > 2 {
69+
inputs[2].parse().map_err(from_parse_err)?
70+
} else {
71+
0.
72+
};
6873

69-
let mut point = (x, y, 0.);
74+
let mut point = (x, y, z);
7075

7176
if src.is_latlong() {
7277
point.0 = point.0.to_radians();

proj4rs/src/adaptors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Transform for (f64, f64) {
3636
///
3737
/// let dst = Proj::from_proj_string("+proj=utm +ellps=GRS80 +zone=30").unwrap();
3838
/// let src = Proj::from_proj_string("+proj=latlong +ellps=GRS80").unwrap();
39-
39+
///
4040
/// let (x, y, z) = transform_vertex_3d(&src, &dst, (2.0, 1.0, 0.0)).unwrap();
4141
/// ```
4242
pub fn transform_vertex_3d(src: &Proj, dst: &Proj, pt: (f64, f64, f64)) -> Result<(f64, f64, f64)> {
@@ -53,7 +53,7 @@ pub fn transform_vertex_3d(src: &Proj, dst: &Proj, pt: (f64, f64, f64)) -> Resul
5353
///
5454
/// let dst = Proj::from_proj_string("+proj=utm +ellps=GRS80 +zone=30").unwrap();
5555
/// let src = Proj::from_proj_string("+proj=latlong +ellps=GRS80").unwrap();
56-
56+
///
5757
/// let (x, y) = transform_vertex_2d(&src, &dst, (2.0, 1.0)).unwrap();
5858
/// ```
5959
#[inline(always)]
@@ -69,7 +69,7 @@ pub fn transform_vertex_2d(src: &Proj, dst: &Proj, pt: (f64, f64)) -> Result<(f6
6969
///
7070
/// let dst = Proj::from_proj_string("+proj=utm +ellps=GRS80 +zone=30").unwrap();
7171
/// let src = Proj::from_proj_string("+proj=latlong +ellps=GRS80").unwrap();
72-
72+
///
7373
/// let (x, y, z) = transform_xyz(&src, &dst, 2.0, 1.0, 0.0).unwrap();
7474
/// ```
7575
#[inline(always)]
@@ -85,7 +85,7 @@ pub fn transform_xyz(src: &Proj, dst: &Proj, x: f64, y: f64, z: f64) -> Result<(
8585
///
8686
/// let dst = Proj::from_proj_string("+proj=utm +ellps=GRS80 +zone=30").unwrap();
8787
/// let src = Proj::from_proj_string("+proj=latlong +ellps=GRS80").unwrap();
88-
88+
///
8989
/// let (x, y) = transform_xy(&src, &dst, 2.0, 1.0).unwrap();
9090
/// ```
9191
#[inline(always)]

proj4rs/src/parameters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a> TryFrom<&Parameter<'a>> for &'a str {
3737
}
3838
}
3939

40-
impl<'a> Parameter<'a> {
40+
impl Parameter<'_> {
4141
fn try_value<F: FromStr>(&self) -> Result<F> {
4242
match self.value.map(F::from_str) {
4343
None => Err(Error::NoValueParameter),

proj4rs/src/projections/eqc.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ impl Projection {
5151
}
5252
}
5353

54-
5554
#[cfg(test)]
5655
mod tests {
5756
use crate::math::consts::EPS_10;
@@ -64,9 +63,7 @@ mod tests {
6463

6564
println!("{:#?}", p.projection());
6665

67-
let inputs = [
68-
((2., 47., 0.), (222638.98158654713, 5232016.06728385761, 0.)),
69-
];
66+
let inputs = [((2., 47., 0.), (222638.98158654713, 5232016.06728385761, 0.))];
7067

7168
test_proj_forward(&p, &inputs, EPS_10);
7269
test_proj_inverse(&p, &inputs, EPS_10);
@@ -78,12 +75,12 @@ mod tests {
7875

7976
println!("{:#?}", p.projection());
8077

81-
let inputs = [
82-
((-88., 30., 0.), (192811.01392664597, 3339584.72379820701, 0.)),
83-
];
78+
let inputs = [(
79+
(-88., 30., 0.),
80+
(192811.01392664597, 3339584.72379820701, 0.),
81+
)];
8482

8583
test_proj_forward(&p, &inputs, EPS_10);
8684
test_proj_inverse(&p, &inputs, EPS_10);
8785
}
88-
8986
}

proj4rs/src/projections/geos.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Projection {
4949
pub fn geos(p: &mut ProjData, params: &ParamList) -> Result<Self> {
5050
let h: f64 = params
5151
.try_value("h")?
52-
.ok_or_else(|| Error::InputStringError("Missing parameter 'h'"))?;
52+
.ok_or(Error::InputStringError("Missing parameter 'h'"))?;
5353
let flip_axis: bool = params
5454
.try_value::<&str>("sweep")
5555
.and_then(|sweep| match sweep {

proj4rs/src/transform.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ where
110110
let src_datum = src.datum();
111111
let dst_datum = dst.datum();
112112

113-
// Return true if the datums are identical is respect
113+
// Return true if the datums are identical with respect
114114
// to datum transformation.
115115
// As of PROJ 4 behavior, we prevent datum transformation
116116
// if either the source or destination are of an unknown datum type.

0 commit comments

Comments
 (0)