-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(engine): update MVT handling and add error types #560
Conversation
WalkthroughThe changes in this pull request involve significant updates to the Rust project, particularly in the handling of vector tiles (MVT). A new dependency, Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
✅ Deploy Preview for reearth-flow canceled.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 17
🧹 Outside diff range and nitpick comments (8)
engine/runtime/action-sink/src/errors.rs (1)
27-27
: LGTM: New Result type alias with a minor suggestion.The addition of the
Result
type alias is a good practice that will simplify error handling throughout the codebase. It's well-implemented and follows Rust conventions.Consider adding a brief comment above the type alias to explain its purpose, for example:
/// A convenient alias for Results with SinkError as the default error type. pub type Result<T, E = SinkError> = std::result::Result<T, E>;engine/runtime/action-sink/src/file/mvt/tags.rs (2)
10-19
: LGTM: Null, String, and Bool cases are handled appropriately.The handling of Null, String, and Bool cases is correct. However, consider adding a comment explaining why Null values are ignored to improve code clarity.
Consider adding a comment to explain why Null values are ignored:
AttributeValue::Null => { - // ignore + // Ignore Null values as they don't add meaningful information to the tags }
40-43
: Consider specifying DateTime format and handling timezones.The current implementation converts DateTime to a string, which is a reasonable approach. However, it's important to ensure consistency in the string representation and handle timezone information appropriately.
Consider specifying a standard format for DateTime conversion and explicitly handling timezone information:
AttributeValue::DateTime(v) => { - tags.extend(tags_enc.add(name, v.to_string().into())); + // Use a specific format and consider UTC conversion for consistency + tags.extend(tags_enc.add(name, v.to_rfc3339().into())); }This ensures that all DateTime values are consistently formatted and timezone information is preserved.
engine/tools/mvt/index.html (1)
40-40
: Approve change in layer name and suggest documentation update.The update to "luse:LandUse" provides more specificity and suggests a hierarchical structure in the layer naming. This aligns with the PR objective of improving MVT handling.
Consider updating any relevant documentation to reflect this change in layer naming convention, especially if it's part of a broader restructuring of layer names.
engine/runtime/examples/plateau/testdata/workflow/data-convert/04-luse-lsld/workflow.yml (1)
124-132
: Approve changes and suggest minor improvementThe changes to this node significantly improve the workflow by replacing the no-operation sink with an actual MVT writer. This aligns well with the PR objectives of updating MVT handling. The configuration looks good, with appropriate zoom levels for city-level data and flexible output path setting.
Consider adding a comment explaining the purpose of the MVT writer and the chosen zoom levels. This would improve the maintainability of the configuration. For example:
name: mvtWriter type: action action: MVTWriter with: # Write Map Vector Tiles (MVT) for city-level data # Zoom levels 12-18 provide a good range for detailed urban features format: mvt minZoom: 12 maxZoom: 18 output: | env.get("outputPath")engine/runtime/geometry/src/types/polygon.rs (1)
384-400
: LGTM! Consider optimizing and clarifying lifetime usage.The implementation of
From<Polygon3D<f64>> for NPolygon2<'a>
looks correct and handles both exterior and interior rings properly. However, there are a few points to consider:
- The use of
clone()
on input polygon components could be inefficient for large polygons. Consider using references or moving the data if possible.- The
'a
lifetime in the output typeNPolygon2<'a>
suggests borrowed data, but the implementation doesn't seem to utilize this. Consider clarifying the lifetime usage or removing it if not needed.Consider the following optimizations:
impl<'a> From<Polygon3D<f64>> for NPolygon2<'a> { #[inline] fn from(poly: Polygon3D<f64>) -> Self { let interiors: Vec<NLineString2> = poly .interiors() .iter() - .map(|interior| interior.clone().into()) + .map(|interior| interior.into()) .collect(); let mut npoly = NPolygon2::new(); - let exterior: NLineString2 = poly.exterior().clone().into(); + let exterior: NLineString2 = poly.exterior().into(); npoly.add_ring(&exterior); for interior in interiors.iter() { npoly.add_ring(interior); } npoly } }These changes remove unnecessary
clone()
calls, potentially improving performance for large polygons.engine/runtime/action-sink/src/file/mvt/slice.rs (1)
98-275
: Improve variable naming for better readabilityVariables like
k1
,k2
,a
, andb
are not self-explanatory, which can make the code harder to understand. Using more descriptive variable names would enhance readability.For instance, rename
k1
andk2
tomin_bound
andmax_bound
, anda
andb
toprevious_point
andcurrent_point
. This will make the code clearer to other developers.engine/runtime/action-sink/src/file/mvt/sink.rs (1)
98-110
: Add documentation comments to public structsPublic structs
MVTWriterCommonParam
andMVTWriterParam
lack documentation comments. Adding them will improve code clarity and aid users in understanding the purpose of these structs.Consider adding documentation as follows:
/// Common parameters for the MVT Writer. #[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)] #[serde(rename_all = "camelCase")] pub struct MVTWriterCommonParam { pub(super) output: Expr, } /// Parameters for the MVT Writer. #[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)] #[serde(rename_all = "camelCase")] pub struct MVTWriterParam { pub(super) output: Expr, pub(super) min_zoom: u8, pub(super) max_zoom: u8, }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (1)
engine/Cargo.lock
is excluded by!**/*.lock
,!**/*.lock
📒 Files selected for processing (15)
- engine/Cargo.toml (1 hunks)
- engine/runtime/action-sink/Cargo.toml (2 hunks)
- engine/runtime/action-sink/src/errors.rs (1 hunks)
- engine/runtime/action-sink/src/file.rs (0 hunks)
- engine/runtime/action-sink/src/file/mvt.rs (1 hunks)
- engine/runtime/action-sink/src/file/mvt/sink.rs (1 hunks)
- engine/runtime/action-sink/src/file/mvt/slice.rs (1 hunks)
- engine/runtime/action-sink/src/file/mvt/tags.rs (1 hunks)
- engine/runtime/action-sink/src/file/types.rs (1 hunks)
- engine/runtime/action-sink/src/file/vector_tile.rs (0 hunks)
- engine/runtime/action-sink/src/mapping.rs (1 hunks)
- engine/runtime/examples/plateau/testdata/workflow/data-convert/04-luse-lsld/workflow.yml (1 hunks)
- engine/runtime/geometry/src/types/line_string.rs (2 hunks)
- engine/runtime/geometry/src/types/polygon.rs (2 hunks)
- engine/tools/mvt/index.html (2 hunks)
💤 Files with no reviewable changes (2)
- engine/runtime/action-sink/src/file.rs
- engine/runtime/action-sink/src/file/vector_tile.rs
🧰 Additional context used
🔇 Additional comments (17)
engine/runtime/action-sink/src/file/types.rs (1)
1-4
: Consider the implications of increased module visibilityThe visibility of the
material
,metadata
,slice
, andtree
modules has been changed frompub(super)
topub(crate)
. This increases their accessibility throughout the entire crate, which may align with the PR objective of updating MVT handling.However, please consider the following:
- Increased visibility can lead to tighter coupling between different parts of the crate, potentially making future maintenance and refactoring more challenging.
- Ensure that this change is necessary and that it doesn't violate any encapsulation principles you might have in place.
To better understand the impact of this change, let's check where these modules are now being used:
This will help us understand if the increased visibility is being utilized and if it's necessary for the MVT handling updates mentioned in the PR objectives.
✅ Verification successful
[/run_scripts]
No external usages detected for the updated modules
The visibility of the
material
,metadata
,slice
, andtree
modules has been changed frompub(super)
topub(crate)
. However, no usages of these modules were found outside their original scope within the crate. This change does not introduce additional coupling and appears safe based on the current analysis.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Find usages of the newly exposed modules across the crate echo "Searching for usages of the material module:" rg --type rust "use (crate|super)::file::types::material" ./engine/runtime/action-sink echo "Searching for usages of the metadata module:" rg --type rust "use (crate|super)::file::types::metadata" ./engine/runtime/action-sink echo "Searching for usages of the slice module:" rg --type rust "use (crate|super)::file::types::slice" ./engine/runtime/action-sink echo "Searching for usages of the tree module:" rg --type rust "use (crate|super)::file::types::tree" ./engine/runtime/action-sinkLength of output: 730
Script:
#!/bin/bash # Description: Comprehensive search for usages of the material, metadata, slice, and tree modules across the entire crate echo "Searching for all usages of the material module:" rg --type rust "file::types::material" ./engine/runtime/action-sink echo "Searching for all usages of the metadata module:" rg --type rust "file::types::metadata" ./engine/runtime/action-sink echo "Searching for all usages of the slice module:" rg --type rust "file::types::slice" ./engine/runtime/action-sink echo "Searching for all usages of the tree module:" rg --type rust "file::types::tree" ./engine/runtime/action-sinkLength of output: 678
engine/runtime/action-sink/src/errors.rs (2)
17-18
: LGTM: New error variant for MVT writer.The addition of the
MvtWriter
error variant is consistent with the existing error handling structure and aligns with the PR objective of updating MVT handling. This change enhances the error reporting capabilities for MVT-related operations.
Line range hint
1-27
: Overall assessment: Good improvements to error handling.The changes in this file enhance the error handling capabilities for MVT operations and simplify the use of Result types throughout the codebase. These improvements align well with the PR's objective of updating MVT handling. The implementation is consistent with existing code patterns and Rust best practices.
engine/runtime/action-sink/src/mapping.rs (1)
10-10
: LGTM! Verify consistency across the codebase.The update to the import path for
MVTSinkFactory
looks good. This change reflects a restructuring of themvt
module, which is likely part of a larger refactoring effort to improve code organization.To ensure consistency across the codebase, please run the following script:
This script will help ensure that the import path has been updated consistently throughout the project.
✅ Verification successful
LGTM!
All imports of
MVTSinkFactory
have been updated to the new path consistently across the codebase. No remaining old imports or misuse found.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that all imports of MVTSinkFactory use the new path # Test 1: Search for any remaining old imports echo "Checking for any remaining old imports of MVTSinkFactory:" rg --type rust "use .*mvt::MVTSinkFactory" # Test 2: Verify new imports echo "Verifying new imports of MVTSinkFactory:" rg --type rust "use .*mvt::sink::MVTSinkFactory" # Test 3: Check for any direct uses of MVTSinkFactory without import echo "Checking for any direct uses of MVTSinkFactory without import:" rg --type rust "MVTSinkFactory" -g '!**/mapping.rs'Length of output: 659
engine/runtime/action-sink/src/file/mvt/tags.rs (2)
1-9
: LGTM: Imports and function signature are well-defined.The imports and function signature are appropriate for the task. The use of mutable references for
tags
andtags_enc
is correct, allowing the function to modify these parameters in-place.
1-44
: Overall, the implementation is well-structured with room for minor improvements.The
convert_properties
function effectively handles various attribute types, converting them into a standardized tag format. The code is generally well-organized and easy to follow. Consider implementing the suggested improvements:
- Add a comment explaining why Null values are ignored.
- Handle potential unrepresented number types in the Number case.
- Consider adding a depth limit for recursive Map handling to prevent potential stack overflow.
- Specify a standard format for DateTime conversion and handle timezone information consistently.
These changes will enhance the robustness and clarity of the code.
engine/tools/mvt/index.html (3)
50-50
: Request clarification on camera position change.The initial camera position has been moved to a new geographical location. While this change doesn't directly relate to the stated PR objectives (updating MVT handling and adding error types), it might be relevant to showcase the updates.
Could you please clarify the reason for this change? Is it related to the MVT updates, or is it to focus on a specific area that better demonstrates the changes made in this PR?
Line range hint
1-53
: Summary of changes and their impactThe changes in this file improve the MVT handling by:
- Updating the MVT source to use the more efficient
.pbf
format.- Providing a more specific layer name, which could improve data organization.
- Changing the initial camera position (reason to be clarified).
These updates align well with the PR objectives and should enhance the functionality of the MVT display. Ensure that the new MVT endpoint is properly set up and consider updating any relevant documentation to reflect these changes.
39-39
: Approve change in MVT source and suggest verification.The update from
.mvt
to.pbf
format and the change in port number align with the PR objective of updating MVT handling. The.pbf
format is more efficient for vector tiles.Please verify that the new endpoint (http://localhost:8004) is correctly set up and serving the expected
.pbf
files. Run the following command to check:engine/runtime/action-sink/Cargo.toml (1)
33-33
: LGTM: Addition ofbincode
dependency.The addition of
bincode
as a workspace dependency is appropriate. This crate is commonly used for efficient binary serialization and deserialization, which aligns well with the PR's objective of updating MVT (Map Vector Tiles) handling. Using the workspace dependency ensures version consistency across the project.engine/Cargo.toml (1)
81-81
: Approve with suggestions: bincode dependency additionThe addition of the
bincode
dependency aligns well with the PR objectives of updating MVT handling, as it can potentially improve the efficiency of data serialization and deserialization.However, I have a few suggestions:
The use of a pre-release version (2.0.0-rc.3) may introduce instability. Consider documenting the specific reason for choosing this version over the latest stable release.
It's recommended to monitor the
bincode
repository for a stable 2.0.0 release and update accordingly when it becomes available.The careful selection of features (disabling defaults and enabling only
serde
andstd
) is commendable. Ensure this configuration is consistently applied across the project wherebincode
is used.To ensure the
bincode
dependency is used consistently across the project, run the following script:This script will help identify where
bincode
is being used and ensure that the feature flags are consistently applied.engine/runtime/geometry/src/types/line_string.rs (3)
Line range hint
301-309
: LGTM: Improved type clarity with LineString2DThe change from
LineString<f64, NoValue>
toLineString2D<f64>
improves type clarity while maintaining the same functionality. This aligns well with the new type alias introduced earlier in the file.
Line range hint
324-332
: LGTM: Enhanced type clarity with LineString3DThe change from
LineString<f64>
toLineString3D<f64>
improves type clarity while maintaining the same functionality. This aligns well with the new type alias introduced earlier in the file and ensures consistency with the 2D version.
313-322
: Approve with caution: Potential data loss in 3D to 2D conversionThe implementation correctly converts a
LineString3D<f64>
toNLineString2<'a>
. However, this conversion discards the z-coordinate, which may lead to loss of important information in some use cases.Consider adding a warning or documentation about the z-coordinate being dropped during this conversion. You may also want to verify if there are any use cases in the codebase where this loss of information could be problematic.
✅ Verification successful
Verified: Conversion is locally scoped with minimal impact
The
From<LineString3D<f64>> for NLineString2<'a>
conversion is only utilized withinengine/runtime/geometry/src/types/line_string.rs
. This limited usage means that potential data loss from discarding the z-coordinate is confined and does not affect other parts of the codebase.It's recommended to add documentation or comments to highlight that the z-coordinate is intentionally omitted during this conversion to inform future developers.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for usages of this conversion in the codebase rg --type rust "From<LineString3D<f64>> for NLineString2"Length of output: 164
engine/runtime/action-sink/src/file/mvt.rs (1)
1-3
: Restructuring improves modularity and code organizationThe addition of modules
sink
,slice
, andtags
effectively modularizes MVT functionalities, enhancing code maintainability and readability.engine/runtime/action-sink/src/file/mvt/slice.rs (1)
27-28
: Ensurebuffer_pixels
correctly scales withextent
The calculation of
buffer
asextent * buffer_pixels / 256
assumes thatbuffer_pixels
scales linearly withextent
. Verify that this scaling aligns with the intended behavior, especially ifbuffer_pixels
might vary or ifextent
can become very large.To confirm the correctness of the buffer calculation, you can verify the values produced for different
max_detail
andbuffer_pixels
:engine/runtime/action-sink/src/file/mvt/sink.rs (1)
388-390
: Log or handle skipped features with empty geometryIn the
make_tile
function, features with empty geometry are silently skipped on lines 388-390. It might be beneficial to log these occurrences or handle them appropriately to ensure data integrity.Please confirm if silently skipping features is the intended behavior. If not, consider adding logging or error handling:
if geometry.is_empty() { // Log warning or handle the empty geometry case eprintln!("Warning: Encountered feature with empty geometry."); continue; }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🧹 Outside diff range and nitpick comments (1)
engine/runtime/action-sink/src/file/mvt/sink.rs (1)
1-35
: Imports look good, but consider organizing themThe imports are comprehensive and cover all necessary dependencies. However, they could be better organized for improved readability.
Consider grouping the imports as follows:
- Standard library imports
- External crate imports
- Internal module imports
This organization can help developers quickly identify the origin of each import.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
- engine/runtime/action-sink/src/file/mvt/sink.rs (1 hunks)
- engine/runtime/action-sink/src/file/mvt/tags.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- engine/runtime/action-sink/src/file/mvt/tags.rs
🧰 Additional context used
🔇 Additional comments (2)
engine/runtime/action-sink/src/file/mvt/sink.rs (2)
1-424
: Overall assessment: Solid implementation with room for improvementThe MVT writing functionality implemented in this file is comprehensive and well-structured. However, there are several areas where improvements can be made:
- Configurability: Many hardcoded values (e.g.,
max_detail
,buffer_pixels
,default_detail
,min_detail
) should be made configurable through theMVTWriterParam
struct.- Error handling: Consider using custom error types or the
anyhow
crate for more expressive and easier-to-handle errors throughout the file.- Code organization: Some functions, particularly
make_tile
, could benefit from being broken down into smaller, more focused functions.- Thread management: The use of
std::thread::scope
might cause issues on stable Rust and should be replaced with a stable alternative.Addressing these points will improve the flexibility, maintainability, and robustness of the code. Despite these suggestions, the overall implementation is solid and provides a good foundation for MVT writing functionality.
148-161
:⚠️ Potential issueCaution:
std::thread::scope
is a nightly featureThe
finish
method usesstd::thread::scope
, which is currently a nightly-only feature in Rust. This may cause issues when compiling with stable Rust.Consider using a stable alternative for managing thread lifetimes, such as the
crossbeam
crate's scoped threads. Here's how you can verify ifstd::thread::scope
is available:If the output doesn't include "thread_local": true, you should replace
std::thread::scope
with a stable alternative.
Overview
What I've done
What I haven't done
How I tested
Screenshot
Which point I want you to review particularly
Memo
Summary by CodeRabbit
Release Notes
New Features
Improvements
Bug Fixes
Documentation