Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix loading of curved multitypes
  • Loading branch information
mhugent committed May 29, 2015
1 parent 4c1ba46 commit 0e55b3b
Show file tree
Hide file tree
Showing 23 changed files with 123 additions and 57 deletions.
4 changes: 4 additions & 0 deletions python/core/geometry/qgsabstractgeometryv2.sip
Expand Up @@ -112,4 +112,8 @@ class QgsAbstractGeometryV2
/**Length for linear geometries,perimeter for area geometries*/
virtual double length() const;
virtual double area() const;

virtual bool hasCurvedSegments() const;
/**Returns a geometry without curves. Caller takes ownership*/
virtual QgsAbstractGeometryV2* segmentize() const /Factory/;
};
1 change: 1 addition & 0 deletions python/core/geometry/qgscircularstringv2.sip
Expand Up @@ -52,4 +52,5 @@ class QgsCircularStringV2: public QgsCurveV2
bool pointAt( int i, QgsPointV2& vertex, QgsVertexId::VertexType& type ) const;

void sumUpArea( double& sum ) const;
bool hasCurvedSegments() const;
};
2 changes: 2 additions & 0 deletions python/core/geometry/qgscompoundcurvev2.sip
Expand Up @@ -58,4 +58,6 @@ class QgsCompoundCurveV2: public QgsCurveV2
bool pointAt( int i, QgsPointV2& vertex, QgsVertexId::VertexType& type ) const;

void sumUpArea( double& sum ) const;

bool hasCurvedSegments() const;
};
3 changes: 3 additions & 0 deletions python/core/geometry/qgscurvepolygonv2.sip
Expand Up @@ -59,4 +59,7 @@ class QgsCurvePolygonV2: public QgsSurfaceV2
virtual void coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coord /Out/ ) const;
double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const;
bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const;

bool hasCurvedSegments() const;
QgsAbstractGeometryV2* segmentize() const /Factory/;
};
3 changes: 3 additions & 0 deletions python/core/geometry/qgscurvev2.sip
Expand Up @@ -23,4 +23,7 @@ class QgsCurveV2: public QgsAbstractGeometryV2
virtual void coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coord /Out/ ) const;
virtual bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const;
virtual bool pointAt( int i, QgsPointV2& vertex, QgsVertexId::VertexType& type ) const = 0;

/**Returns a geometry without curves. Caller takes ownership*/
QgsAbstractGeometryV2* segmentize() const /Factory/;
};
2 changes: 2 additions & 0 deletions python/core/geometry/qgsgeometrycollectionv2.sip
Expand Up @@ -49,4 +49,6 @@ class QgsGeometryCollectionV2: public QgsAbstractGeometryV2

virtual double length() const;
virtual double area() const;

bool hasCurvedSegments() const;
};
2 changes: 2 additions & 0 deletions python/core/geometry/qgsmulticurvev2.sip
Expand Up @@ -20,4 +20,6 @@ class QgsMultiCurveV2: public QgsGeometryCollectionV2

/**Adds a geometry and takes ownership. Returns true in case of success*/
virtual bool addGeometry( QgsAbstractGeometryV2* g );
/**Returns a geometry without curves. Caller takes ownership*/
QgsAbstractGeometryV2* segmentize() const /Factory/;
};
3 changes: 3 additions & 0 deletions python/core/geometry/qgsmultisurfacev2.sip
Expand Up @@ -19,4 +19,7 @@ class QgsMultiSurfaceV2: public QgsGeometryCollectionV2

/**Adds a geometry and takes ownership. Returns true in case of success*/
virtual bool addGeometry( QgsAbstractGeometryV2* g );

/**Returns a geometry without curves. Caller takes ownership*/
QgsAbstractGeometryV2* segmentize() const /Factory/;
};
3 changes: 3 additions & 0 deletions src/core/geometry/qgsabstractgeometryv2.h
Expand Up @@ -131,6 +131,9 @@ class CORE_EXPORT QgsAbstractGeometryV2

bool isEmpty() const;

virtual bool hasCurvedSegments() const { return false; }
/**Returns a geometry without curves. Caller takes ownership*/
virtual QgsAbstractGeometryV2* segmentize() const { return clone(); }

protected:
QgsWKBTypes::Type mWkbType;
Expand Down
2 changes: 2 additions & 0 deletions src/core/geometry/qgscircularstringv2.h
Expand Up @@ -72,6 +72,8 @@ class CORE_EXPORT QgsCircularStringV2: public QgsCurveV2

void sumUpArea( double& sum ) const override;

bool hasCurvedSegments() const override { return true; }

private:
QVector<double> mX;
QVector<double> mY;
Expand Down
32 changes: 14 additions & 18 deletions src/core/geometry/qgscompoundcurvev2.cpp
Expand Up @@ -333,24 +333,7 @@ QgsLineStringV2* QgsCompoundCurveV2::curveToLine() const
line->append( currentLine );
delete currentLine;
}
#if 0
if ( curveIt == mCurves.constBegin() )
{
line = ( *curveIt )->curveToLine();
if ( !line )
{
return 0;
}
}
else
{
currentLine = ( *curveIt )->curveToLine();
line->append( currentLine );
delete currentLine;
}
}
#endif //0
return line;
return line;
}

const QgsCurveV2* QgsCompoundCurveV2::curveAt( int i ) const
Expand Down Expand Up @@ -568,3 +551,16 @@ void QgsCompoundCurveV2::close()
addVertex( startPoint() );
}

bool QgsCompoundCurveV2::hasCurvedSegments() const
{
QList< QgsCurveV2* >::const_iterator curveIt = mCurves.constBegin();
for ( ; curveIt != mCurves.constEnd(); ++curveIt )
{
if (( *curveIt )->hasCurvedSegments() )
{
return true;
}
}
return false;
}

2 changes: 2 additions & 0 deletions src/core/geometry/qgscompoundcurvev2.h
Expand Up @@ -78,6 +78,8 @@ class CORE_EXPORT QgsCompoundCurveV2: public QgsCurveV2
/**Appends first point if not already closed*/
void close();

bool hasCurvedSegments() const override;

private:
QList< QgsCurveV2* > mCurves;
/**Turns a vertex id for the compound curve into one or more ids for the subcurves
Expand Down
23 changes: 23 additions & 0 deletions src/core/geometry/qgscurvepolygonv2.cpp
Expand Up @@ -636,3 +636,26 @@ bool QgsCurvePolygonV2::deleteVertex( const QgsVertexId& vId )
}
return success;
}

bool QgsCurvePolygonV2::hasCurvedSegments() const
{
if ( mExteriorRing && mExteriorRing->hasCurvedSegments() )
{
return true;
}

QList<QgsCurveV2*>::const_iterator it = mInteriorRings.constBegin();
for ( ; it != mInteriorRings.constEnd(); ++it )
{
if (( *it )->hasCurvedSegments() )
{
return true;
}
}
return false;
}

QgsAbstractGeometryV2* QgsCurvePolygonV2::segmentize() const
{
return toPolygon();
}
3 changes: 3 additions & 0 deletions src/core/geometry/qgscurvepolygonv2.h
Expand Up @@ -80,6 +80,9 @@ class CORE_EXPORT QgsCurvePolygonV2: public QgsSurfaceV2
double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const override;
bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const override;

bool hasCurvedSegments() const override;
QgsAbstractGeometryV2* segmentize() const override;

protected:

QgsCurveV2* mExteriorRing;
Expand Down
6 changes: 6 additions & 0 deletions src/core/geometry/qgscurvev2.cpp
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/

#include "qgscurvev2.h"
#include "qgslinestringv2.h"

QgsCurveV2::QgsCurveV2(): QgsAbstractGeometryV2()
{}
Expand Down Expand Up @@ -79,3 +80,8 @@ double QgsCurveV2::area() const
sumUpArea( area );
return qAbs( area );
}

QgsAbstractGeometryV2* QgsCurveV2::segmentize() const
{
return curveToLine();
}
3 changes: 3 additions & 0 deletions src/core/geometry/qgscurvev2.h
Expand Up @@ -46,6 +46,9 @@ class CORE_EXPORT QgsCurveV2: public QgsAbstractGeometryV2
virtual void coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coord ) const override;
virtual bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const override;
virtual bool pointAt( int i, QgsPointV2& vertex, QgsVertexId::VertexType& type ) const = 0;

/**Returns a geometry without curves. Caller takes ownership*/
QgsAbstractGeometryV2* segmentize() const override;
};

#endif // QGSCURVEV2_H
44 changes: 5 additions & 39 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -1485,42 +1485,10 @@ void QgsGeometry::convertToStraightSegment()
}

detach();
QgsWKBTypes::Type flatGeomType = QgsWKBTypes::flatType( d->geometry->wkbType() );
if ( flatGeomType == QgsWKBTypes::CompoundCurve || flatGeomType == QgsWKBTypes::CircularString )
{
QgsCurveV2* curve = dynamic_cast<QgsCurveV2*>( d->geometry );
if ( !curve )
{
return ;
}
d->geometry = curve->curveToLine();
removeWkbGeos();
delete curve;
}
else if ( flatGeomType == QgsWKBTypes::CurvePolygon )
{
QgsCurvePolygonV2* curvePolygon = dynamic_cast<QgsCurvePolygonV2*>( d->geometry );
if ( !curvePolygon )
{
return;
}
d->geometry = curvePolygon->toPolygon();
removeWkbGeos();
delete curvePolygon;
}
else //no segmentation needed
{
return;
}

//compoundcurve / circularstring /multicurve ?

//curve polygon / multisurface?
delete[] mWkb;
mWkb = 0;
mWkbSize = 0;
GEOSGeom_destroy( mGeos );
mGeos = 0;
QgsAbstractGeometryV2* straightGeom = d->geometry->segmentize();
delete d->geometry;
d->geometry = straightGeom;
removeWkbGeos();
}

bool QgsGeometry::requiresConversionToStraightSegments() const
Expand All @@ -1530,9 +1498,7 @@ bool QgsGeometry::requiresConversionToStraightSegments() const
return false;
}

QgsWKBTypes::Type flatGeomType = QgsWKBTypes::flatType( d->geometry->wkbType() );
return ( flatGeomType == QgsWKBTypes::CompoundCurve || flatGeomType == QgsWKBTypes::CircularString
|| flatGeomType == QgsWKBTypes::CurvePolygon );
return d->geometry->hasCurvedSegments();
}

int QgsGeometry::transform( const QgsCoordinateTransform& ct )
Expand Down
13 changes: 13 additions & 0 deletions src/core/geometry/qgsgeometrycollectionv2.cpp
Expand Up @@ -446,3 +446,16 @@ bool QgsGeometryCollectionV2::fromCollectionWkt( const QString &wkt, const QList
qDeleteAll( subtypes );
return true;
}

bool QgsGeometryCollectionV2::hasCurvedSegments() const
{
QVector< QgsAbstractGeometryV2* >::const_iterator it = mGeometries.constBegin();
for ( ; it != mGeometries.constEnd(); ++it )
{
if (( *it )->hasCurvedSegments() )
{
return true;
}
}
return false;
}
2 changes: 2 additions & 0 deletions src/core/geometry/qgsgeometrycollectionv2.h
Expand Up @@ -70,6 +70,8 @@ class CORE_EXPORT QgsGeometryCollectionV2: public QgsAbstractGeometryV2
virtual double length() const override;
virtual double area() const override;

bool hasCurvedSegments() const override;

protected:
QVector< QgsAbstractGeometryV2* > mGeometries;
void removeGeometries();
Expand Down
11 changes: 11 additions & 0 deletions src/core/geometry/qgsmulticurvev2.cpp
Expand Up @@ -106,3 +106,14 @@ bool QgsMultiCurveV2::addGeometry( QgsAbstractGeometryV2* g )
setZMTypeFromSubGeometry( g, QgsWKBTypes::MultiCurve );
return QgsGeometryCollectionV2::addGeometry( g );
}

QgsAbstractGeometryV2* QgsMultiCurveV2::segmentize() const
{
QgsMultiCurveV2* c = new QgsMultiCurveV2();
QVector< QgsAbstractGeometryV2* >::const_iterator geomIt = mGeometries.constBegin();
for ( ; geomIt != mGeometries.constEnd(); ++geomIt )
{
c->addGeometry(( *geomIt )->segmentize() );
}
return c;
}
2 changes: 2 additions & 0 deletions src/core/geometry/qgsmulticurvev2.h
Expand Up @@ -36,6 +36,8 @@ class CORE_EXPORT QgsMultiCurveV2: public QgsGeometryCollectionV2

/**Adds a geometry and takes ownership. Returns true in case of success*/
virtual bool addGeometry( QgsAbstractGeometryV2* g ) override;
/**Returns a geometry without curves. Caller takes ownership*/
QgsAbstractGeometryV2* segmentize() const override;
};

#endif // QGSMULTICURVEV2_H
11 changes: 11 additions & 0 deletions src/core/geometry/qgsmultisurfacev2.cpp
Expand Up @@ -126,3 +126,14 @@ bool QgsMultiSurfaceV2::addGeometry( QgsAbstractGeometryV2* g )
setZMTypeFromSubGeometry( g, QgsWKBTypes::MultiSurface );
return QgsGeometryCollectionV2::addGeometry( g );
}

QgsAbstractGeometryV2* QgsMultiSurfaceV2::segmentize() const
{
QgsMultiSurfaceV2* c = new QgsMultiSurfaceV2();
QVector< QgsAbstractGeometryV2* >::const_iterator geomIt = mGeometries.constBegin();
for ( ; geomIt != mGeometries.constEnd(); ++geomIt )
{
c->addGeometry(( *geomIt )->segmentize() );
}
return c;
}
3 changes: 3 additions & 0 deletions src/core/geometry/qgsmultisurfacev2.h
Expand Up @@ -36,6 +36,9 @@ class CORE_EXPORT QgsMultiSurfaceV2: public QgsGeometryCollectionV2

/**Adds a geometry and takes ownership. Returns true in case of success*/
virtual bool addGeometry( QgsAbstractGeometryV2* g ) override;

/**Returns a geometry without curves. Caller takes ownership*/
QgsAbstractGeometryV2* segmentize() const override;
};

#endif // QGSMULTISURFACEV2_H

0 comments on commit 0e55b3b

Please sign in to comment.