Skip to content

Commit

Permalink
fix(exif): another gps location issue
Browse files Browse the repository at this point in the history
  • Loading branch information
RouHim committed Sep 15, 2023
1 parent 6d7fef5 commit e59848a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/exif_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ pub fn detect_location(exif_data: &Exif) -> Option<GeoLocation> {
maybe_longitude_ref,
) {
return geo_location::from_degrees_minutes_seconds(
latitude.display_value().to_string(),
longitude.display_value().to_string(),
latitude_ref.display_value().to_string(),
longitude_ref.display_value().to_string(),
&latitude.display_value().to_string(),
&longitude.display_value().to_string(),
&latitude_ref.display_value().to_string(),
&longitude_ref.display_value().to_string(),
);
}

Expand Down
20 changes: 10 additions & 10 deletions src/geo_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ impl Display for GeoLocation {

/// Converts Degrees Minutes Seconds To Decimal Degrees
/// See <https://stackoverflow.com/questions/14906764/converting-gps-coordinates-to-decimal-degrees>
fn dms_to_dd(dms_string: &str, dms_ref: String) -> Option<f32> {
fn dms_to_dd(dms_string: &str, dms_ref: &str) -> Option<f32> {
lazy_static! {
static ref DMS_PARSE_PATTERN_1: Regex = Regex::new(
// e.g.: 7 deg 33 min 55.5155 sec
r"(?P<deg>\d+) deg (?P<min>\d+) min (?P<sec>\d+.\d+) sec"
// e.g.: 7 deg 33 min 55.5155 sec or 7 deg 33 min 55 sec
r"(?P<deg>\d+) deg (?P<min>\d+) min (?P<sec>\d+.?\d*) sec"
).unwrap();
static ref DMS_PARSE_PATTERN_2: Regex = Regex::new(
// e.g.: 50/1, 25/1, 2519/100
Expand All @@ -39,7 +39,7 @@ fn dms_to_dd(dms_string: &str, dms_ref: String) -> Option<f32> {
let dms_pattern_2_match: Option<Captures> = DMS_PARSE_PATTERN_2.captures(dms_string);

// Depending on the dms ref the value has to be multiplied by -1
let dms_ref_multiplier = match dms_ref.as_str() {
let dms_ref_multiplier = match dms_ref {
"S" | "W" => -1.0,
_ => 1.0,
};
Expand Down Expand Up @@ -111,13 +111,13 @@ fn parse_pattern_2(caps: Captures) -> Option<f32> {
/// If the latitude or longitude is not valid, None is returned
/// This is done by converting the latitude and longitude to degrees minutes seconds
pub fn from_degrees_minutes_seconds(
latitude: String,
longitude: String,
latitude_ref: String,
longitude_ref: String,
latitude: &str,
longitude: &str,
latitude_ref: &str,
longitude_ref: &str,
) -> Option<GeoLocation> {
let maybe_dd_lat = dms_to_dd(&latitude, latitude_ref);
let maybe_dd_lon = dms_to_dd(&longitude, longitude_ref);
let maybe_dd_lat = dms_to_dd(latitude, latitude_ref);
let maybe_dd_lon = dms_to_dd(longitude, longitude_ref);

if let (Some(latitude), Some(longitude)) = (maybe_dd_lat, maybe_dd_lon) {
Some(GeoLocation {
Expand Down
10 changes: 5 additions & 5 deletions src/resource_processor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ async fn resolve_kottenheim() {
#[actix_rt::test]
async fn resolve_negative_dms() {
// GIVEN are the degree minutes seconds coordinates for San Bartolomé de Tirajana
let lat = "27 deg 45 min 22.22 sec".to_string();
let long = "15 deg 34 min 13.76 sec".to_string();
let lat_ref = "N".to_string();
let long_ref = "W".to_string();
let lat = "27 deg 45 min 22.22 sec";
let long = "15 deg 34 min 13.76 sec";
let lat_ref = "N";
let long_ref = "W";

// WHEN resolving the city name
let dms = geo_location::from_degrees_minutes_seconds(lat, long, lat_ref, long_ref);

// THEN the resolved city name should be Kottenheim
// THEN the resolved city name should be San Bartolomé de Tirajana
let city_name = geo_location::resolve_city_name(dms.unwrap()).await;
assert_that!(city_name).is_equal_to(Some("San Bartolomé de Tirajana".to_string()));
}
Expand Down

0 comments on commit e59848a

Please sign in to comment.