Skip to main content

CityJSON

Struct CityJSON 

Source
pub struct CityJSON {
    pub thetype: String,
    pub version: String,
    pub transform: Transform,
    pub city_objects: HashMap<String, CityObject>,
    pub vertices: Vec<Vec<i64>>,
    pub metadata: Option<Metadata>,
    pub appearance: Option<Appearance>,
    pub geometry_templates: Option<GeometryTemplates>,
    pub extensions: Option<HashMap<String, Extension>>,
    pub other: Value,
    /* private fields */
}

Fields§

§thetype: String§version: String§transform: Transform§city_objects: HashMap<String, CityObject>§vertices: Vec<Vec<i64>>§metadata: Option<Metadata>§appearance: Option<Appearance>§geometry_templates: Option<GeometryTemplates>§extensions: Option<HashMap<String, Extension>>§other: Value

Implementations§

Source§

impl CityJSON

Source

pub fn new() -> Self

Source

pub fn from_str(s: &str) -> Result<Self>

Examples found in repository?
examples/obj_convert.rs (line 29)
6fn main() -> std::io::Result<()> {
7    // Path to the sample CityJSON file
8    let file_path = Path::new("data/1b_w_texture.city.json");
9
10    // Ensure the file exists
11    if !file_path.exists() {
12        println!("Sample file not found: {:?}", file_path);
13        println!("Available files in data directory:");
14        for entry in std::fs::read_dir("data")? {
15            let entry = entry?;
16            println!("  {:?}", entry.path());
17        }
18        return Ok(());
19    }
20
21    // Read the CityJSON file
22    let mut file = File::open(file_path)?;
23    let mut contents = String::new();
24    file.read_to_string(&mut contents)?;
25
26    println!("Converting {} to OBJ format...", file_path.display());
27
28    // Parse into CityJSON
29    let city_json = CityJSON::from_str(&contents).unwrap();
30
31    // Output file path
32    let output_path = "output.obj";
33
34    // Convert to OBJ and save to file
35    obj::to_obj_file(&city_json, output_path)?;
36
37    println!("Conversion complete. OBJ file saved to: {}", output_path);
38
39    // Print some stats about the OBJ file
40    let metadata = std::fs::metadata(output_path)?;
41    println!("OBJ file size: {} bytes", metadata.len());
42
43    // Count number of vertices and faces in the OBJ file
44    let obj_contents = std::fs::read_to_string(output_path)?;
45    let vertex_count = obj_contents
46        .lines()
47        .filter(|line| line.starts_with("v "))
48        .count();
49    let face_count = obj_contents
50        .lines()
51        .filter(|line| line.starts_with("f "))
52        .count();
53
54    println!("OBJ statistics:");
55    println!("  Vertices: {}", vertex_count);
56    println!("  Faces: {}", face_count);
57
58    Ok(())
59}
Source

pub fn get_metadata(&self) -> Self

Source

pub fn get_cjfeature(&self, i: usize) -> Option<CityJSONFeature>

Source

pub fn add_cjfeature(&mut self, cjf: &mut CityJSONFeature)

Source

pub fn remove_duplicate_vertices(&mut self)

Source

pub fn update_transform(&mut self)

Source

pub fn number_of_city_objects(&self) -> usize

Source

pub fn sort_cjfeatures(&mut self, ss: SortingStrategy)

Source

pub fn add_material(&mut self, jm: MaterialObject) -> usize

Trait Implementations§

Source§

impl Clone for CityJSON

Source§

fn clone(&self) -> CityJSON

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 CityJSON

Source§

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

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

impl<'de> Deserialize<'de> for CityJSON

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 PartialEq for CityJSON

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for CityJSON

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 CityJSON

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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