-
Notifications
You must be signed in to change notification settings - Fork 15
German postcodes via geo search #110
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
Draft
skurfuerst
wants to merge
13
commits into
osm-without-borders:master
Choose a base branch
from
skurfuerst:german-postcodes-via-geo-search
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8081518
WIP - initially working
skurfuerst 34c11c4
FEATURE: more fine grained intersection matching
skurfuerst 2f7c673
FEATURE: intersection matching with % inclusion
skurfuerst 59d6358
TASK: code cleanups
skurfuerst d2e6baa
TASK: move Postcode model around
skurfuerst 26a360a
BUGFIX: fix compiler warnings
skurfuerst 0c73aab
BUGFIX: do not read OSM file twice for getting postcodes
skurfuerst 0e16fb1
TASK: use rayon for reading postcodes
skurfuerst 20edf9e
TASK: restructure and parallelize postcode assignment
skurfuerst 9e5af94
run cargo fmt
skurfuerst b9a4b4c
fix clippy issues
skurfuerst 75521ed
TASK: minor refactorings for code clarity
skurfuerst 5cfc987
FEATURE: Sort Zip Codes
skurfuerst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| use crate::mutable_slice::MutableSlice; | ||
| use geo_types::{Coordinate, Geometry, MultiPolygon, Point, Rect, Polygon}; | ||
| use log::warn; | ||
| use osmpbfreader::objects::Tags; | ||
| use serde::Serialize; | ||
| use serde_derive::*; | ||
| use std::collections::BTreeMap; | ||
| use std::fmt; | ||
|
|
||
| pub type Coord = Point<f64>; | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct Postcode { | ||
| pub osm_id: String, | ||
| pub zipcode: String, | ||
| pub boundary: geo_types::MultiPolygon<f64>, | ||
| pub area: f64 | ||
| } | ||
|
|
||
| impl Postcode { | ||
| pub fn get_boundary(&self) -> &geo_types::MultiPolygon<f64> { | ||
| return &self.boundary | ||
| } | ||
|
|
||
| pub fn unsigned_area(&self) -> f64 { | ||
| return self.area; | ||
| } | ||
| } | ||
|
|
||
| impl Default for Postcode { | ||
| fn default() -> Self { | ||
| Postcode { | ||
| osm_id: "".into(), | ||
| boundary: MultiPolygon(vec![]), | ||
| zipcode: "".into(), | ||
| area: 0.0 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Postcode {} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // extends Zones to add some capabilities | ||
| // The Zone's capabilities have been split in order to hide some functions specific to cosmogony | ||
| // and that we do not want to expose in the model | ||
|
|
||
| use cosmogony::{mutable_slice::MutableSlice, Coord, Zone, ZoneIndex, ZoneType, Postcode}; | ||
| use osm_boundaries_utils::build_boundary; | ||
| use osmpbfreader::objects::{OsmId, OsmObj, Relation}; | ||
| use std::collections::{BTreeMap, BTreeSet}; | ||
| use std::convert::TryInto; | ||
| use rstar::{RTreeObject, AABB}; | ||
| use geo::{Point, Rect}; | ||
| use geo::algorithm::area::Area; | ||
|
|
||
|
|
||
| #[derive(Debug)] | ||
| pub struct PostcodeBbox { | ||
| postcode: Postcode, | ||
| bbox: AABB<Point<f64>>, | ||
| } | ||
|
|
||
| impl PostcodeBbox { | ||
| pub fn new(postcode: Postcode, bbox: &Rect<f64>) -> Self { | ||
| PostcodeBbox { | ||
| postcode, | ||
| bbox: envelope(&bbox), | ||
| } | ||
| } | ||
|
|
||
| pub fn get_postcode(&self) -> &Postcode { | ||
| return &self.postcode; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| impl RTreeObject for PostcodeBbox { | ||
| type Envelope = AABB<Point<f64>>; | ||
| fn envelope(&self) -> Self::Envelope { | ||
| self.bbox | ||
| } | ||
| } | ||
|
|
||
|
|
||
| fn envelope(bbox: &Rect<f64>) -> AABB<Point<f64>> { | ||
| AABB::from_corners(bbox.min().into(), bbox.max().into()) | ||
| } | ||
|
|
||
| pub trait PostcodeExt { | ||
| /// create a zone from an osm relation and a geometry | ||
| fn from_osm_relation( | ||
| relation: &Relation, | ||
| objects: &BTreeMap<OsmId, OsmObj>, | ||
| ) -> Option<Postcode>; | ||
| } | ||
|
|
||
| impl PostcodeExt for Postcode { | ||
|
|
||
| fn from_osm_relation( | ||
| relation: &Relation, | ||
| objects: &BTreeMap<OsmId, OsmObj>, | ||
| ) -> Option<Self> { | ||
| // Skip postcode withjout postcode | ||
| let zipcode = match relation.tags.get("postal_code") { | ||
| Some(val) => val, | ||
| None => { | ||
| debug!( | ||
| "relation/{}: postcode region without name, skipped", | ||
| relation.id.0 | ||
| ); | ||
| "" | ||
| } | ||
| }; | ||
|
|
||
| let osm_id = format!("relation:{}", relation.id.0.to_string()); | ||
|
|
||
| let boundary = build_boundary(relation, objects); | ||
|
|
||
| boundary.map(|boundary| { | ||
| let area = boundary.unsigned_area(); | ||
| Postcode { | ||
| osm_id, | ||
| zipcode: zipcode.to_string(), | ||
| boundary, | ||
| area | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.