Skip to content
Permalink
Browse files

adapt local simplication to new geometry types (fixes #13538)

  • Loading branch information
jef-n committed Oct 8, 2015
1 parent a0d7653 commit bc59d6f18d57af8f52b656e21a8f083c3087684e
Showing with 177 additions and 118 deletions.
  1. +149 −0 src/core/qgis.cpp
  2. +27 −117 src/core/qgis.h
  3. +1 −1 src/core/qgsmaptopixelgeometrysimplifier.cpp
@@ -27,6 +27,7 @@
#include <QDateTime>
#include "qgsconfig.h"
#include "qgslogger.h"
#include "geometry/qgswkbtypes.h"

#include <ogr_api.h>

@@ -99,6 +100,56 @@ const char* QGis::qgisUnitTypes[] =
QT_TRANSLATE_NOOP( "QGis::UnitType", "nautical miles" )
};

static QgsWKBTypes::Type fromOldWkbType( QGis::WkbType type )
{
switch ( type )
{
case QGis::WKBPoint: return QgsWKBTypes::Point;
case QGis::WKBLineString: return QgsWKBTypes::LineString;
case QGis::WKBPolygon: return QgsWKBTypes::Polygon;
case QGis::WKBMultiPoint: return QgsWKBTypes::MultiPoint;
case QGis::WKBMultiLineString: return QgsWKBTypes::MultiLineString;
case QGis::WKBMultiPolygon: return QgsWKBTypes::MultiPolygon;
case QGis::WKBNoGeometry: return QgsWKBTypes::NoGeometry;
case QGis::WKBPoint25D: return QgsWKBTypes::PointZ;
case QGis::WKBLineString25D: return QgsWKBTypes::LineStringZ;
case QGis::WKBPolygon25D: return QgsWKBTypes::PolygonZ;
case QGis::WKBMultiPoint25D: return QgsWKBTypes::MultiPointZ;
case QGis::WKBMultiLineString25D: return QgsWKBTypes::MultiLineStringZ;
case QGis::WKBMultiPolygon25D: return QgsWKBTypes::MultiPolygonZ;
case QGis::WKBUnknown: return QgsWKBTypes::Unknown;
default: break;
}

QgsDebugMsg( QString( "unexpected old wkbType=%1" ).arg( type ) );
return ( QgsWKBTypes::Type ) type;
}

static QGis::WkbType fromNewWkbType( QgsWKBTypes::Type type )
{
switch ( type )
{
case QgsWKBTypes::Point: return QGis::WKBPoint;
case QgsWKBTypes::LineString: return QGis::WKBLineString;
case QgsWKBTypes::Polygon: return QGis::WKBPolygon;
case QgsWKBTypes::MultiPoint: return QGis::WKBMultiPoint;
case QgsWKBTypes::MultiLineString: return QGis::WKBMultiLineString;
case QgsWKBTypes::MultiPolygon: return QGis::WKBMultiPolygon;
case QgsWKBTypes::NoGeometry: return QGis::WKBNoGeometry;
case QgsWKBTypes::PointZ: return QGis::WKBPoint25D;
case QgsWKBTypes::LineStringZ: return QGis::WKBLineString25D;
case QgsWKBTypes::PolygonZ: return QGis::WKBPolygon25D;
case QgsWKBTypes::MultiPointZ: return QGis::WKBMultiPoint25D;
case QgsWKBTypes::MultiLineStringZ: return QGis::WKBMultiLineString25D;
case QgsWKBTypes::MultiPolygonZ: return QGis::WKBMultiPolygon25D;
default: break;
}

QgsDebugMsg( QString( "unexpected new wkbType=%1" ).arg( type ) );
return ( QGis::WkbType ) type;
}


QGis::UnitType QGis::fromLiteral( const QString& literal, QGis::UnitType defaultType )
{
for ( unsigned int i = 0; i < ( sizeof( qgisUnitTypes ) / sizeof( qgisUnitTypes[0] ) ); i++ )
@@ -282,3 +333,101 @@ QString qgsVsiPrefix( const QString& path )
else
return "";
}

QGis::WkbType QGis::singleType( QGis::WkbType type )
{
switch ( type )
{
case WKBMultiPoint: return WKBPoint;
case WKBMultiLineString: return WKBLineString;
case WKBMultiPolygon: return WKBPolygon;
case WKBMultiPoint25D: return WKBPoint25D;
case WKBMultiLineString25D: return WKBLineString25D;
case WKBMultiPolygon25D: return WKBPolygon25D;
default: return fromNewWkbType( QgsWKBTypes::singleType( fromOldWkbType( type ) ) );
}
}

QGis::WkbType QGis::multiType( QGis::WkbType type )
{
switch ( type )
{
case WKBPoint: return WKBMultiPoint;
case WKBLineString: return WKBMultiLineString;
case WKBPolygon: return WKBMultiPolygon;
case WKBPoint25D: return WKBMultiPoint25D;
case WKBLineString25D: return WKBMultiLineString25D;
case WKBPolygon25D: return WKBMultiPolygon25D;
default: return fromNewWkbType( QgsWKBTypes::multiType( fromOldWkbType( type ) ) );
}
}

QGis::WkbType QGis::flatType( QGis::WkbType type )
{
switch ( type )
{
case WKBPoint25D: return WKBPoint;
case WKBLineString25D: return WKBLineString;
case WKBPolygon25D: return WKBPolygon;
case WKBMultiPoint25D: return WKBMultiPoint;
case WKBMultiLineString25D: return WKBMultiLineString;
case WKBMultiPolygon25D: return WKBMultiPolygon;
default: return fromNewWkbType( QgsWKBTypes::flatType( fromOldWkbType( type ) ) );
}
}

bool QGis::isSingleType( QGis::WkbType type )
{
return QgsWKBTypes::isSingleType( fromOldWkbType( type ) );
}

bool QGis::isMultiType( QGis::WkbType type )
{
return QgsWKBTypes::flatType( fromOldWkbType( type ) );
}

int QGis::wkbDimensions( QGis::WkbType type )
{
if ( type == WKBUnknown || type == WKBNoGeometry )
return 0;

QgsWKBTypes::Type wkbType = fromOldWkbType( type );
return 2 + ( QgsWKBTypes::hasZ( wkbType ) ? 1 : 0 ) + ( QgsWKBTypes::hasM( wkbType ) ? 1 : 0 );
}

const char *QGis::vectorGeometryType( QGis::GeometryType type )
{
switch ( type )
{
case Point: return "Point";
case Line: return "Line";
case Polygon: return "Polygon";
case UnknownGeometry: return "Unknown geometry";
case NoGeometry: return "No geometry";
default: return "Invalid type";
}
}


const char *QGis::featureType( QGis::WkbType type )
{
switch ( type )
{
case WKBUnknown: return "WKBUnknown";
case WKBPoint: return "WKBPoint";
case WKBLineString: return "WKBLineString";
case WKBPolygon: return "WKBPolygon";
case WKBMultiPoint: return "WKBMultiPoint";
case WKBMultiLineString: return "WKBMultiLineString";
case WKBMultiPolygon: return "WKBMultiPolygon";
case WKBNoGeometry: return "WKBNoGeometry";
case WKBPoint25D: return "WKBPoint25D";
case WKBLineString25D: return "WKBLineString25D";
case WKBPolygon25D: return "WKBPolygon25D";
case WKBMultiPoint25D: return "WKBMultiPoint25D";
case WKBMultiLineString25D: return "WKBMultiLineString25D";
case WKBMultiPolygon25D: return "WKBMultiPolygon25D";
default: return "invalid wkbtype";

}
}
@@ -50,7 +50,8 @@ class CORE_EXPORT QGis

//! Used for symbology operations
// Feature types
enum WkbType
// @deprecated use QgsWKBTypes::Type
/* Q_DECL_DEPRECATED */ enum WkbType
{
WKBUnknown = 0,
WKBPoint = 1,
@@ -68,89 +69,29 @@ class CORE_EXPORT QGis
WKBMultiPolygon25D,
};

static WkbType singleType( WkbType type )
{
switch ( type )
{
case WKBMultiPoint: return WKBPoint;
case WKBMultiLineString: return WKBLineString;
case WKBMultiPolygon: return WKBPolygon;
case WKBMultiPoint25D: return WKBPoint25D;
case WKBMultiLineString25D: return WKBLineString25D;
case WKBMultiPolygon25D: return WKBPolygon25D;
default: return type;
}
}

static WkbType multiType( WkbType type )
{
switch ( type )
{
case WKBPoint: return WKBMultiPoint;
case WKBLineString: return WKBMultiLineString;
case WKBPolygon: return WKBMultiPolygon;
case WKBPoint25D: return WKBMultiPoint25D;
case WKBLineString25D: return WKBMultiLineString25D;
case WKBPolygon25D: return WKBMultiPolygon25D;
default: return type;
}
}

static WkbType flatType( WkbType type )
{
switch ( type )
{
case WKBPoint25D: return WKBPoint;
case WKBLineString25D: return WKBLineString;
case WKBPolygon25D: return WKBPolygon;
case WKBMultiPoint25D: return WKBMultiPoint;
case WKBMultiLineString25D: return WKBMultiLineString;
case WKBMultiPolygon25D: return WKBMultiPolygon;
default: return type;
}
}

static bool isSingleType( WkbType type )
{
switch ( flatType( type ) )
{
case WKBPoint:
case WKBLineString:
case WKBPolygon:
return true;
default:
return false;
}
}

static bool isMultiType( WkbType type )
{
switch ( flatType( type ) )
{
case WKBMultiPoint:
case WKBMultiLineString:
case WKBMultiPolygon:
return true;
default:
return false;
}
}

static int wkbDimensions( WkbType type )
{
switch ( type )
{
case WKBUnknown: return 0;
case WKBNoGeometry: return 0;
case WKBPoint25D: return 3;
case WKBLineString25D: return 3;
case WKBPolygon25D: return 3;
case WKBMultiPoint25D: return 3;
case WKBMultiLineString25D: return 3;
case WKBMultiPolygon25D: return 3;
default: return 2;
}
}
//! Map multi to single type
// @deprecated use QgsWKBTypes::singleType
/* Q_DECL_DEPRECATED */ static WkbType singleType( WkbType type );

//! Map single to multitype type
// @deprecated use QgsWKBTypes::multiType
/* Q_DECL_DEPRECATED */ static WkbType multiType( WkbType type );

//! Map 2d+ to 2d type
// @deprecated use QgsWKBTypes::flatType
/* Q_DECL_DEPRECATED */ static WkbType flatType( WkbType type );

//! Return if type is a single type
// @deprecated use QgsWKBTypes::isSingleType
/* Q_DECL_DEPRECATED */ static bool isSingleType( WkbType type );

//! Return if type is a multi type
// @deprecated use QgsWKBTypes::isMultiType
/* Q_DECL_DEPRECATED */ static bool isMultiType( WkbType type );

// get dimension of points
// @deprecated use QgsWKBTypes::hasZ() and QgsWKBTypes::hasM()
/* Q_DECL_DEPRECATED */ static int wkbDimensions( WkbType type );

enum GeometryType
{
@@ -162,41 +103,10 @@ class CORE_EXPORT QGis
};

//! description strings for geometry types
static const char *vectorGeometryType( GeometryType type )
{
switch ( type )
{
case Point: return "Point";
case Line: return "Line";
case Polygon: return "Polygon";
case UnknownGeometry: return "Unknown geometry";
case NoGeometry: return "No geometry";
default: return "Invalid type";
}
}
static const char *vectorGeometryType( GeometryType type );

//! description strings for feature types
static const char *featureType( WkbType type )
{
switch ( type )
{
case WKBUnknown: return "WKBUnknown";
case WKBPoint: return "WKBPoint";
case WKBLineString: return "WKBLineString";
case WKBPolygon: return "WKBPolygon";
case WKBMultiPoint: return "WKBMultiPoint";
case WKBMultiLineString: return "WKBMultiLineString";
case WKBMultiPolygon: return "WKBMultiPolygon";
case WKBNoGeometry: return "WKBNoGeometry";
case WKBPoint25D: return "WKBPoint25D";
case WKBLineString25D: return "WKBLineString25D";
case WKBPolygon25D: return "WKBPolygon25D";
case WKBMultiPoint25D: return "WKBMultiPoint25D";
case WKBMultiLineString25D: return "WKBMultiLineString25D";
case WKBMultiPolygon25D: return "WKBMultiPolygon25D";
default: return "invalid wkbtype";
}
}
static const char *featureType( WkbType type );

/** Raster data types.
* This is modified and extended copy of GDALDataType.
@@ -72,7 +72,7 @@ static bool generalizeWkbGeometryByBoundingBox(
unsigned int geometryType = QGis::singleType( QGis::flatType( wkbType ) );

int sizeOfDoubleX = sizeof( double );
int sizeOfDoubleY = QGis::wkbDimensions( wkbType ) == 3 /*hasZValue*/ ? 2 * sizeof( double ) : sizeof( double );
int sizeOfDoubleY = sizeof( double ) * ( QGis::wkbDimensions( wkbType ) - 1 );

// If the geometry is already minimal skip the generalization
size_t minimumSize = geometryType == QGis::WKBLineString ? 4 + 2 * ( sizeOfDoubleX + sizeOfDoubleY ) : 8 + 5 * ( sizeOfDoubleX + sizeOfDoubleY );

0 comments on commit bc59d6f

Please sign in to comment.
You can’t perform that action at this time.