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: ValueImplementations§
Source§impl CityJSON
impl CityJSON
pub fn new() -> Self
Sourcepub fn from_str(s: &str) -> Result<Self>
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}pub fn get_metadata(&self) -> Self
pub fn get_cjfeature(&self, i: usize) -> Option<CityJSONFeature>
pub fn add_cjfeature(&mut self, cjf: &mut CityJSONFeature)
pub fn remove_duplicate_vertices(&mut self)
pub fn update_transform(&mut self)
pub fn number_of_city_objects(&self) -> usize
pub fn sort_cjfeatures(&mut self, ss: SortingStrategy)
pub fn add_material(&mut self, jm: MaterialObject) -> usize
Trait Implementations§
Source§impl<'de> Deserialize<'de> for CityJSON
impl<'de> Deserialize<'de> for CityJSON
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for CityJSON
Auto Trait Implementations§
impl Freeze for CityJSON
impl RefUnwindSafe for CityJSON
impl Send for CityJSON
impl Sync for CityJSON
impl Unpin for CityJSON
impl UnsafeUnpin for CityJSON
impl UnwindSafe for CityJSON
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more