Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow displaying layers with 2.5D geometries.
For now, Z value is ignored.
This addresses ticket #308.


git-svn-id: http://svn.osgeo.org/qgis/trunk@5879 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Sep 27, 2006
1 parent 10f9dbc commit a1f3742
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 19 deletions.
8 changes: 7 additions & 1 deletion src/core/qgis.h
Expand Up @@ -59,7 +59,13 @@ class QGis
WKBMultiPoint,
WKBMultiLineString,
WKBMultiPolygon,
WKBUnknown
WKBUnknown,
WKBPoint25D = 0x80000001,
WKBLineString25D,
WKBPolygon25D,
WKBMultiPoint25D,
WKBMultiLineString25D,
WKBMultiPolygon25D
};
enum VectorType
{
Expand Down
51 changes: 42 additions & 9 deletions src/gui/qgsvectorlayer.cpp
Expand Up @@ -423,6 +423,7 @@ QgsRect QgsVectorLayer::inverseProjectRect(const QgsRect& r) const
}

unsigned char* QgsVectorLayer::drawLineString(unsigned char* feature,
bool hasZValue,
QPainter* p,
QgsMapToPixel* mtp,
bool projectionsEnabledFlag,
Expand All @@ -443,6 +444,9 @@ unsigned char* QgsVectorLayer::drawLineString(unsigned char* feature,
ptr += sizeof(double);
y[i] = *((double *) ptr);
ptr += sizeof(double);

if (hasZValue) // ignore Z value
ptr += sizeof(double);
}

// Transform the points into map coordinates (and reproject if
Expand Down Expand Up @@ -519,6 +523,7 @@ unsigned char* QgsVectorLayer::drawLineString(unsigned char* feature,
}

unsigned char* QgsVectorLayer::drawPolygon(unsigned char* feature,
bool hasZValue,
QPainter* p,
QgsMapToPixel* mtp,
bool projectionsEnabledFlag,
Expand Down Expand Up @@ -568,6 +573,10 @@ std::cerr << "Points for ring " << idx << " ("
ptr += sizeof(double);
ring->second[jdx] = *((double *) ptr);
ptr += sizeof(double);

if (hasZValue)
ptr += sizeof(double);

/*
#ifdef QGISDEBUG
std::cerr << jdx << ": "
Expand Down Expand Up @@ -1303,16 +1312,27 @@ QGis::VectorType QgsVectorLayer::vectorType() const
switch (type)
{
case QGis::WKBPoint:
case QGis::WKBPoint25D:
return QGis::Point;

case QGis::WKBLineString:
case QGis::WKBLineString25D:
return QGis::Line;

case QGis::WKBPolygon:
case QGis::WKBPolygon25D:
return QGis::Polygon;

case QGis::WKBMultiPoint:
case QGis::WKBMultiPoint25D:
return QGis::Point;

case QGis::WKBMultiLineString:
case QGis::WKBMultiLineString25D:
return QGis::Line;

case QGis::WKBMultiPolygon:
case QGis::WKBMultiPolygon25D:
return QGis::Polygon;
}
#ifdef QGISDEBUG
Expand Down Expand Up @@ -3326,7 +3346,8 @@ void QgsVectorLayer::drawFeature(QPainter* p,

switch (wkbType)
{
case WKBPoint:
case QGis::WKBPoint:
case QGis::WKBPoint25D:
{
double x = *((double *) (feature + 5));
double y = *((double *) (feature + 5 + sizeof(double)));
Expand All @@ -3346,7 +3367,8 @@ void QgsVectorLayer::drawFeature(QPainter* p,

break;
}
case WKBMultiPoint:
case QGis::WKBMultiPoint:
case QGis::WKBMultiPoint25D:
{
unsigned char *ptr = feature + 5;
unsigned int nPoints = *((int*)ptr);
Expand All @@ -3362,6 +3384,9 @@ void QgsVectorLayer::drawFeature(QPainter* p,
ptr += sizeof(double);
double y = *((double *) ptr);
ptr += sizeof(double);

if (wkbType == QGis::WKBMultiPoint25D) // ignore Z value
ptr += sizeof(double);

#ifdef QGISDEBUG
std::cout <<"...WKBMultiPoint (" << x << ", " << y << ")" <<std::endl;
Expand All @@ -3384,47 +3409,55 @@ void QgsVectorLayer::drawFeature(QPainter* p,

break;
}
case WKBLineString:
case QGis::WKBLineString:
case QGis::WKBLineString25D:
{
drawLineString(feature,
(wkbType == QGis::WKBLineString25D),
p,
theMapToPixelTransform,
projectionsEnabledFlag,
drawingToEditingCanvas);
break;
}
case WKBMultiLineString:
{
case QGis::WKBMultiLineString:
case QGis::WKBMultiLineString25D:
{
unsigned char* ptr = feature + 5;
unsigned int numLineStrings = *((int*)ptr);
ptr = feature + 9;

for (register unsigned int jdx = 0; jdx < numLineStrings; jdx++)
{
ptr = drawLineString(ptr,
(wkbType == QGis::WKBMultiLineString25D),
p,
theMapToPixelTransform,
projectionsEnabledFlag,
drawingToEditingCanvas);
}
break;
}
case WKBPolygon:
{
case QGis::WKBPolygon:
case QGis::WKBPolygon25D:
{
drawPolygon(feature,
(wkbType == QGis::WKBPolygon25D),
p,
theMapToPixelTransform,
projectionsEnabledFlag,
drawingToEditingCanvas);
break;
}
case WKBMultiPolygon:
{
case QGis::WKBMultiPolygon:
case QGis::WKBMultiPolygon25D:
{
unsigned char *ptr = feature + 5;
unsigned int numPolygons = *((int*)ptr);
ptr = feature + 9;
for (register unsigned int kdx = 0; kdx < numPolygons; kdx++)
ptr = drawPolygon(ptr,
(wkbType == QGis::WKBMultiPolygon25D),
p,
theMapToPixelTransform,
projectionsEnabledFlag,
Expand Down
11 changes: 2 additions & 9 deletions src/gui/qgsvectorlayer.h
Expand Up @@ -579,6 +579,7 @@ protected slots:
// to the byte after the end of the line string binary data stream
// (WKB).
unsigned char* drawLineString(unsigned char* WKBlinestring,
bool hasZValue,
QPainter* p,
QgsMapToPixel* mtp,
bool projectionsEnabledFlag,
Expand All @@ -587,6 +588,7 @@ protected slots:
// Draw the polygon as given in the WKB format. Returns a pointer to
// the byte after the end of the polygon binary data stream (WKB).
unsigned char* drawPolygon(unsigned char* WKBpolygon,
bool hasZValue,
QPainter* p,
QgsMapToPixel* mtp,
bool projectionsEnabledFlag,
Expand Down Expand Up @@ -622,15 +624,6 @@ protected slots:
bool valid;
bool registered;

enum WKBTYPE
{
WKBPoint = 1,
WKBLineString,
WKBPolygon,
WKBMultiPoint,
WKBMultiLineString,
WKBMultiPolygon
};
private: // Private methods

/**Caches all the (commited) geometries to mCachedGeometries - somewhat out of date as mCachedGeometries should only contain geometries currently visible on the canvas */
Expand Down

0 comments on commit a1f3742

Please sign in to comment.