Skip to content

Commit

Permalink
Add tests and accessors for additional ogr field types.
Browse files Browse the repository at this point in the history
  • Loading branch information
manimaul committed Dec 2, 2020
1 parent 787e33b commit f4932f9
Show file tree
Hide file tree
Showing 13 changed files with 381 additions and 6 deletions.
168 changes: 168 additions & 0 deletions fixtures/US5WA22M/US5WA22A.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
NOAA ENC�

NATIONAL OCEANIC AND ATMOSPHERIC ADMINISTRATION

US5WA22M - TACOMA HARBOR

INDEX:
NOTE A
SUPPLEMENTAL INFORMATION
AIDS TO NAVIGATION
CAUTION - TEMPORARY
CAUTION - DREDGED AREAS
CAUTION - LIMITATIONS
CAUTION - SUBMARINE PIPELINES AND CABLES
ANCHORING STANDARDS OF CARE
AUTHORITIES
WARNING - PRUDENT MARINER
NOAA WEATHER RADIO BROADCASTS
POLLUTION REPORTS
RADAR REFLECTORS
COLREGS, 80.1395 (see note A)
ADMINISTRATION AREA
TIDAL INFORMATION
ADDITIONAL INFORMATION
REGULATED NAVIGATION AREA
USACE HYDROGRAPHIC SURVEYS


NOTES:
NOTE A
Navigation regulations are published in Chapter 2, U.S.
Coast Pilot 7. Additions or revisions to Chapter 2 are pub-
lished in the Notice to Mariners. Information concerning the
regulations may be obtained at the Office of the Commander,
13th Coast Guard District in Seattle, Washington or at the
Office of the District Engineer, Corps of Engineers in
Seattle, Washington.
Refer to charted regulation section numbers.


SUPPLEMENTAL INFORMATION
Consult U.S. Coast Pilot 7 for important supplemental information.


AIDS TO NAVIGATION
Consult U.S. Coast Guard Light List for
supplemental information concerning aids to
navigation.


CAUTION - TEMPORARY
Temporary changes or defects in aids to
navigation are not indicated. See
Local Notice to Mariners.


CAUTION - DREDGED AREAS
Improved channels
are subject to shoaling, particularly at the edges.


CAUTION - LIMITATIONS
Limitations on the use of radio signals as
aids to marine navigation can be found in the
U.S. Coast Guard Light Lists and National
Geospatial-Intelligence Agency Publication 117.
Radio direction-finder bearings to commercial
broadcasting stations are subject to error and
should be used with caution.


CAUTION - SUBMARINE PIPELINES AND CABLES
Additional uncharted submarine pipelines and
submarine cables may exist within the area of
this chart. Not all submarine pipelines and sub-
marine cables are required to be buried, and
those that were originally buried may have
become exposed. Mariners should use extreme
caution when operating vessels in depths of
water comparable to their draft in areas where
pipelines and cables may exist, and when
anchoring, dragging, or trawling.
Covered wells may be marked by lighted or
unlighted buoys.


ANCHORING STANDARDS OF CARE
Anchoring Standards of Care have been established for this area through Harbor
Safety Plan. These Standards of Care supplement existing regulations with good
marine practices for anchoring, and are separated into different weather categories.
If your vessel does not have a copy of the Anchoring Standards of Care, you can
download one at http://pshsc.org/about/harbor safety plan or contact (206) 443-3830.


AUTHORITIES
Hydrography and topography by the National Ocean Service, Coast
Survey, with additional data from the Corps of Engineers, and U.S
Coast Guard.


WARNING - PRUDENT MARINER
The prudent mariner will not rely solely on
any single aid to navigation, particularly on
floating aids. See U.S. Coast Guard Light List
and U.S. Coast Pilot for details.


NOAA WEATHER RADIO BROADCASTS
The NOAA Weather Radio station listed
below provides continuous weather broadcasts.
The reception range is typically 37 to 74 kilometers / 20 to 40
nautical miles from the antenna site, but can be
as much as 185 kilometers / 100 nautical miles for stations
at high elevations.

Seattle, WA KHB-60 162.550 MHz


POLLUTION REPORTS
Report all spills of oil and hazardous sub-
stances to the National Response Center via
1-800-424-8802 (toll free), or to the nearest U.S.
Coast Guard facility if telephone communication
is impossible (33 CFR 153).


RADAR REFLECTORS
Radar reflectors have been placed on many
floating aids to navigation. Individual radar
reflector identification on these aids has been
omitted from this chart.


COLREGS, 80.1395 (see note A)
International Regulations for Preventing
Collisions at Sea, 1972. The entire area of
this chart falls seaward of the COLREGS
Demarcation Line.


ADMINISTRATION AREA
The entire extent of this ENC cell falls within the limits of an
Administration Area. This area covers land, internal waters, and
territorial sea. The territorial sea is a maritime zone which the United
States exercises sovereignty extending to the airspace as well as to its
bed and subsoil. For more information, please refer to the Coast Pilot.


TIDAL INFORMATION
For tidal information see the NOS Tide Table publication or go to http://co-ops.nos.noaa.gov


ADDITIONAL INFORMATION
Additional information can be obtained at www.nauticalcharts.noaa.gov


REGULATED NAVIGATION AREA
A Regulated Navigation Area has been established by the U.S. Coast Guard.
Please see Chapter 2, U.S. Coast Pilot 7 or 33 CFR 165.1301 and 33 CFR
165.1303.


USACE HYDROGRAPHIC SURVEYS
USACE conducts hydrographic surveys to monitor navigation conditions. These surveys are not intended to
detect underwater features. Uncharted features hazardous to surface navigation are not expected but may
exist in federal channels.

END OF FILE
4 changes: 4 additions & 0 deletions fixtures/US5WA22M/US5WA22B.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
For bascule bridges, whose spans do not
open to a full upright or vertical position, unlimited
vertical clearance is not available for the entire
charted horizontal clearance.
14 changes: 14 additions & 0 deletions fixtures/US5WA22M/US5WA22C.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
One-way traffic lanes are RECOMMENDED for use by
all vessels traveling between the points involved. They have been designated to
aid in the prevention of collisions in the Puget Sound waters, but are
not intended in any way to supersede or alter the applicable Rules of the
Road. Separation zones are intended to separate inbound and outbound traffic
and to be free of ship traffic. Separation Zones should not be used except
for crossing purposes. When crossing traffic lanes and separation zones, use
extreme caution.
Precautionary Areas have been established where major lanes merge
and cross the traffic separation scheme. It is recommended that vessels proceed
with caution in these areas. Wherever practical, vessels entering or leaving the
system should do so at these precautionary areas. For more information regarding
Traffic Separation Scheme procedures and regulations, see 33 CFR 167 and / or
chapter 2 of the U.S. Coast Pilot.
5 changes: 5 additions & 0 deletions fixtures/US5WA22M/US5WA22D.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CAUTION - QUALITY OF BATHYMETRIC DATA
The areas represented by the object M_QUAL (Quality of Data) are approximate due to generalizing for
clarity. Caution is advised, particularly for nearshore navigation or voyage planning. M-QUAL represents
areas of uniform quality of bathymetric data. The CATZOC (Category of Zone of Confidence in Data) attribute
of M_QUAL provides an assessment of the overall zone of confidence.
Binary file added fixtures/US5WA22M/US5WA22M.000
Binary file not shown.
Binary file added fixtures/US5WA22M/US5WA22M.001
Binary file not shown.
Binary file added fixtures/US5WA22M/US5WA22M.002
Binary file not shown.
Binary file added fixtures/US5WA22M/US5WA22M.003
Binary file not shown.
Binary file added fixtures/US5WA22M/US5WA22M.004
Binary file not shown.
18 changes: 18 additions & 0 deletions fixtures/soundg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"features": [
{
"geometry": {
"coordinates": [ -122.4335161, 47.3136322 ],
"type": "Point"
},
"properties": {
"a_string_list": [ "a", "list", "of", "strings"],
"a_real_list": [ 0.1, 0.2 ],
"an_int_list": [ 1, 2 ],
"a_long_list": [ 5000000000, 6000000000 ]
},
"type": "Feature"
}
],
"type": "FeatureCollection"
}
21 changes: 21 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ pub fn _string(raw_ptr: *const c_char) -> String {
c_str.to_string_lossy().into_owned()
}

pub fn _string_array(raw_ptr: *mut *mut c_char) -> Vec<String> {
let mut ret_val: Vec<String> = vec![];
let mut i = 0;
unsafe {
loop {
let ptr = raw_ptr.add(i);
if ptr.is_null() {
break;
}
let next = ptr.read();
if next.is_null() {
break;
}
let value = _string(next);
i += 1;
ret_val.push(value);
}
}
ret_val
}

// TODO: inspect if this is sane...
pub fn _last_cpl_err(cpl_err_class: CPLErr::Type) -> GdalError {
let last_err_no = unsafe { gdal_sys::CPLGetLastErrorNo() };
Expand Down
72 changes: 66 additions & 6 deletions src/vector/feature.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::{_last_null_pointer_err, _string};
use crate::utils::{_last_null_pointer_err, _string, _string_array};
use crate::vector::geometry::Geometry;
use crate::vector::layer::Layer;
use crate::vector::Defn;
Expand All @@ -12,6 +12,7 @@ use std::ffi::CString;
use chrono::{Date, DateTime, Datelike, FixedOffset, TimeZone, Timelike};

use crate::errors::*;
use std::slice;

/// OGR Feature
pub struct Feature<'a> {
Expand Down Expand Up @@ -77,18 +78,49 @@ impl<'a> Feature<'a> {
let rv = unsafe { gdal_sys::OGR_F_GetFieldAsString(self.c_feature, field_id) };
Ok(FieldValue::StringValue(_string(rv)))
}
OGRFieldType::OFTStringList => {
let rv = unsafe {
let ptr = gdal_sys::OGR_F_GetFieldAsStringList(self.c_feature, field_id);
_string_array(ptr)
};
Ok(FieldValue::StringListValue(rv))
}
OGRFieldType::OFTReal => {
let rv = unsafe { gdal_sys::OGR_F_GetFieldAsDouble(self.c_feature, field_id) };
Ok(FieldValue::RealValue(rv as f64))
}
OGRFieldType::OFTRealList => {
let rv = unsafe {
let mut len: i32 = 0;
let ptr = gdal_sys::OGR_F_GetFieldAsDoubleList(self.c_feature, field_id, &mut len);
slice::from_raw_parts(ptr, len as usize).to_vec()
};
Ok(FieldValue::RealListValue(rv))
}
OGRFieldType::OFTInteger => {
let rv = unsafe { gdal_sys::OGR_F_GetFieldAsInteger(self.c_feature, field_id) };
Ok(FieldValue::IntegerValue(rv as i32))
}
OGRFieldType::OFTIntegerList => {
let rv = unsafe {
let mut len: i32 = 0;
let ptr = gdal_sys::OGR_F_GetFieldAsIntegerList(self.c_feature, field_id, &mut len);
slice::from_raw_parts(ptr, len as usize).to_vec()
};
Ok(FieldValue::IntegerListValue(rv))
}
OGRFieldType::OFTInteger64 => {
let rv = unsafe { gdal_sys::OGR_F_GetFieldAsInteger64(self.c_feature, field_id) };
Ok(FieldValue::Integer64Value(rv))
}
OGRFieldType::OFTInteger64List => {
let rv = unsafe {
let mut len: i32 = 0;
let ptr = gdal_sys::OGR_F_GetFieldAsInteger64List(self.c_feature, field_id, &mut len);
slice::from_raw_parts(ptr, len as usize).to_vec()
};
Ok(FieldValue::Integer64ListValue(rv))
}
#[cfg(feature = "datetime")]
OGRFieldType::OFTDateTime => Ok(FieldValue::DateTimeValue(
self.get_field_datetime(field_id)?,
Expand Down Expand Up @@ -295,19 +327,23 @@ impl<'a> Feature<'a> {
}

pub fn set_field(&self, field_name: &str, value: &FieldValue) -> Result<()> {
match *value {
FieldValue::RealValue(value) => self.set_field_double(field_name, value),
match value {
FieldValue::RealValue(value) => self.set_field_double(field_name, *value),
FieldValue::StringValue(ref value) => self.set_field_string(field_name, value.as_str()),
FieldValue::IntegerValue(value) => self.set_field_integer(field_name, value),
FieldValue::Integer64Value(value) => self.set_field_integer64(field_name, value),
FieldValue::IntegerValue(value) => self.set_field_integer(field_name, *value),
FieldValue::Integer64Value(value) => self.set_field_integer64(field_name, *value),

#[cfg(feature = "datetime")]
FieldValue::DateTimeValue(value) => self.set_field_datetime(field_name, value),
FieldValue::DateTimeValue(value) => self.set_field_datetime(field_name, value.clone()),

#[cfg(feature = "datetime")]
FieldValue::DateValue(value) => {
self.set_field_datetime(field_name, value.and_hms(0, 0, 0))
}
_ => Err(GdalError::UnhandledFieldType {
field_type: value.ogr_field_type(),
method_name: "OGR_Fld_GetType",
})
}
}

Expand Down Expand Up @@ -384,11 +420,16 @@ impl<'a> Drop for Feature<'a> {
}
}

#[derive(Debug, PartialEq)]
pub enum FieldValue {
IntegerValue(i32),
IntegerListValue(Vec<i32>),
Integer64Value(i64),
Integer64ListValue(Vec<i64>),
StringValue(String),
StringListValue(Vec<String>),
RealValue(f64),
RealListValue(Vec<f64>),

#[cfg(feature = "datetime")]
DateValue(Date<FixedOffset>),
Expand Down Expand Up @@ -450,4 +491,23 @@ impl FieldValue {
_ => None,
}
}

pub fn ogr_field_type(&self) -> OGRFieldType::Type {
match self {
FieldValue::IntegerValue(_) => OGRFieldType::OFTInteger,
FieldValue::IntegerListValue(_) => OGRFieldType::OFTIntegerList,
FieldValue::Integer64Value(_) => OGRFieldType::OFTInteger64,
FieldValue::Integer64ListValue(_) => OGRFieldType::OFTInteger64List,
FieldValue::StringValue(_) => OGRFieldType::OFTString,
FieldValue::StringListValue(_) => OGRFieldType::OFTStringList,
FieldValue::RealValue(_) => OGRFieldType::OFTReal,
FieldValue::RealListValue(_) => OGRFieldType::OFTRealList,

#[cfg(feature = "datetime")]
FieldValue::DateValue(_) => OGRFieldType::OFTDate,

#[cfg(feature = "datetime")]
FieldValue::DateTimeValue(_) => OGRFieldType::OFTDateTime
}
}
}
Loading

0 comments on commit f4932f9

Please sign in to comment.