Skip to content

Commit 6228d9f

Browse files
author
wonder
committed
Fixed #709. The crash happened with shapefiles containing 2.5D geometries.
Now these files can be importent, but Z coordinates are ignored. git-svn-id: http://svn.osgeo.org/qgis/trunk@7126 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4aaabbe commit 6228d9f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/plugins/spit/qgsshapefile.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,25 @@ bool QgsShapeFile::scanGeometries()
123123

124124
}
125125
}
126+
127+
// a hack to support 2.5D geometries (their wkb is equivalent to 2D variants
128+
// except that the highest bit is set also). For now we will ignore 3rd coordinate.
129+
hasMoreDimensions = false;
130+
if (currentType & 0x80000000)
131+
{
132+
QgsDebugMsg("Got a shapefile with 2.5D geometry.");
133+
currentType &= ~0x80000000;
134+
hasMoreDimensions = true;
135+
}
136+
126137
ogrLayer->ResetReading();
127138
geom_type = geometries[currentType];
128139
if(multi && (geom_type.find("MULTI") == -1))
129140
{
130141
geom_type = "MULTI" + geom_type;
131142
}
132143
delete sg;
144+
133145
// std::cerr << "Geometry type is " << currentType << " (" << geometries[currentType] << ")" << std::endl;
134146
return multi;
135147
}
@@ -363,6 +375,10 @@ bool QgsShapeFile::insertLayer(QString dbname, QString schema, QString geom_col,
363375

364376
int num = geom->WkbSize();
365377
char * geo_temp = new char[num*3];
378+
// 'GeometryFromText' supports only 2D coordinates
379+
// TODO for proper 2.5D support we would need to use 'GeomFromEWKT'
380+
if (hasMoreDimensions)
381+
geom->setCoordinateDimension(2);
366382
geom->exportToWkt(&geo_temp);
367383
QString geometry(geo_temp);
368384

src/plugins/spit/qgsshapefile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class QgsShapeFile : public QObject
6868
bool valid;
6969
//! Flag to indicate the file contains multiple geometry types
7070
bool isMulti;
71+
bool hasMoreDimensions;
7172
int features;
7273
QString filename;
7374
QString geom_type;

0 commit comments

Comments
 (0)