Crate jgdtrans

Source
Expand description

§jgdtrans

Unofficial coordinate transformer by Gridded Correction Parameter which Geospatial Information Authority of Japan (GIAJ) distributing 1.

国土地理院が公開しているパラメータファイル(par ファイル)による座標変換(順逆変換)を提供します 1

use std::error::Error;
use std::fs;

use jgdtrans::{Format, Point, Transformer};

fn main() -> Result<(), Box<dyn Error>> {
    // Deserialize par-formatted file, e.g. SemiDyna2023.par
    let s = fs::read_to_string("SemiDyna2023.par").expect("file not found 'SemiDyna2023.par'");
    let tf = Transformer::from_str(&s, Format::SemiDynaEXE)?;

    // Makes the origin of transformation
    let origin = Point::new_unchecked(35.0, 135.0, 2.34);
    // Prints Point { latitude: 35.0, longitude: 135.0, altitude: 2.34 }
    println!("{origin:?}");

    // Perform forward transformation resulting a Point
    let result = tf.forward(&origin)?;
    // Prints Point { latitude: 34.99999831111111, longitude: 135.00000621666666, altitude: 2.33108 }
    println!("{result:?}");

    // Perform backward transformation
    let p = tf.backward(&result)?;
    // Prints Point { latitude: 35.0, longitude: 135.0, altitude: 2.34 }
    println!("{p:?}");

    // Perform backward transformation compatible to the GIAJ web app/APIs
    let q = tf.backward_compat(&result)?;
    // Prints Point { latitude: 34.999999999999986, longitude: 135.0, altitude: 2.339999999105295 }
    println!("{q:?}");

    Ok(())
}

Features:

This package does not contain parameter files, download it from GIAJ 2.

このパッケージはパラメータファイルを提供しません。公式サイトよりダウンロードしてください 2

We use TKY2JGD for Windows Ver.1.3.79 3 as a reference.

§Optional Features

  • serde: supports serialization/deserialization by serde crate, this requires dependency on serde.

§Serialization and Deserialization

§Par (Gridded Correction Parameter)

We provide APIs, ParData::from_str.

use std::error::Error;

use jgdtrans::{Format, ParData};

let s = fs::read_to_string("SemiDyna2023.par").expect("file not found 'SemiDyna2023.par'");
let data = ParData::from_str(&s, Format::SemiDynaEXE)?;

§Json

It supports (de)serialization by serde crate for all struct including Transformer (deserialized object of par-formatted data) only when the feature serde is enabled. We show a (de)serialization example to/from json;

use std::collections::HashMap;

use serde_json;

use jgdtrans::{
    Format,
    Parameter,
    ParData,
};

fn main() -> serde_json::Result<()> {
    let data = ParData::new(
        Format::TKY2JGD,
        HashMap::from([(12345678, Parameter::new(1., 2., 3.))])
    );

    // Serialize to json
    let json = serde_json::to_string(&data)?;
    assert_eq!(
        json,
        r#"{"format":"TKY2JGD","parameter":{"12345678":{"latitude":1.0,"longitude":2.0,"altitude":3.0}}}"#
    );

    // Deserialize from json
    let result: ParData = serde_json::from_str(&json)?;
    assert_eq!(result.format, Format::TKY2JGD);
    assert_eq!(result.parameter, HashMap::from([(12345678, Parameter::new(1., 2., 3.)), ]));
    assert_eq!(result.description, None);
    Ok(())
}

  1. Geospatial Information Authority of Japan (GIAJ, 国土地理院): https://www.gsi.go.jp/, (English) https://www.gsi.go.jp/ENGLISH/

  2. TKY2JGD: https://www.gsi.go.jp/sokuchikijun/tky2jgd_download.html; PatchJGD, PatchJGD(H) and HyokoRev: https://www.gsi.go.jp/sokuchikijun/sokuchikijun41012.html; SemiDynaEXE: https://www.gsi.go.jp/sokuchikijun/semidyna.html; geonetF3 and ITRF2014 (POS2JGD): https://positions.gsi.go.jp/cdcs/

  3. TKY2JGD for Windows Ver.1.3.79 (reference implementation): https://www.gsi.go.jp/sokuchikijun/tky2jgd_download.html released under 国土地理院コンテンツ利用規約 which compatible to CC BY 4.0. 

  4. Other implementation: Python https://github.com/paqira/jgdtrans-py, Java https://github.com/paqira/jgdtrans-java, JavaScript/TypeScript https://github.com/paqira/jgdtrans-js

Modules§

dms
Provides utilities for DMS notation degree.
mesh
Provides utilities handling mesh.

Structs§

Correction
The transformation correction.
ParData
Data of par file.
ParParser
Parser of par-formatted &str.
Parameter
The parameter triplet.
ParseParError
An error which can be returned on parsing par-formatted text.
Point
Represents a position on the Earth, a triplet latitude, longitude and altitude.
StatisticData
The statistics of parameter.
Statistics
The statistical summary of parameter.
TransformError
An error which can be returned on coordinate transforming.
Transformer
The coordinate Transformer, and represents a deserializing result of par-formatted data.
TransformerBuilder
The builder of Transformer.

Enums§

Format
Represents format of par-formatted text.
MeshUnit
The mesh unit, or approximate length of cell’s edge.
ParseParErrorKind
An error kind of ParseParError.
TransformErrorKind
An error kind used by TransformError.

Traits§

ParameterData
Trait for statistical analysis.
ParameterSet
Trait for transformation.