-
-
Notifications
You must be signed in to change notification settings - Fork 306
Add auto_webmercator to COG
#1893
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
base: main
Are you sure you want to change the base?
Changes from 27 commits
05d8465
4108e8b
55a5ee1
df8c954
209224f
a212c37
17d0528
aaed0d1
bfe18cc
3a4a946
c5e4b9a
7981a38
40b5ee3
c8010ec
32dab67
1bab765
f571457
dbc603a
e79b088
0f2ee38
02f425a
1ecd40a
8a9d551
acd389e
cf6ac10
843c016
8292dde
3cbd185
73b8b7c
f5da83c
78c2a99
73331e1
c9a071f
0cd936f
b48a52b
92baf2a
a348677
0145c8e
04c4eb1
7d7ac8a
326fcd8
17308ab
6aad230
fa372c6
0b1cb8c
bf8f726
b6039a7
ada9be0
0833a42
ccba0ee
a348df2
d4b0f83
5f194bb
51270d4
8e35aa1
1f04451
f4ad640
a8e716a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -267,6 +267,30 @@ pub fn tile_index(lng: f64, lat: f64, zoom: u8) -> (u32, u32) { | |
| (col, row) | ||
| } | ||
|
|
||
| /// Convert min/max XYZ tile coordinates to a bounding box values in Web Mercator. | ||
| #[must_use] | ||
| pub fn xyz_to_bbox_webmercator( | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have already a xyz_to_bbox actually but its result is not in 3857
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add it here?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, comparing in the doc string the two seems sensible. Moreover, we should likely use |
||
| zoom: u8, | ||
| min_x: u32, | ||
| min_y: u32, | ||
| max_x: u32, | ||
| max_y: u32, | ||
| ) -> [f64; 4] { | ||
| assert!(zoom <= MAX_ZOOM, "zoom {zoom} must be <= {MAX_ZOOM}"); | ||
|
|
||
| let tile_length = EARTH_CIRCUMFERENCE / f64::from(1_u32 << zoom); | ||
|
|
||
| let left_down_bbox = tile_bbox(min_x, max_y, tile_length); | ||
| let right_top_bbox = tile_bbox(max_x, min_y, tile_length); | ||
|
|
||
| [ | ||
| left_down_bbox[0], | ||
| left_down_bbox[1], | ||
| right_top_bbox[2], | ||
| right_top_bbox[3], | ||
| ] | ||
| } | ||
|
|
||
| /// Convert min/max XYZ tile coordinates to a bounding box values. | ||
| /// | ||
| /// The result is `[min_lng, min_lat, max_lng, max_lat]` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,11 @@ use crate::file_config::{ConfigExtras, FileResult, SourceConfigExtras}; | |
| pub struct CogConfig { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should not serialize |
||
| #[serde(flatten)] | ||
| pub unrecognized: UnrecognizedValues, | ||
|
|
||
| /// Default false | ||
| /// If enabled, martin will automatically serve COG as a [WebMercatorQuad](https://docs.ogc.org/is/17-083r2/17-083r2.html#72) service, the tiles will be cliped and merged internally to be aligned with the Web Mercator grid. | ||
| /// Note: Just work for COG files with a Web Mercator CRS (EPSG:3857). | ||
| pub auto_web: Option<bool>, | ||
| } | ||
|
|
||
| impl ConfigExtras for CogConfig { | ||
|
|
@@ -27,7 +32,32 @@ impl SourceConfigExtras for CogConfig { | |
| } | ||
|
|
||
| async fn new_sources(&self, id: String, path: PathBuf) -> FileResult<Box<dyn Source>> { | ||
| let cog = CogSource::new(id, path)?; | ||
| let cog = CogSource::new(id, path, self.auto_web.unwrap_or(false))?; | ||
| Ok(Box::new(cog)) | ||
| } | ||
|
|
||
| async fn new_sources_with_config( | ||
| &self, | ||
| id: String, | ||
| path: PathBuf, | ||
| config: serde_yaml::Value, | ||
| ) -> FileResult<Box<dyn Source>> { | ||
| let source_auto_web = if let serde_yaml::Value::Mapping(map) = &config { | ||
| if let Some(auto_web_value) = map.get(serde_yaml::Value::String("auto_web".to_string())) | ||
| { | ||
| match auto_web_value { | ||
| serde_yaml::Value::Bool(b) => Some(*b), | ||
| _ => None, | ||
| } | ||
| } else { | ||
| None | ||
| } | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| let auto_web = source_auto_web.unwrap_or_else(|| self.auto_web.unwrap_or(false)); | ||
| let cog = CogSource::new(id, path, auto_web)?; | ||
| Ok(Box::new(cog)) | ||
| } | ||
|
|
||
|
|
||
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.
as far as I remember these two need to be marked as "please always optimise these at O3" as otherwise debug builds handling images are.. painfull.