Skip to main content

ReferenceSystem

Struct ReferenceSystem 

Source
pub struct ReferenceSystem {
    pub base_url: String,
    pub segments: Vec<String>,
}
Expand description

A reference system following the OGC Name Type Specification.

The format follows: http://www.opengis.net/def/crs/{authority}/{version}/{code} where:

  • {authority} designates the authority responsible for the definition of this CRS (usually “EPSG” or “OGC”)
  • {version} designates the specific version of the CRS (use “0” if there is no version)
  • {code} is the identifier for the specific coordinate reference system

That three-element form is what OGC names and what every real file uses, but it is not what makes a referenceSystem legal. The normative constraint in metadata.schema.json is a prefix pattern and nothing else:

"referenceSystem": {
  "type": "string",
  "pattern": "^(http|https)://www.opengis.net/def/crs/"
}

So .../crs/EPSG/0/4326/extra and .../crs/EPSG/0/7415/ are both legal CityJSON, and an earlier version of this type rejected them outright by demanding exactly three /-separated elements. That is the same rejects-legal defect as the old Address, and the fix is the same: stop inventing structure the format does not mandate.

Hence segments rather than three named fields. It holds the path elements after .../def/crs/ verbatim, so ReferenceSystem::to_url can rebuild any legal URL byte for byte – including a trailing slash, which is simply a final empty element. The OGC reading is still available, as ReferenceSystem::authority, ReferenceSystem::version and ReferenceSystem::code, which return None when the URL does not have that shape. Keeping the three as plain fields alongside the verbatim path was the obvious alternative and is a trap: the two representations can disagree, and then to_url silently contradicts the fields.

In JSON this is a single string, not an object, so the derive needs telling how to get between the two. #[serde(try_from/into)] does exactly that and nothing else: Serialize and Deserialize stay derived, and the conversion is ordinary TryFrom/From code that serde calls on either side of a plain String. This replaces a hand-written Serialize and Deserialize pair, which violated the crate’s derived-only rule – hand-written impls are the one place a field can be silently dropped or reshaped without any type-level trace, which is the whole reason for the rule.

Fields§

§base_url: String

Everything up to and including .../def/crs, with no trailing slash.

§segments: Vec<String>

The /-separated path elements after .../def/crs/, verbatim. OGC names the first three {authority}/{version}/{code}; the schema requires no particular number of them.

Implementations§

Source§

impl ReferenceSystem

Source

pub fn new( base_url: Option<String>, authority: String, version: String, code: String, ) -> Self

The ordinary three-element OGC form.

Source

pub fn authority(&self) -> Option<&str>

The {authority} element, or None if this URL has no such element.

Source

pub fn version(&self) -> Option<&str>

The {version} element ("0" when the CRS has no version).

Source

pub fn code(&self) -> Option<&str>

The {code} element identifying the CRS.

Source

pub fn to_url(&self) -> String

Rebuild the URL. Exact for every input ReferenceSystem::from_url accepts, whatever its element count – segments is stored verbatim, so there is nothing to reconstruct incorrectly.

Source

pub fn from_url(url: &str) -> Result<Self>

Parse a referenceSystem string.

The only thing checked is the prefix, because the prefix is the only thing metadata.schema.json constrains. The OGC three-element form is a convention this honours (see ReferenceSystem::authority and friends) but does not enforce, so a longer or shorter path is carried through rather than rejected.

Trait Implementations§

Source§

impl Clone for ReferenceSystem

Source§

fn clone(&self) -> ReferenceSystem

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ReferenceSystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ReferenceSystem

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<ReferenceSystem> for String

The two conversions #[serde(try_from = "String", into = "String")] calls. They carry no serde logic of their own – they are the same to_url and from_url the rest of the crate uses.

Source§

fn from(rs: ReferenceSystem) -> String

Converts to this type from the input type.
Source§

impl PartialEq for ReferenceSystem

Source§

fn eq(&self, other: &ReferenceSystem) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ReferenceSystem

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ReferenceSystem

Source§

impl TryFrom<String> for ReferenceSystem

Source§

type Error = CjseqError

The type returned in the event of a conversion error.
Source§

fn try_from(url: String) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.