Skip to content

Commit

Permalink
Merge pull request OSGeo#1898 from bjornharrtell/more-dims
Browse files Browse the repository at this point in the history
FlatGeobuf: Fix Z/M handling
  • Loading branch information
rouault authored Oct 1, 2019
2 parents a3ccd33 + ddef1de commit 7b25270
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
21 changes: 14 additions & 7 deletions autotest/ogr/ogr_flatgeobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ def wktRoundtrip(expected):
lyr.CreateFeature(f)
ds = None

fgb_ds = ogr.Open('/vsimem/test.fgb')
fgb_lyr = fgb_ds.GetLayer(0)
f = fgb_lyr.GetNextFeature()
ds = ogr.Open('/vsimem/test.fgb')
lyr = ds.GetLayer(0)
f = lyr.GetNextFeature()
g = f.GetGeometryRef()
actual = g.ExportToWkt()
fgb_ds = None
actual = g.ExportToIsoWkt()
ds = None

ogr.GetDriverByName('FlatGeobuf').DeleteDataSource('/vsimem/test.fgb')
assert not gdal.VSIStatL('/vsimem/test.fgb')
Expand All @@ -235,7 +235,7 @@ def test_ogr_flatgeobuf_3():
wktRoundtrip('POINT (1.12345678901234 1.4321)') # max precision 15 decimals
#wktRoundtrip('POINT (1.123456789012341 1.4321)') # 16 decimals, will not pass
wktRoundtrip('POINT (1.2 -2.1)')
wktRoundtrip('MULTIPOINT (10 40,40 30,20 20,30 10)')
wktRoundtrip('MULTIPOINT ((10 40),(40 30),(20 20),(30 10))')
wktRoundtrip('LINESTRING (1.2 -2.1,2.4 -4.8)')
wktRoundtrip('MULTILINESTRING ((10 10,20 20,10 40),(40 40,30 30,40 20,30 10),(50 50,60 60,50 90))')
wktRoundtrip('MULTILINESTRING ((1.2 -2.1,2.4 -4.8))')
Expand All @@ -246,7 +246,14 @@ def test_ogr_flatgeobuf_3():
wktRoundtrip('MULTIPOLYGON (((30 20,45 40,10 40,30 20)))')
wktRoundtrip('MULTIPOLYGON (((35 10,45 45,15 40,10 20,35 10),(20 30,35 35,30 20,20 30)))')

#wktRoundtrip('POINT ZM (1 2 3 4)')
wktRoundtrip('POINT Z (1 2 3)')
wktRoundtrip('POINT ZM (1 2 3 4)')
wktRoundtrip('LINESTRING Z (1 2 3,2 3 4)')
wktRoundtrip('LINESTRING ZM (1 2 3 4,2 3 4 5)')
wktRoundtrip('POLYGON Z ((30 10 1,40 40 2,20 40 3,10 20 4,30 10 5))')
wktRoundtrip('POLYGON ZM ((30 10 1 5,40 40 2 4,20 40 3 3,10 20 4 2,30 10 5 1))')
wktRoundtrip('MULTIPOLYGON Z (((35 10 1,45 45 2,15 40 3,10 20 4,35 10 5),(20 30 1,35 35 2,30 20 3,20 30 4)))')
wktRoundtrip('MULTIPOLYGON ZM (((35 10 1 5,45 45 2 4,15 40 3 3,10 20 4 2,35 10 1 1),(20 30 4 1,35 35 3 2,30 20 2 3,20 30 1 4)))')

# Run test_ogrsf
def test_ogr_flatgeobuf_8():
Expand Down
27 changes: 16 additions & 11 deletions gdal/ogr/ogrsf_frmts/flatgeobuf/ogrflatgeobuflayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,22 @@ bool OGRFlatGeobufLayer::translateOGRwkbGeometryType()

OGRwkbGeometryType OGRFlatGeobufLayer::getOGRwkbGeometryType()
{
OGRwkbGeometryType ogrType = OGRwkbGeometryType::wkbUnknown;
switch (m_geometryType) {
case GeometryType::Point: return OGRwkbGeometryType::wkbPoint;
case GeometryType::MultiPoint: return OGRwkbGeometryType::wkbMultiPoint;
case GeometryType::LineString: return OGRwkbGeometryType::wkbLineString;
case GeometryType::MultiLineString: return OGRwkbGeometryType::wkbMultiLineString;
case GeometryType::Polygon: return OGRwkbGeometryType::wkbPolygon;
case GeometryType::MultiPolygon: return OGRwkbGeometryType::wkbMultiPolygon;
case GeometryType::Point: ogrType = OGRwkbGeometryType::wkbPoint; break;
case GeometryType::MultiPoint: ogrType = OGRwkbGeometryType::wkbMultiPoint; break;
case GeometryType::LineString: ogrType = OGRwkbGeometryType::wkbLineString; break;
case GeometryType::MultiLineString: ogrType = OGRwkbGeometryType::wkbMultiLineString; break;
case GeometryType::Polygon: ogrType = OGRwkbGeometryType::wkbPolygon; break;
case GeometryType::MultiPolygon: ogrType = OGRwkbGeometryType::wkbMultiPolygon; break;
default:
CPLError(CE_Failure, CPLE_NotSupported, "toOGRwkbGeometryType: Unknown FlatGeobuf::GeometryType %d", (int) m_geometryType);
}
return OGRwkbGeometryType::wkbUnknown;
if (m_hasZ)
ogrType = wkbSetZ(ogrType);
if (m_hasM)
ogrType = wkbSetM(ogrType);
return ogrType;
}

ColumnType OGRFlatGeobufLayer::toColumnType(OGRFieldType type, OGRFieldSubType /* subType */)
Expand Down Expand Up @@ -749,9 +754,9 @@ void OGRFlatGeobufLayer::readSimpleCurve(const Feature *feature, uint32_t len, u
auto aZ = feature->z()->data();
if (m_hasM) {
auto aM = feature->m()->data();
sc->setPoints(len, (OGRRawPoint *) xy + offset, aZ, aM);
sc->setPoints(len, (OGRRawPoint *) xy + offset, aZ + offset, aM + offset);
} else {
sc->setPoints(len, (OGRRawPoint *) xy + offset, aZ);
sc->setPoints(len, (OGRRawPoint *) xy + offset, aZ + offset);
}
} else {
sc->setPoints(len, (OGRRawPoint *) xy + offset);
Expand All @@ -763,7 +768,7 @@ OGRPolygon *OGRFlatGeobufLayer::readPolygon(const Feature *feature, uint32_t len
auto ends = feature->ends();
auto p = new OGRPolygon();
if (ends == nullptr || ends->size() < 2) {
p->addRingDirectly(readLinearRing(feature, len >> 1));
p->addRingDirectly(readLinearRing(feature, len / 2));
} else {
for (uint32_t i = 0; i < ends->size(); i++) {
auto e = ends->Get(i);
Expand Down Expand Up @@ -814,7 +819,7 @@ OGRGeometry *OGRFlatGeobufLayer::readGeometry(const Feature *feature)
case GeometryType::MultiPoint:
return readMultiPoint(feature, xySize);
case GeometryType::LineString:
return readLineString(feature, xySize >> 1);
return readLineString(feature, xySize / 2);
case GeometryType::MultiLineString:
return readMultiLineString(feature);
case GeometryType::Polygon:
Expand Down

0 comments on commit 7b25270

Please sign in to comment.