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

FileGDB/OpenFileGDB: be robust when winding order of outer ring is incorrect (fixes #1369) #1373

Merged
merged 1 commit into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
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
Binary file added autotest/ogr/data/weird_winding_order_fgdb.zip
Binary file not shown.
41 changes: 40 additions & 1 deletion autotest/ogr/ogr_fgdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2100,6 +2100,9 @@ def test_ogr_fgdb_23():

def test_ogr_fgdb_24():

if ogrtest.fgdb_drv is None:
pytest.skip()

ds = ogr.Open('data/filegdb_polygonzm_m_not_closing_with_curves.gdb')
lyr = ds.GetLayer(0)
ds_ref = ogr.Open('data/filegdb_polygonzm_m_not_closing_with_curves.gdb.csv')
Expand Down Expand Up @@ -2127,6 +2130,9 @@ def test_ogr_fgdb_24():

def test_ogr_fgdb_25():

if ogrtest.fgdb_drv is None:
pytest.skip()

ds = ogr.Open('data/curves.gdb')
sql_lyr = ds.ExecuteSQL('SELECT OBJECTID FROM polygon WHERE OBJECTID = 2')
assert sql_lyr is not None
Expand All @@ -2145,7 +2151,36 @@ def test_ogr_fgdb_25():
f.DumpReadable()
pytest.fail()



###############################################################################
# Test bugfix for https://github.com/OSGeo/gdal/issues/1369
# where a polygon with inner rings has its exterior ring with wrong orientation

def test_ogr_fgdb_weird_winding_order():

if ogrtest.fgdb_drv is None:
pytest.skip()

if not ogr_fgdb_is_sdk_1_4_or_later():
pytest.skip('SDK 1.4 required')

if not ogrtest.have_geos():
pytest.skip()

try:
shutil.rmtree('tmp/roads_clip Drawing.gdb')
except OSError:
pass
gdaltest.unzip('tmp', 'data/weird_winding_order_fgdb.zip')

ds = ogr.Open('tmp/roads_clip Drawing.gdb')
lyr = ds.GetLayer(0)
f = lyr.GetNextFeature()
g = f.GetGeometryRef()
assert g.GetGeometryCount() == 1
assert g.GetGeometryRef(0).GetGeometryCount() == 17


###############################################################################
# Cleanup

Expand All @@ -2171,6 +2206,10 @@ def test_ogr_fgdb_cleanup():
shutil.rmtree('tmp/test3005.gdb')
except OSError:
pass
try:
shutil.rmtree('tmp/roads_clip Drawing.gdb')
except OSError:
pass

if ogrtest.openfilegdb_drv is not None:
ogrtest.fgdb_drv.Deregister()
Expand Down
18 changes: 17 additions & 1 deletion autotest/ogr/ogr_openfilegdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,23 @@ def test_ogr_openfilegdb_21():
f.DumpReadable()
pytest.fail()


###############################################################################
# Test bugfix for https://github.com/OSGeo/gdal/issues/1369
# where a polygon with inner rings has its exterior ring with wrong orientation

def test_ogr_openfilegdb_weird_winding_order():

if not ogrtest.have_geos():
pytest.skip()

ds = ogr.Open('/vsizip/data/weird_winding_order_fgdb.zip/roads_clip Drawing.gdb')
lyr = ds.GetLayer(0)
f = lyr.GetNextFeature()
g = f.GetGeometryRef()
assert g.GetGeometryCount() == 1
assert g.GetGeometryRef(0).GetGeometryCount() == 17


###############################################################################
# Cleanup

Expand Down
6 changes: 5 additions & 1 deletion gdal/ogr/ogrpgeogeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2882,8 +2882,12 @@ OGRErr OGRCreateFromShapeBin( GByte *pabyShape,
if( tabPolygons != nullptr )
{
int isValidGeometry = FALSE;
// The outer ring is supposed to be clockwise oriented
// If it is not, then use the default/slow method.
const char* papszOptions[] =
{ "METHOD=ONLY_CCW", nullptr };
{ !(tabPolygons[0]->getExteriorRing()->isClockwise()) ?
"METHOD=DEFAULT" : "METHOD=ONLY_CCW",
nullptr };
poOGR = OGRGeometryFactory::organizePolygons(
reinterpret_cast<OGRGeometry **>(tabPolygons),
nParts,
Expand Down
3 changes: 1 addition & 2 deletions gdal/ogr/ogrsf_frmts/openfilegdb/filegdbtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3104,9 +3104,8 @@ OGRGeometry* FileGDBOGRGeometryConverterImpl::GetAsGeometry(const OGRField* psFi
}
delete[] papoRings;
papoRings = nullptr;
const char* papszOptions[] = { "METHOD=ONLY_CCW", nullptr };
poRet = OGRGeometryFactory::organizePolygons(
(OGRGeometry**) papoPolygons, nParts, nullptr, papszOptions );
(OGRGeometry**) papoPolygons, nParts, nullptr, nullptr );
delete[] papoPolygons;
}
#ifdef ASSUME_INNER_RINGS_IMMEDIATELY_AFTER_OUTER_RING
Expand Down