Skip to content
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

Forward srid to children of multitype container items #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/ewkb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,9 @@ macro_rules! impl_read_for_geometry_container_type {
let mut $itemname: Vec<$itemtype<P>> = vec![];
let size = read_u32(raw, is_be)? as usize;
for _ in 0..size {
$itemname.push($itemtype::read_ewkb(raw)?);
let _byte_order = raw.read_i8()?;
let type_id = read_u32(raw, is_be)?;
$itemname.push($itemtype::read_ewkb_body(raw, is_be, type_id, srid)?);
}
Ok($geotype::<P> {
$itemname: $itemname,
Expand Down Expand Up @@ -1883,3 +1885,21 @@ fn test_iterators() {
let line = self::LineStringT::<Point> {srid: Some(4326), points: vec![p(10.0, -20.0), p(0., -0.5)]};
assert_eq!(line.points().last(), Some(&Point { x: 0., y: -0.5, srid: None }));
}

#[test]
#[cfg_attr(rustfmt, rustfmt_skip)]
fn test_srid_on_multipolygons() {
let p = |x, y| Point { x: x, y: y, srid: Some(4326) };
// SELECT 'SRID=4326;MULTIPOLYGON (((0 0, 2 0, 2 2, 0 2, 0 0)), ((10 10, -2 10, -2 -2, 10 -2, 10 10)))'::geometry
let line = LineStringT::<Point> {srid: Some(4326), points: vec![p(0., 0.), p(2., 0.), p(2., 2.), p(0., 2.), p(0., 0.)]};
let poly1 = PolygonT::<Point> {srid: Some(4326), rings: vec![line]};
let line = LineStringT::<Point> {srid: Some(4326), points: vec![p(10., 10.), p(-2., 10.), p(-2., -2.), p(10., -2.), p(10., 10.)]};
let poly2 = PolygonT::<Point> {srid: Some(4326), rings: vec![line]};
let multipoly = MultiPolygonT::<Point> {srid: Some(4326), polygons: vec![poly1, poly2]};
let hex = multipoly.as_ewkb().to_hex_ewkb();
let ewkb = hex_to_vec(&hex);
let geom = MultiPolygon::read_ewkb(&mut ewkb.as_slice()).unwrap();

assert_eq!(geom.srid, Some(4326));
assert_eq!(geom.polygons[0].srid, Some(4326));
}