Skip to content

Commit

Permalink
mvt: min_z, max_z options
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscorn committed Feb 27, 2024
1 parent 6e9f25f commit 365fb20
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use nusamai::pipeline::Canceller;
use nusamai::sink::DataSinkProvider;
use nusamai::sink::{
cesiumtiles::CesiumTilesSinkProvider, czml::CzmlSinkProvider, geojson::GeoJsonSinkProvider,
gltf::GltfSinkProvider, gpkg::GpkgSinkProvider, kml::KmlSinkProvider, mvt::MVTSinkProvider,
gltf::GltfSinkProvider, gpkg::GpkgSinkProvider, kml::KmlSinkProvider, mvt::MvtSinkProvider,
ply::StanfordPlySinkProvider, serde::SerdeSinkProvider, shapefile::ShapefileSinkProvider,
};
use nusamai::source::citygml::CityGmlSourceProvider;
Expand Down Expand Up @@ -39,7 +39,7 @@ fn select_sink_provider(filetype: &str) -> Box<dyn DataSinkProvider> {
"serde" => Box::new(SerdeSinkProvider {}),
"geojson" => Box::new(GeoJsonSinkProvider {}),
"gpkg" => Box::new(GpkgSinkProvider {}),
"mvt" => Box::new(MVTSinkProvider {}),
"mvt" => Box::new(MvtSinkProvider {}),

Check warning on line 42 in app/src-tauri/src/main.rs

View check run for this annotation

Codecov / codecov/patch

app/src-tauri/src/main.rs#L42

Added line #L42 was not covered by tests
"shapefile" => Box::new(ShapefileSinkProvider {}),
"czml" => Box::new(CzmlSinkProvider {}),
"kml" => Box::new(KmlSinkProvider {}),
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod transformer;
pub static BUILTIN_SINKS: &[&dyn sink::DataSinkProvider] = &[
&sink::cesiumtiles::CesiumTilesSinkProvider {},
&sink::gpkg::GpkgSinkProvider {},
&sink::mvt::MVTSinkProvider {},
&sink::mvt::MvtSinkProvider {},
&sink::geojson::GeoJsonSinkProvider {},
&sink::czml::CzmlSinkProvider {},
&sink::gltf::GltfSinkProvider {},
Expand Down
60 changes: 48 additions & 12 deletions nusamai/src/sink/mvt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ use slice::slice_cityobj_geoms;
use sort::BincodeExternalChunk;
use tags::convert_properties;

pub struct MVTSinkProvider {}
pub struct MvtSinkProvider {}

impl DataSinkProvider for MVTSinkProvider {
impl DataSinkProvider for MvtSinkProvider {
fn info(&self) -> SinkInfo {
SinkInfo {
id_name: "mvt".to_string(),
Expand All @@ -54,22 +54,53 @@ impl DataSinkProvider for MVTSinkProvider {
}),
},
);
// TODO: min Zoom
// TODO: max Zoom
params.define(
"min_z".into(),
ParameterEntry {
description: "Minumum zoom level".into(),
required: true,
parameter: ParameterType::Integer(IntegerParameter {
value: Some(7),
min: Some(0),
max: Some(20),
}),
},
);
params.define(
"max_z".into(),
ParameterEntry {
description: "Maximum zoom level".into(),
required: true,
parameter: ParameterType::Integer(IntegerParameter {
value: Some(15),
min: Some(0),
max: Some(20),
}),
},
);
params
}

fn create(&self, params: &Parameters) -> Box<dyn DataSink> {
let output_path = get_parameter_value!(params, "@output", FileSystemPath);
let min_z = get_parameter_value!(params, "min_z", Integer).unwrap() as u8;
let max_z = get_parameter_value!(params, "max_z", Integer).unwrap() as u8;

Box::<MVTSink>::new(MVTSink {
Box::<MvtSink>::new(MvtSink {
output_path: output_path.as_ref().unwrap().into(),
mvt_options: MvtParams { min_z, max_z },
})
}
}

struct MVTSink {
struct MvtSink {
output_path: PathBuf,
mvt_options: MvtParams,
}

struct MvtParams {
min_z: u8,
max_z: u8,
}

#[derive(Serialize, Deserialize, deepsize::DeepSizeOf)]
Expand All @@ -85,7 +116,7 @@ struct SlicedFeature<'a> {
properties: nusamai_citygml::object::Value,
}

impl DataSink for MVTSink {
impl DataSink for MvtSink {
fn make_transform_requirements(&self) -> transformer::Requirements {
transformer::Requirements {
key_value: transformer::KeyValueSpec::DotNotation,
Expand All @@ -105,9 +136,13 @@ impl DataSink for MVTSink {
// Slicing geometry along the tile boundaries
{
s.spawn(|| {
if let Err(error) =
geometry_slicing_stage(feedback, upstream, tile_id_conv, sender_sliced)
{
if let Err(error) = geometry_slicing_stage(
feedback,
upstream,
tile_id_conv,
sender_sliced,
&self.mvt_options,
) {
feedback.report_fatal_error(error);
}
});
Expand Down Expand Up @@ -149,6 +184,7 @@ fn geometry_slicing_stage(
upstream: mpsc::Receiver<crate::pipeline::Parcel>,
tile_id_conv: TileIdMethod,
sender_sliced: mpsc::SyncSender<SerializedSlicedFeature>,
mvt_options: &MvtParams,
) -> Result<()> {
// Convert CityObjects to sliced features
upstream.into_iter().par_bridge().try_for_each(|parcel| {
Expand All @@ -158,8 +194,8 @@ fn geometry_slicing_stage(
let buffer_pixels = 5;
slice_cityobj_geoms(
&parcel.entity,
7,
16,
mvt_options.min_z,
mvt_options.max_z,
max_detail,
buffer_pixels,
|(z, x, y), mpoly| {
Expand Down
2 changes: 1 addition & 1 deletion nusamai/tests/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn run_gpkg_sink() {

#[test]
fn run_mvt_sink() {
simple_run_sink(sink::mvt::MVTSinkProvider {}, "/tmp/nusamai/mvt/".into());
simple_run_sink(sink::mvt::MvtSinkProvider {}, "/tmp/nusamai/mvt/".into());
}

#[test]
Expand Down

0 comments on commit 365fb20

Please sign in to comment.