Repository navigation
feat(crs): write GeoJSON, CSV, KML and GPX in longitude/latitude from the system a layer holds (#2032 C1e part 2) #2510
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2089,14 +2089,16 @@ fn converted(ds: &Dataset, p: &Value) -> Result<(String, Vec<String>), String> { | |||||
| let name_field = | ||||||
| ps(p, "nameField").and_then(|n| ds.field_index(n)).or_else(|| ds.fields.iter().position(|f| f.name.eq_ignore_ascii_case("name"))); | ||||||
| let format = conversion_format(p)?; | ||||||
| // Every format here is longitude/latitude, whatever system the layer holds its coordinates | ||||||
| // in; the notes below read the layer itself, converting as they need. | ||||||
| let lonlat = ds.in_lonlat()?; | ||||||
| let text = match format { | ||||||
| "geojson" => rustgis_data::io::to_geojson_text(ds).map_err(|e| e.to_string())?, | ||||||
| "csv" => rustgis_data::io::to_csv(ds).map_err(|e| e.to_string())?, | ||||||
| "kml" => rustgis_data::interop::to_kml(ds, name_field).map_err(|e| e.to_string())?, | ||||||
| "gpx" => rustgis_data::interop::to_gpx(ds, name_field).map_err(|e| e.to_string())?, | ||||||
| _ => rustgis_data::interop::to_wkt_csv(ds).map_err(|e| e.to_string())?, | ||||||
| "geojson" => rustgis_data::io::to_geojson_text(&lonlat).map_err(|e| e.to_string())?, | ||||||
| "csv" => rustgis_data::io::to_csv(&lonlat).map_err(|e| e.to_string())?, | ||||||
| "kml" => rustgis_data::interop::to_kml(&lonlat, name_field).map_err(|e| e.to_string())?, | ||||||
| "gpx" => rustgis_data::interop::to_gpx(&lonlat, name_field).map_err(|e| e.to_string())?, | ||||||
| _ => rustgis_data::interop::to_wkt_csv(&lonlat).map_err(|e| e.to_string())?, | ||||||
| }; | ||||||
| // Every format here is longitude/latitude. | ||||||
| let target = ps(p, "path").unwrap_or(&ds.name); | ||||||
| let mut notes = rustgis_data::export_notes([(ds, ds.lonlat_extent())], target, rustgis_data::raster::Crs::LonLat); | ||||||
| notes.extend(rustgis_data::io::export_losses_notes(ds, format, name_field, target).map_err(|e| e.to_string())?); | ||||||
|
Contributor
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. Memory: the CSV branch converts the layer twice once a layer holds another system. Passing the already-converted copy here avoids the second copy. The losses notes only read coordinates in longitude/latitude, so the notes do not change.
Suggested change
Confidence: high on the code path, medium on how much this matters before a layer can hold another system. |
||||||
|
|
||||||
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.
Performance (latent):
Dataset::geometry_to_lonlatcallsself.coord_crs().to(LonLat)on every call. For a layer in another system, that builds aCrs::transformer()per feature.ogc_warp::transformercaches the same construction for this reason. The per-feature loops here (alsosharing.rsstyled_featuresand the Pythonlayer_geojsonselection branch) would pay that cost once per feature.Behaviour is unchanged today, since
coord_crs()is alwaysLonLatand the call returns early. Before a layer can hold another system, build theReprojectiononce per layer (Dataset::lonlat_conversion()is already public) and convert each row with it, or add a helper that does so. No change is needed in this PR if the follow-up is tracked for C2.Confidence: medium. The mechanism is clear from the code. The cost depends on how expensive
Crs::transformeris for the systems in use.