Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions c/sedona-proj/src/proj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ impl ProjContext {
}
}

/// Set the logging level for PROJ operations
///
/// `level` - Unsigned Integer value representing the log level:
/// - PJ_LOG_LEVEL_PJ_LOG_NONE (0): No logging
/// - PJ_LOG_LEVEL_PJ_LOG_ERROR (1): Error messages
/// - PJ_LOG_LEVEL_PJ_LOG_DEBUG (2): Debug messages
/// - PJ_LOG_LEVEL_PJ_LOG_TRACE (3): Trace
/// - PJ_LOG_LEVEL_PJ_LOG_TELL (4): Tell
pub(crate) fn set_log_level(&self, level: u32) -> Result<(), SedonaProjError> {
unsafe {
call_proj_api!(self.api, proj_log_level, self.inner, level);
}
Ok(())
}

/// Set the path in which to look for PROJ data files
///
/// Most PROJ distributions come with a few small data files installed to a /share directory
Expand Down
32 changes: 29 additions & 3 deletions c/sedona-proj/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use crate::error::SedonaProjError;
use crate::proj::{Proj, ProjContext};
use sedona_geometry::bounding_box::BoundingBox;
use sedona_geometry::error::SedonaGeometryError;
use sedona_geometry::interval::IntervalTrait;
Expand All @@ -22,9 +24,6 @@ use std::cell::RefCell;
use std::path::PathBuf;
use std::rc::Rc;

use crate::error::SedonaProjError;
use crate::proj::{Proj, ProjContext};

/// Builder for a [ProjCrsEngine]
///
/// API for specifying various engine parameters. More parameters may
Expand All @@ -34,6 +33,7 @@ pub struct ProjCrsEngineBuilder {
shared_library: Option<PathBuf>,
database_path: Option<PathBuf>,
search_paths: Option<Vec<PathBuf>>,
log_level: Option<u32>,
}

impl ProjCrsEngineBuilder {
Expand Down Expand Up @@ -82,6 +82,25 @@ impl ProjCrsEngineBuilder {
}
}

/// Set the PROJ log level
///
/// Set the verbosity of PROJ logging. The default is no logging,
/// however errors will still be propagated through the error
/// handling.
///
/// Log level constants are defined in proj_sys:
/// - PJ_LOG_LEVEL_PJ_LOG_NONE (0): No logging
/// - PJ_LOG_LEVEL_PJ_LOG_ERROR (1): Error messages
/// - PJ_LOG_LEVEL_PJ_LOG_DEBUG (2): Debug messages
/// - PJ_LOG_LEVEL_PJ_LOG_TRACE (3): Trace
/// - PJ_LOG_LEVEL_PJ_LOG_TELL (4): Tell
pub fn with_log_level(self, log_level: u32) -> Self {
Self {
log_level: Some(log_level),
..self
}
}

/// Build a [ProjCrsEngine] with the specified options
pub fn build(&self) -> Result<ProjCrsEngine, SedonaProjError> {
let mut ctx = if let Some(shared_library) = self.shared_library.clone() {
Expand All @@ -102,6 +121,13 @@ impl ProjCrsEngineBuilder {
ctx.set_search_paths(&string_vec)?;
}

if let Some(log_level) = &self.log_level {
ctx.set_log_level(*log_level)?;
} else {
// Default log level to none
ctx.set_log_level(0)?;
}

Ok(ProjCrsEngine { ctx: Rc::new(ctx) })
}
}
Expand Down