Skip to content

Commit

Permalink
Allow 3d inputs in examples/proj4rs
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarteau committed Jan 7, 2025
1 parent e71df1a commit 1bb061a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ Cargo.lock

/target
.idea/

__pycache__
7 changes: 6 additions & 1 deletion proj4rs-clib/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ args = [
]


[tasks."python.build-dev"]
command = "maturin"
args = ["develop"]


[tasks."python.lint-fix"]
command = "ruff"
args = [
Expand All @@ -65,4 +70,4 @@ args = ["python"]
[tasks."python.test"]
command = "pytest"
args = [ "-v", "python/tests"]
dependencies = ["python.lint", "python.typing"]
dependencies = ["python.build-dev", "python.lint", "python.typing"]
11 changes: 8 additions & 3 deletions proj4rs/examples/rsproj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,20 @@ fn main() -> Result<()> {
for line in stdin.lines() {
let line = line.unwrap();
let inputs = line.as_str().split_whitespace().collect::<Vec<_>>();
if inputs.len() != 2 {
eprintln!("Expecting: '<x> ,<y>' found: {}", line.as_str());
if inputs.len() < 2 || inputs.len() > 3 {
eprintln!("Expecting: '<x> ,<y> [,<z>]' found: {}", line.as_str());
std::process::exit(1);
}

let x: f64 = inputs[0].parse().map_err(from_parse_err)?;
let y: f64 = inputs[1].parse().map_err(from_parse_err)?;
let z: f64 = if inputs.len() > 2 {
inputs[2].parse().map_err(from_parse_err)?
} else {
0.
};

let mut point = (x, y, 0.);
let mut point = (x, y, z);

if src.is_latlong() {
point.0 = point.0.to_radians();
Expand Down
8 changes: 4 additions & 4 deletions proj4rs/src/adaptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Transform for (f64, f64) {
///
/// let dst = Proj::from_proj_string("+proj=utm +ellps=GRS80 +zone=30").unwrap();
/// let src = Proj::from_proj_string("+proj=latlong +ellps=GRS80").unwrap();
///
/// let (x, y, z) = transform_vertex_3d(&src, &dst, (2.0, 1.0, 0.0)).unwrap();
/// ```
pub fn transform_vertex_3d(src: &Proj, dst: &Proj, pt: (f64, f64, f64)) -> Result<(f64, f64, f64)> {
Expand All @@ -53,7 +53,7 @@ pub fn transform_vertex_3d(src: &Proj, dst: &Proj, pt: (f64, f64, f64)) -> Resul
///
/// let dst = Proj::from_proj_string("+proj=utm +ellps=GRS80 +zone=30").unwrap();
/// let src = Proj::from_proj_string("+proj=latlong +ellps=GRS80").unwrap();
///
/// let (x, y) = transform_vertex_2d(&src, &dst, (2.0, 1.0)).unwrap();
/// ```
#[inline(always)]
Expand All @@ -69,7 +69,7 @@ pub fn transform_vertex_2d(src: &Proj, dst: &Proj, pt: (f64, f64)) -> Result<(f6
///
/// let dst = Proj::from_proj_string("+proj=utm +ellps=GRS80 +zone=30").unwrap();
/// let src = Proj::from_proj_string("+proj=latlong +ellps=GRS80").unwrap();
///
/// let (x, y, z) = transform_xyz(&src, &dst, 2.0, 1.0, 0.0).unwrap();
/// ```
#[inline(always)]
Expand All @@ -85,7 +85,7 @@ pub fn transform_xyz(src: &Proj, dst: &Proj, x: f64, y: f64, z: f64) -> Result<(
///
/// let dst = Proj::from_proj_string("+proj=utm +ellps=GRS80 +zone=30").unwrap();
/// let src = Proj::from_proj_string("+proj=latlong +ellps=GRS80").unwrap();
///
/// let (x, y) = transform_xy(&src, &dst, 2.0, 1.0).unwrap();
/// ```
#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion proj4rs/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'a> TryFrom<&Parameter<'a>> for &'a str {
}
}

impl<'a> Parameter<'a> {
impl Parameter<'_> {
fn try_value<F: FromStr>(&self) -> Result<F> {
match self.value.map(F::from_str) {
None => Err(Error::NoValueParameter),
Expand Down
13 changes: 5 additions & 8 deletions proj4rs/src/projections/eqc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ impl Projection {
}
}


#[cfg(test)]
mod tests {
use crate::math::consts::EPS_10;
Expand All @@ -64,9 +63,7 @@ mod tests {

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

let inputs = [
((2., 47., 0.), (222638.98158654713, 5232016.06728385761, 0.)),
];
let inputs = [((2., 47., 0.), (222638.98158654713, 5232016.06728385761, 0.))];

test_proj_forward(&p, &inputs, EPS_10);
test_proj_inverse(&p, &inputs, EPS_10);
Expand All @@ -78,12 +75,12 @@ mod tests {

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

let inputs = [
((-88., 30., 0.), (192811.01392664597, 3339584.72379820701, 0.)),
];
let inputs = [(
(-88., 30., 0.),
(192811.01392664597, 3339584.72379820701, 0.),
)];

test_proj_forward(&p, &inputs, EPS_10);
test_proj_inverse(&p, &inputs, EPS_10);
}

}
2 changes: 1 addition & 1 deletion proj4rs/src/projections/geos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Projection {
pub fn geos(p: &mut ProjData, params: &ParamList) -> Result<Self> {
let h: f64 = params
.try_value("h")?
.ok_or_else(|| Error::InputStringError("Missing parameter 'h'"))?;
.ok_or(Error::InputStringError("Missing parameter 'h'"))?;
let flip_axis: bool = params
.try_value::<&str>("sweep")
.and_then(|sweep| match sweep {
Expand Down
2 changes: 1 addition & 1 deletion proj4rs/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ where
let src_datum = src.datum();
let dst_datum = dst.datum();

// Return true if the datums are identical is respect
// Return true if the datums are identical with respect
// to datum transformation.
// As of PROJ 4 behavior, we prevent datum transformation
// if either the source or destination are of an unknown datum type.
Expand Down

0 comments on commit 1bb061a

Please sign in to comment.