Skip to content

Commit abc984c

Browse files
committed
Implement ToSql for Geometry
1 parent 9056d3c commit abc984c

File tree

3 files changed

+377
-4
lines changed

3 files changed

+377
-4
lines changed

src/ewkb.rs

Lines changed: 320 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ macro_rules! geometry_container_write {
692692
$ewkbtype { geom: self, srid: self.srid, point_type: Self::PointType::point_type() }
693693
}
694694
}
695-
)
695+
);
696696
}
697697

698698

@@ -793,6 +793,30 @@ pub enum GeometryT<P: postgis::Point + EwkbRead> {
793793
GeometryCollection(GeometryCollectionT<P>)
794794
}
795795

796+
impl<'a, P> postgis::Geometry<'a> for GeometryT<P>
797+
where P: 'a + postgis::Point + EwkbRead
798+
{
799+
type Point = P;
800+
type LineString = LineStringT<P>;
801+
type Polygon = PolygonT<P>;
802+
type MultiPoint = MultiPointT<P>;
803+
type MultiLineString = MultiLineStringT<P>;
804+
type MultiPolygon = MultiPolygonT<P>;
805+
type GeometryCollection = GeometryCollectionT<P>;
806+
fn as_type(&'a self) -> postgis::GeometryType<'a, Self::Point, Self::LineString, Self::Polygon, Self::MultiPoint, Self::MultiLineString, Self::MultiPolygon, Self::GeometryCollection> {
807+
use ewkb::GeometryT as A;
808+
use types::GeometryType as B;
809+
match *self {
810+
A::Point(ref geom) => B::Point(geom),
811+
A::LineString(ref geom) => B::LineString(geom),
812+
A::Polygon(ref geom) => B::Polygon(geom),
813+
A::MultiPoint(ref geom) => B::MultiPoint(geom),
814+
A::MultiLineString(ref geom) => B::MultiLineString(geom),
815+
A::MultiPolygon(ref geom) => B::MultiPolygon(geom),
816+
A::GeometryCollection(ref geom) => B::GeometryCollection(geom),
817+
}
818+
}
819+
}
796820

797821
impl<P> EwkbRead for GeometryT<P>
798822
where P: postgis::Point + EwkbRead
@@ -827,6 +851,152 @@ impl<P> EwkbRead for GeometryT<P>
827851
}
828852
}
829853

854+
pub enum EwkbGeometry<'a, P, PI, MP, L, LI, ML, Y, YI, MY, G, GI, GC>
855+
where P: 'a + postgis::Point,
856+
PI: 'a + Iterator<Item=&'a P> + ExactSizeIterator<Item=&'a P>,
857+
MP: 'a + postgis::MultiPoint<'a, ItemType=P, Iter=PI>,
858+
L: 'a + postgis::LineString<'a, ItemType=P, Iter=PI>,
859+
LI: 'a + Iterator<Item=&'a L> + ExactSizeIterator<Item=&'a L>,
860+
ML: 'a + postgis::MultiLineString<'a, ItemType=L, Iter=LI>,
861+
Y: 'a + postgis::Polygon<'a, ItemType=L, Iter=LI>,
862+
YI: 'a + Iterator<Item=&'a Y> + ExactSizeIterator<Item=&'a Y>,
863+
MY: 'a + postgis::MultiPolygon<'a, ItemType=Y, Iter=YI>,
864+
G: 'a + postgis::Geometry<'a, Point=P, LineString=L, Polygon=Y, MultiPoint=MP, MultiLineString=ML, MultiPolygon=MY, GeometryCollection=GC>,
865+
GI: 'a + Iterator<Item=&'a G> + ExactSizeIterator<Item=&'a G>,
866+
GC: 'a + postgis::GeometryCollection<'a, ItemType=G, Iter=GI>
867+
{
868+
Point(EwkbPoint<'a>),
869+
LineString(EwkbLineString<'a, P, PI>),
870+
Polygon(EwkbPolygon<'a, P, PI, L, LI>),
871+
MultiPoint(EwkbMultiPoint<'a, P, PI>),
872+
MultiLineString(EwkbMultiLineString<'a, P, PI, L, LI>),
873+
MultiPolygon(EwkbMultiPolygon<'a, P, PI, L, LI, Y, YI>),
874+
GeometryCollection(EwkbGeometryCollection<'a, P, PI, MP, L, LI, ML, Y, YI, MY, G, GI, GC>),
875+
}
876+
877+
pub trait AsEwkbGeometry<'a> {
878+
type PointType: 'a + postgis::Point + EwkbRead;
879+
type PointIter: Iterator<Item=&'a Self::PointType>+ExactSizeIterator<Item=&'a Self::PointType>;
880+
type MultiPointType: 'a + postgis::MultiPoint<'a, ItemType=Self::PointType, Iter=Self::PointIter>;
881+
type LineType: 'a + postgis::LineString<'a, ItemType=Self::PointType, Iter=Self::PointIter>;
882+
type LineIter: Iterator<Item=&'a Self::LineType>+ExactSizeIterator<Item=&'a Self::LineType>;
883+
type MultiLineType: 'a + postgis::MultiLineString<'a, ItemType=Self::LineType, Iter=Self::LineIter>;
884+
type PolyType: 'a + postgis::Polygon<'a, ItemType=Self::LineType, Iter=Self::LineIter>;
885+
type PolyIter: Iterator<Item=&'a Self::PolyType>+ExactSizeIterator<Item=&'a Self::PolyType>;
886+
type MultiPolyType: 'a + postgis::MultiPolygon<'a, ItemType=Self::PolyType, Iter=Self::PolyIter>;
887+
type GeomType: 'a + postgis::Geometry<'a, Point=Self::PointType, LineString=Self::LineType, Polygon=Self::PolyType, MultiPoint=Self::MultiPointType, MultiLineString=Self::MultiLineType, MultiPolygon=Self::MultiPolyType, GeometryCollection=Self::GeomCollection>;
888+
type GeomIter: Iterator<Item=&'a Self::GeomType>+ExactSizeIterator<Item=&'a Self::GeomType>;
889+
type GeomCollection: 'a + postgis::GeometryCollection<'a, ItemType=Self::GeomType, Iter=Self::GeomIter>;
890+
fn as_ewkb(&'a self) -> EwkbGeometry<'a, Self::PointType, Self::PointIter, Self::MultiPointType, Self::LineType, Self::LineIter, Self::MultiLineType, Self::PolyType, Self::PolyIter, Self::MultiPolyType, Self::GeomType, Self::GeomIter, Self::GeomCollection>;
891+
}
892+
893+
impl<'a, P, PI, MP, L, LI, ML, Y, YI, MY, G, GI, GC> fmt::Debug for EwkbGeometry<'a, P, PI, MP, L, LI, ML, Y, YI, MY, G, GI, GC>
894+
where P: 'a + postgis::Point,
895+
PI: 'a + Iterator<Item=&'a P> + ExactSizeIterator<Item=&'a P>,
896+
MP: 'a + postgis::MultiPoint<'a, ItemType=P, Iter=PI>,
897+
L: 'a + postgis::LineString<'a, ItemType=P, Iter=PI>,
898+
LI: 'a + Iterator<Item=&'a L> + ExactSizeIterator<Item=&'a L>,
899+
ML: 'a + postgis::MultiLineString<'a, ItemType=L, Iter=LI>,
900+
Y: 'a + postgis::Polygon<'a, ItemType=L, Iter=LI>,
901+
YI: 'a + Iterator<Item=&'a Y> + ExactSizeIterator<Item=&'a Y>,
902+
MY: 'a + postgis::MultiPolygon<'a, ItemType=Y, Iter=YI>,
903+
G: 'a + postgis::Geometry<'a, Point=P, LineString=L, Polygon=Y, MultiPoint=MP, MultiLineString=ML, MultiPolygon=MY, GeometryCollection=GC>,
904+
GI: 'a + Iterator<Item=&'a G> + ExactSizeIterator<Item=&'a G>,
905+
GC: 'a + postgis::GeometryCollection<'a, ItemType=G, Iter=GI>
906+
{
907+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
908+
write!(f, stringify!(EwkbGeometry))?; //TODO
909+
Ok(())
910+
}
911+
}
912+
913+
impl<'a, P, PI, MP, L, LI, ML, Y, YI, MY, G, GI, GC> EwkbWrite for EwkbGeometry<'a, P, PI, MP, L, LI, ML, Y, YI, MY, G, GI, GC>
914+
where P: 'a + postgis::Point,
915+
PI: 'a + Iterator<Item=&'a P> + ExactSizeIterator<Item=&'a P>,
916+
MP: 'a + postgis::MultiPoint<'a, ItemType=P, Iter=PI>,
917+
L: 'a + postgis::LineString<'a, ItemType=P, Iter=PI>,
918+
LI: 'a + Iterator<Item=&'a L> + ExactSizeIterator<Item=&'a L>,
919+
ML: 'a + postgis::MultiLineString<'a, ItemType=L, Iter=LI>,
920+
Y: 'a + postgis::Polygon<'a, ItemType=L, Iter=LI>,
921+
YI: 'a + Iterator<Item=&'a Y> + ExactSizeIterator<Item=&'a Y>,
922+
MY: 'a + postgis::MultiPolygon<'a, ItemType=Y, Iter=YI>,
923+
G: 'a + postgis::Geometry<'a, Point=P, LineString=L, Polygon=Y, MultiPoint=MP, MultiLineString=ML, MultiPolygon=MY, GeometryCollection=GC>,
924+
GI: 'a + Iterator<Item=&'a G> + ExactSizeIterator<Item=&'a G>,
925+
GC: 'a + postgis::GeometryCollection<'a, ItemType=G, Iter=GI>
926+
{
927+
fn opt_srid(&self) -> Option<i32> {
928+
match *self {
929+
EwkbGeometry::Point(ref ewkb) => ewkb.opt_srid(),
930+
EwkbGeometry::LineString(ref ewkb) => ewkb.opt_srid(),
931+
EwkbGeometry::Polygon(ref ewkb) => ewkb.opt_srid(),
932+
EwkbGeometry::MultiPoint(ref ewkb) => ewkb.opt_srid(),
933+
EwkbGeometry::MultiLineString(ref ewkb) => ewkb.opt_srid(),
934+
EwkbGeometry::MultiPolygon(ref ewkb) => ewkb.opt_srid(),
935+
EwkbGeometry::GeometryCollection(ref ewkb) => ewkb.opt_srid(),
936+
}
937+
}
938+
939+
fn type_id(&self) -> u32 {
940+
match *self {
941+
EwkbGeometry::Point(ref ewkb) => ewkb.type_id(),
942+
EwkbGeometry::LineString(ref ewkb) => ewkb.type_id(),
943+
EwkbGeometry::Polygon(ref ewkb) => ewkb.type_id(),
944+
EwkbGeometry::MultiPoint(ref ewkb) => ewkb.type_id(),
945+
EwkbGeometry::MultiLineString(ref ewkb) => ewkb.type_id(),
946+
EwkbGeometry::MultiPolygon(ref ewkb) => ewkb.type_id(),
947+
EwkbGeometry::GeometryCollection(ref ewkb) => ewkb.type_id(),
948+
}
949+
}
950+
951+
fn write_ewkb_body<W: Write+?Sized>(&self, w: &mut W) -> Result<(), Error> {
952+
match *self {
953+
EwkbGeometry::Point(ref ewkb) => ewkb.write_ewkb_body(w),
954+
EwkbGeometry::LineString(ref ewkb) => ewkb.write_ewkb_body(w),
955+
EwkbGeometry::Polygon(ref ewkb) => ewkb.write_ewkb_body(w),
956+
EwkbGeometry::MultiPoint(ref ewkb) => ewkb.write_ewkb_body(w),
957+
EwkbGeometry::MultiLineString(ref ewkb) => ewkb.write_ewkb_body(w),
958+
EwkbGeometry::MultiPolygon(ref ewkb) => ewkb.write_ewkb_body(w),
959+
EwkbGeometry::GeometryCollection(ref ewkb) => ewkb.write_ewkb_body(w),
960+
}
961+
}
962+
}
963+
964+
// NOTE: Implement once for each point type to avoid trait lifetime constraints
965+
macro_rules! impl_as_ewkb_geometry {
966+
($ptype:ident) => (
967+
impl<'a> AsEwkbGeometry<'a> for GeometryT<$ptype> {
968+
type PointType = $ptype;
969+
type PointIter = Iter<'a, $ptype>;
970+
type MultiPointType = MultiPointT<$ptype>;
971+
type LineType = LineStringT<$ptype>;
972+
type LineIter = Iter<'a, Self::LineType>;
973+
type MultiLineType = MultiLineStringT<$ptype>;
974+
type PolyType = PolygonT<$ptype>;
975+
type PolyIter = Iter<'a, Self::PolyType>;
976+
type MultiPolyType = MultiPolygonT<$ptype>;
977+
type GeomType = GeometryT<$ptype>;
978+
type GeomIter = Iter<'a, Self::GeomType>;
979+
type GeomCollection = GeometryCollectionT<$ptype>;
980+
fn as_ewkb(&'a self) -> EwkbGeometry<'a, Self::PointType, Self::PointIter, Self::MultiPointType, Self::LineType, Self::LineIter, Self::MultiLineType, Self::PolyType, Self::PolyIter, Self::MultiPolyType, Self::GeomType, Self::GeomIter, Self::GeomCollection> {
981+
match *self {
982+
GeometryT::Point(ref geom) => EwkbGeometry::Point(geom.as_ewkb()),
983+
GeometryT::LineString(ref geom) => EwkbGeometry::LineString(geom.as_ewkb()),
984+
GeometryT::Polygon(ref geom) => EwkbGeometry::Polygon(geom.as_ewkb()),
985+
GeometryT::MultiPoint(ref geom) => EwkbGeometry::MultiPoint(geom.as_ewkb()),
986+
GeometryT::MultiLineString(ref geom) => EwkbGeometry::MultiLineString(geom.as_ewkb()),
987+
GeometryT::MultiPolygon(ref geom) => EwkbGeometry::MultiPolygon(geom.as_ewkb()),
988+
GeometryT::GeometryCollection(ref geom) => EwkbGeometry::GeometryCollection(geom.as_ewkb()),
989+
}
990+
}
991+
}
992+
)
993+
}
994+
995+
impl_as_ewkb_geometry!(Point);
996+
impl_as_ewkb_geometry!(PointZ);
997+
impl_as_ewkb_geometry!(PointM);
998+
impl_as_ewkb_geometry!(PointZM);
999+
8301000
/// OGC Geometry type
8311001
pub type Geometry = GeometryT<Point>;
8321002
/// OGC GeometryZ type
@@ -839,14 +1009,25 @@ pub type GeometryZM = GeometryT<PointZM>;
8391009

8401010
#[derive(Debug)]
8411011
pub struct GeometryCollectionT<P: postgis::Point + EwkbRead> {
842-
pub geometries: Vec<GeometryT<P>>
1012+
pub geometries: Vec<GeometryT<P>>,
1013+
pub srid: Option<i32>,
8431014
}
8441015

8451016
impl<P> GeometryCollectionT<P>
8461017
where P: postgis::Point + EwkbRead
8471018
{
8481019
pub fn new() -> GeometryCollectionT<P> {
849-
GeometryCollectionT { geometries: Vec::new() }
1020+
GeometryCollectionT { geometries: Vec::new(), srid: None }
1021+
}
1022+
}
1023+
1024+
impl<'a, P> postgis::GeometryCollection<'a> for GeometryCollectionT<P>
1025+
where P: 'a + postgis::Point + EwkbRead
1026+
{
1027+
type ItemType = GeometryT<P>;
1028+
type Iter = Iter<'a, Self::ItemType>;
1029+
fn geometries(&'a self) -> Self::Iter {
1030+
self.geometries.iter()
8501031
}
8511032
}
8521033

@@ -856,6 +1037,7 @@ impl<P> EwkbRead for GeometryCollectionT<P>
8561037
fn point_type() -> PointType {
8571038
P::point_type()
8581039
}
1040+
8591041
fn read_ewkb_body<R: Read>(raw: &mut R, is_be: bool, _srid: Option<i32>) -> Result<Self, Error> {
8601042
let mut ret = GeometryCollectionT::new();
8611043
let size = read_u32(raw, is_be)? as usize;
@@ -883,6 +1065,141 @@ impl<P> EwkbRead for GeometryCollectionT<P>
8831065
}
8841066
}
8851067

1068+
pub struct EwkbGeometryCollection<'a, P, PI, MP, L, LI, ML, Y, YI, MY, G, GI, GC>
1069+
where P: 'a + postgis::Point,
1070+
PI: 'a + Iterator<Item=&'a P> + ExactSizeIterator<Item=&'a P>,
1071+
MP: 'a + postgis::MultiPoint<'a, ItemType=P, Iter=PI>,
1072+
L: 'a + postgis::LineString<'a, ItemType=P, Iter=PI>,
1073+
LI: 'a + Iterator<Item=&'a L> + ExactSizeIterator<Item=&'a L>,
1074+
ML: 'a + postgis::MultiLineString<'a, ItemType=L, Iter=LI>,
1075+
Y: 'a + postgis::Polygon<'a, ItemType=L, Iter=LI>,
1076+
YI: 'a + Iterator<Item=&'a Y> + ExactSizeIterator<Item=&'a Y>,
1077+
MY: 'a + postgis::MultiPolygon<'a, ItemType=Y, Iter=YI>,
1078+
G: 'a + postgis::Geometry<'a, Point=P, LineString=L, Polygon=Y, MultiPoint=MP, MultiLineString=ML, MultiPolygon=MY, GeometryCollection=GC>,
1079+
GI: 'a + Iterator<Item=&'a G> + ExactSizeIterator<Item=&'a G>,
1080+
GC: 'a + postgis::GeometryCollection<'a, ItemType=G, Iter=GI>
1081+
{
1082+
pub geom: &'a postgis::GeometryCollection<'a, ItemType=G, Iter=GI>,
1083+
pub srid: Option<i32>,
1084+
pub point_type: PointType,
1085+
}
1086+
1087+
pub trait AsEwkbGeometryCollection<'a> {
1088+
type PointType: 'a + postgis::Point + EwkbRead;
1089+
type PointIter: Iterator<Item=&'a Self::PointType>+ExactSizeIterator<Item=&'a Self::PointType>;
1090+
type MultiPointType: 'a + postgis::MultiPoint<'a, ItemType=Self::PointType, Iter=Self::PointIter>;
1091+
type LineType: 'a + postgis::LineString<'a, ItemType=Self::PointType, Iter=Self::PointIter>;
1092+
type LineIter: Iterator<Item=&'a Self::LineType>+ExactSizeIterator<Item=&'a Self::LineType>;
1093+
type MultiLineType: 'a + postgis::MultiLineString<'a, ItemType=Self::LineType, Iter=Self::LineIter>;
1094+
type PolyType: 'a + postgis::Polygon<'a, ItemType=Self::LineType, Iter=Self::LineIter>;
1095+
type PolyIter: Iterator<Item=&'a Self::PolyType>+ExactSizeIterator<Item=&'a Self::PolyType>;
1096+
type MultiPolyType: 'a + postgis::MultiPolygon<'a, ItemType=Self::PolyType, Iter=Self::PolyIter>;
1097+
type GeomType: 'a + postgis::Geometry<'a, Point=Self::PointType, LineString=Self::LineType, Polygon=Self::PolyType, MultiPoint=Self::MultiPointType, MultiLineString=Self::MultiLineType, MultiPolygon=Self::MultiPolyType, GeometryCollection=Self::GeomCollection>;
1098+
type GeomIter: Iterator<Item=&'a Self::GeomType>+ExactSizeIterator<Item=&'a Self::GeomType>;
1099+
type GeomCollection: 'a + postgis::GeometryCollection<'a, ItemType=Self::GeomType, Iter=Self::GeomIter>;
1100+
fn as_ewkb(&'a self) -> EwkbGeometryCollection<'a, Self::PointType, Self::PointIter, Self::MultiPointType, Self::LineType, Self::LineIter, Self::MultiLineType, Self::PolyType, Self::PolyIter, Self::MultiPolyType, Self::GeomType, Self::GeomIter, Self::GeomCollection>;
1101+
}
1102+
1103+
impl<'a, P, PI, MP, L, LI, ML, Y, YI, MY, G, GI, GC> fmt::Debug for EwkbGeometryCollection<'a, P, PI, MP, L, LI, ML, Y, YI, MY, G, GI, GC>
1104+
where P: 'a + postgis::Point,
1105+
PI: 'a + Iterator<Item=&'a P> + ExactSizeIterator<Item=&'a P>,
1106+
MP: 'a + postgis::MultiPoint<'a, ItemType=P, Iter=PI>,
1107+
L: 'a + postgis::LineString<'a, ItemType=P, Iter=PI>,
1108+
LI: 'a + Iterator<Item=&'a L> + ExactSizeIterator<Item=&'a L>,
1109+
ML: 'a + postgis::MultiLineString<'a, ItemType=L, Iter=LI>,
1110+
Y: 'a + postgis::Polygon<'a, ItemType=L, Iter=LI>,
1111+
YI: 'a + Iterator<Item=&'a Y> + ExactSizeIterator<Item=&'a Y>,
1112+
MY: 'a + postgis::MultiPolygon<'a, ItemType=Y, Iter=YI>,
1113+
G: 'a + postgis::Geometry<'a, Point=P, LineString=L, Polygon=Y, MultiPoint=MP, MultiLineString=ML, MultiPolygon=MY, GeometryCollection=GC>,
1114+
GI: 'a + Iterator<Item=&'a G> + ExactSizeIterator<Item=&'a G>,
1115+
GC: 'a + postgis::GeometryCollection<'a, ItemType=G, Iter=GI>
1116+
{
1117+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1118+
write!(f, stringify!(EwkbGeometryCollection))?; //TODO
1119+
Ok(())
1120+
}
1121+
}
1122+
1123+
impl<'a, P, PI, MP, L, LI, ML, Y, YI, MY, G, GI, GC> EwkbWrite for EwkbGeometryCollection<'a, P, PI, MP, L, LI, ML, Y, YI, MY, G, GI, GC>
1124+
where P: 'a + postgis::Point,
1125+
PI: 'a + Iterator<Item=&'a P> + ExactSizeIterator<Item=&'a P>,
1126+
MP: 'a + postgis::MultiPoint<'a, ItemType=P, Iter=PI>,
1127+
L: 'a + postgis::LineString<'a, ItemType=P, Iter=PI>,
1128+
LI: 'a + Iterator<Item=&'a L> + ExactSizeIterator<Item=&'a L>,
1129+
ML: 'a + postgis::MultiLineString<'a, ItemType=L, Iter=LI>,
1130+
Y: 'a + postgis::Polygon<'a, ItemType=L, Iter=LI>,
1131+
YI: 'a + Iterator<Item=&'a Y> + ExactSizeIterator<Item=&'a Y>,
1132+
MY: 'a + postgis::MultiPolygon<'a, ItemType=Y, Iter=YI>,
1133+
G: 'a + postgis::Geometry<'a, Point=P, LineString=L, Polygon=Y, MultiPoint=MP, MultiLineString=ML, MultiPolygon=MY, GeometryCollection=GC>,
1134+
GI: 'a + Iterator<Item=&'a G> + ExactSizeIterator<Item=&'a G>,
1135+
GC: 'a + postgis::GeometryCollection<'a, ItemType=G, Iter=GI>
1136+
{
1137+
fn opt_srid(&self) -> Option<i32> {
1138+
self.srid
1139+
}
1140+
1141+
fn type_id(&self) -> u32 {
1142+
0x07 | Self::wkb_type_id(&self.point_type, self.srid)
1143+
}
1144+
1145+
fn write_ewkb_body<W: Write+?Sized>(&self, w: &mut W) -> Result<(), Error> {
1146+
w.write_u32::<LittleEndian>(self.geom.geometries().len() as u32)?;
1147+
for geom in self.geom.geometries() {
1148+
match geom.as_type() {
1149+
postgis::GeometryType::Point(geom) => {
1150+
let wkb = EwkbPoint { geom: geom, srid: None, point_type: self.point_type.clone() };
1151+
wkb.write_ewkb_body(w)?;
1152+
},
1153+
postgis::GeometryType::LineString(geom) => {
1154+
let wkb = EwkbLineString { geom: geom, srid: None, point_type: self.point_type.clone() };
1155+
wkb.write_ewkb_body(w)?;
1156+
},
1157+
postgis::GeometryType::Polygon(geom) => {
1158+
let wkb = EwkbPolygon { geom: geom, srid: None, point_type: self.point_type.clone() };
1159+
wkb.write_ewkb_body(w)?;
1160+
},
1161+
postgis::GeometryType::MultiPoint(geom) => {
1162+
let wkb = EwkbMultiPoint { geom: geom, srid: None, point_type: self.point_type.clone() };
1163+
wkb.write_ewkb(w)?;
1164+
},
1165+
postgis::GeometryType::MultiLineString(geom) => {
1166+
let wkb = EwkbMultiLineString { geom: geom, srid: None, point_type: self.point_type.clone() };
1167+
wkb.write_ewkb(w)?;
1168+
},
1169+
postgis::GeometryType::MultiPolygon(geom) => {
1170+
let wkb = EwkbMultiPolygon { geom: geom, srid: None, point_type: self.point_type.clone() };
1171+
wkb.write_ewkb(w)?;
1172+
},
1173+
postgis::GeometryType::GeometryCollection(geom) => {
1174+
let wkb = EwkbGeometryCollection { geom: geom, srid: None, point_type: self.point_type.clone() };
1175+
wkb.write_ewkb_body(w)?;
1176+
},
1177+
}
1178+
}
1179+
Ok(())
1180+
}
1181+
}
1182+
1183+
impl<'a, P> AsEwkbGeometryCollection<'a> for GeometryCollectionT<P>
1184+
where P: 'a + postgis::Point + EwkbRead
1185+
{
1186+
type PointType = P;
1187+
type PointIter = Iter<'a, P>;
1188+
type MultiPointType = MultiPointT<P>;
1189+
type LineType = LineStringT<P>;
1190+
type LineIter = Iter<'a, Self::LineType>;
1191+
type MultiLineType = MultiLineStringT<P>;
1192+
type PolyType = PolygonT<P>;
1193+
type PolyIter = Iter<'a, Self::PolyType>;
1194+
type MultiPolyType = MultiPolygonT<P>;
1195+
type GeomType = GeometryT<P>;
1196+
type GeomIter = Iter<'a, Self::GeomType>;
1197+
type GeomCollection = GeometryCollectionT<P>;
1198+
fn as_ewkb(&'a self) -> EwkbGeometryCollection<'a, Self::PointType, Self::PointIter, Self::MultiPointType, Self::LineType, Self::LineIter, Self::MultiLineType, Self::PolyType, Self::PolyIter, Self::MultiPolyType, Self::GeomType, Self::GeomIter, Self::GeomCollection> {
1199+
EwkbGeometryCollection { geom: self, srid: self.srid, point_type: P::point_type() }
1200+
}
1201+
}
1202+
8861203
/// OGC GeometryCollection type
8871204
pub type GeometryCollection = GeometryCollectionT<Point>;
8881205
/// OGC GeometryCollectionZ type

0 commit comments

Comments
 (0)