Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Removed ewkt conversion functions
  • Loading branch information
domi4484 committed Jan 10, 2022
1 parent d583bc0 commit d7a58c6
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 171 deletions.
10 changes: 5 additions & 5 deletions python/core/auto_additions/qgis.py
Expand Up @@ -773,12 +773,12 @@
Qgis.TemporalIntervalMatchMethod.__doc__ = 'Method to use when resolving a temporal range to a data provider layer or band.\n\n.. versionadded:: 3.22\n\n' + '* ``MatchUsingWholeRange``: ' + Qgis.TemporalIntervalMatchMethod.MatchUsingWholeRange.__doc__ + '\n' + '* ``MatchExactUsingStartOfRange``: ' + Qgis.TemporalIntervalMatchMethod.MatchExactUsingStartOfRange.__doc__ + '\n' + '* ``MatchExactUsingEndOfRange``: ' + Qgis.TemporalIntervalMatchMethod.MatchExactUsingEndOfRange.__doc__ + '\n' + '* ``FindClosestMatchToStartOfRange``: ' + Qgis.TemporalIntervalMatchMethod.FindClosestMatchToStartOfRange.__doc__ + '\n' + '* ``FindClosestMatchToEndOfRange``: ' + Qgis.TemporalIntervalMatchMethod.FindClosestMatchToEndOfRange.__doc__
# --
Qgis.TemporalIntervalMatchMethod.baseClass = Qgis
QgsCoordinateTransform.TransformDirection = Qgis.TransformDirection
# monkey patching scoped based enum
QgsCoordinateTransform.ForwardTransform = Qgis.TransformDirection.Forward
QgsCoordinateTransform.ForwardTransform.is_monkey_patched = True
QgsCoordinateTransform.ForwardTransform.__doc__ = "Forward transform (from source to destination)"
QgsCoordinateTransform.ReverseTransform = Qgis.TransformDirection.Reverse
Qgis.CoordinateType.XY.__doc__ = "Coordinate defined by X and Y values"
Qgis.CoordinateType.Point.__doc__ = "Coordinate defined by a point"
Qgis.CoordinateType.__doc__ = 'Types of coordinate definitions\n\n.. versionadded:: 3.22\n\n' + '* ``XY``: ' + Qgis.CoordinateType.XY.__doc__ + '\n' + '* ``Point``: ' + Qgis.CoordinateType.Point.__doc__
# --
Qgis.CoordinateType.baseClass = Qgis
QgsCoordinateTransform.ReverseTransform.is_monkey_patched = True
QgsCoordinateTransform.ReverseTransform.__doc__ = "Reverse/inverse transform (from destination to source)"
Qgis.TransformDirection.__doc__ = 'Indicates the direction (forward or inverse) of a transform.\n\n.. versionadded:: 3.22\n\n' + '* ``ForwardTransform``: ' + Qgis.TransformDirection.Forward.__doc__ + '\n' + '* ``ReverseTransform``: ' + Qgis.TransformDirection.Reverse.__doc__
Expand Down
7 changes: 0 additions & 7 deletions python/core/auto_additions/qgslabeling.py

This file was deleted.

27 changes: 1 addition & 26 deletions python/core/auto_generated/geometry/qgsreferencedgeometry.sip.in
Expand Up @@ -161,39 +161,14 @@ Construct a new QgsReferencedGeometry from referenced ``point``
static QgsReferencedGeometry fromReferencedRect( const QgsReferencedRectangle &rectangle );
%Docstring
Construct a new QgsReferencedGeometry from referenced ``rectangle``
%End

static QgsReferencedGeometry fromEwkt( const QString &ewkt );
%Docstring
Creates a new geometry from a EWKT string

.. note::

Assumes a string in the format SRID={EPSG Id};WKT

.. seealso:: :py:func:`asEwkt`

.. versionadded:: 3.22
%End

QString asEwkt( int precision = 17 ) const;
%Docstring
Exports the geometry to EWKT

:param precision: number of decimal places for coordinates

:return: the EWKT string in format SRID={EPSG Id};WKT

.. seealso:: :py:func:`fromEwkt`

.. versionadded:: 3.22
%End

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsReferencedGeometry: %1 (%2)>" ).arg( sipCpp->asWkt(), sipCpp->crs().authid() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

};


Expand Down
9 changes: 0 additions & 9 deletions python/core/auto_generated/labeling/qgslabeling.sip.in
Expand Up @@ -20,9 +20,6 @@ Contains constants and enums relating to labeling.
%TypeHeaderCode
#include "qgslabeling.h"
%End
public:
static const QMetaObject staticMetaObject;

public:

enum LinePlacementFlag
Expand All @@ -43,12 +40,6 @@ Contains constants and enums relating to labeling.
typedef QFlags<QgsLabeling::PolygonPlacementFlag> PolygonPlacementFlags;


enum class CoordinateType
{
XY,
Point
};

};

QFlags<QgsLabeling::LinePlacementFlag> operator|(QgsLabeling::LinePlacementFlag f1, QFlags<QgsLabeling::LinePlacementFlag> f2);
Expand Down
4 changes: 2 additions & 2 deletions python/core/auto_generated/labeling/qgspallabeling.sip.in
Expand Up @@ -420,7 +420,7 @@ Set unit for rotation of labels.

int priority;

QgsLabeling::CoordinateType placementCoordinateType() const;
Qgis::CoordinateType placementCoordinateType() const;
%Docstring
Coordinates type for data defined placement.

Expand All @@ -429,7 +429,7 @@ Coordinates type for data defined placement.
.. versionadded:: 3.22
%End

void setPlacementCoordinateType( QgsLabeling::CoordinateType placementCoordinateType );
void setPlacementCoordinateType( Qgis::CoordinateType placementCoordinateType );
%Docstring
Set coordinates type for data defined placement.

Expand Down
8 changes: 4 additions & 4 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -554,10 +554,10 @@ The development version
FindClosestMatchToEndOfRange
};

enum class TransformDirection
{
Forward,
Reverse
enum class CoordinateType
{
XY,
Point
};

enum class MapSettingsFlag
Expand Down
12 changes: 6 additions & 6 deletions src/app/labeling/qgsmaptoollabel.cpp
Expand Up @@ -714,15 +714,15 @@ bool QgsMapToolLabel::currentLabelDataDefinedPosition( double &x, bool &xSuccess
QgsAttributes attributes = f.attributes();
switch ( mCurrentLabel.settings.placementCoordinateType() )
{
case QgsLabeling::CoordinateType::XY:
case Qgis::CoordinateType::XY:
{
if ( !attributes.at( xCol ).isNull() )
x = attributes.at( xCol ).toDouble( &xSuccess );
if ( !attributes.at( yCol ).isNull() )
y = attributes.at( yCol ).toDouble( &ySuccess );
}
break;
case QgsLabeling::CoordinateType::Point:
case Qgis::CoordinateType::Point:
{
if ( !attributes.at( pointCol ).isNull() )
{
Expand Down Expand Up @@ -809,7 +809,7 @@ bool QgsMapToolLabel::changeCurrentLabelDataDefinedPosition( const QVariant &x,
{
switch ( mCurrentLabel.settings.placementCoordinateType() )
{
case QgsLabeling::CoordinateType::XY:
case Qgis::CoordinateType::XY:
{
QString xColName = dataDefinedColumnName( QgsPalLayerSettings::PositionX, mCurrentLabel.settings, mCurrentLabel.layer );
QString yColName = dataDefinedColumnName( QgsPalLayerSettings::PositionY, mCurrentLabel.settings, mCurrentLabel.layer );
Expand All @@ -821,7 +821,7 @@ bool QgsMapToolLabel::changeCurrentLabelDataDefinedPosition( const QVariant &x,
return false;
}
break;
case QgsLabeling::CoordinateType::Point:
case Qgis::CoordinateType::Point:
{
QString pointColName = dataDefinedColumnName( QgsPalLayerSettings::PositionPoint, mCurrentLabel.settings, mCurrentLabel.layer );
int pointCol = mCurrentLabel.layer->fields().lookupField( pointColName );
Expand Down Expand Up @@ -979,7 +979,7 @@ bool QgsMapToolLabel::labelMoveable( QgsVectorLayer *vlayer, const QgsPalLayerSe

switch ( mCurrentLabel.settings.placementCoordinateType() )
{
case QgsLabeling::CoordinateType::XY:
case Qgis::CoordinateType::XY:
{
QString xColName = dataDefinedColumnName( QgsPalLayerSettings::PositionX, settings, vlayer );
QString yColName = dataDefinedColumnName( QgsPalLayerSettings::PositionY, settings, vlayer );
Expand All @@ -989,7 +989,7 @@ bool QgsMapToolLabel::labelMoveable( QgsVectorLayer *vlayer, const QgsPalLayerSe
return false;
}
break;
case QgsLabeling::CoordinateType::Point:
case Qgis::CoordinateType::Point:
{
QString pointColName = dataDefinedColumnName( QgsPalLayerSettings::PositionPoint, settings, vlayer );
pointCol = vlayer->fields().lookupField( pointColName );
Expand Down
8 changes: 4 additions & 4 deletions src/app/labeling/qgsmaptoolmovelabel.cpp
Expand Up @@ -188,7 +188,7 @@ void QgsMapToolMoveLabel::cadCanvasPressEvent( QgsMapMouseEvent *e )
{
switch ( mCurrentLabel.settings.placementCoordinateType() )
{
case QgsLabeling::CoordinateType::XY:
case Qgis::CoordinateType::XY:
{
mPalProperties.clear();
mPalProperties << QgsPalLayerSettings::PositionX;
Expand All @@ -214,7 +214,7 @@ void QgsMapToolMoveLabel::cadCanvasPressEvent( QgsMapMouseEvent *e )
yCol = indexes[ QgsPalLayerSettings::PositionY ];
}
break;
case QgsLabeling::CoordinateType::Point:
case Qgis::CoordinateType::Point:
{
mPalProperties.clear();
mPalProperties << QgsPalLayerSettings::PositionPoint;
Expand Down Expand Up @@ -251,7 +251,7 @@ void QgsMapToolMoveLabel::cadCanvasPressEvent( QgsMapMouseEvent *e )

bool usesAuxFields = vlayer->fields().fieldOrigin( xCol ) == QgsFields::OriginJoin
&& vlayer->fields().fieldOrigin( yCol ) == QgsFields::OriginJoin;
if ( mCurrentLabel.settings.placementCoordinateType() == QgsLabeling::CoordinateType::Point
if ( mCurrentLabel.settings.placementCoordinateType() == Qgis::CoordinateType::Point
&& !mCurrentLabel.pos.isDiagram )
usesAuxFields = vlayer->fields().fieldOrigin( pointCol ) == QgsFields::OriginJoin;

Expand Down Expand Up @@ -366,7 +366,7 @@ void QgsMapToolMoveLabel::cadCanvasPressEvent( QgsMapMouseEvent *e )

bool success = false;
if ( !isCalloutMove
&& vlayer->labeling()->settings().placementCoordinateType() != QgsLabeling::CoordinateType::XY )
&& vlayer->labeling()->settings().placementCoordinateType() != Qgis::CoordinateType::XY )
{
success = changeCurrentLabelDataDefinedPosition( xPosNew, yPosNew );
}
Expand Down
32 changes: 0 additions & 32 deletions src/core/geometry/qgsreferencedgeometry.cpp
Expand Up @@ -17,8 +17,6 @@

#include "qgsreferencedgeometry.h"

#include <QRegularExpression>

QgsReferencedGeometryBase::QgsReferencedGeometryBase( const QgsCoordinateReferenceSystem &crs )
: mCrs( crs )
{}
Expand Down Expand Up @@ -67,33 +65,3 @@ QgsReferencedGeometry QgsReferencedGeometry::fromReferencedRect( const QgsRefere
{
return QgsReferencedGeometry( QgsGeometry::fromRect( rectangle ), rectangle.crs() );
}

QgsReferencedGeometry QgsReferencedGeometry::fromEwkt( const QString &ewkt )
{
Ewkt ewktinfo = parseEwkt( ewkt );

if ( ewktinfo.srid < 0 )
return QgsReferencedGeometry();

QgsGeometry geom = QgsGeometry::fromWkt( ewktinfo.wkt );
return QgsReferencedGeometry( geom, QgsCoordinateReferenceSystem::fromEpsgId( ewktinfo.srid ) );
}

QString QgsReferencedGeometry::asEwkt( int precision ) const
{
return QStringLiteral( "SRID=%1;%2" ).arg( crs().postgisSrid() ).arg( asWkt( precision ) );
}

QgsReferencedGeometry::Ewkt QgsReferencedGeometry::parseEwkt( const QString &ewkt )
{
thread_local const QRegularExpression regularExpressionSRID( "^SRID=(\\d+);" );

QRegularExpressionMatch regularExpressionMatch = regularExpressionSRID.match( ewkt );
if ( !regularExpressionMatch.hasMatch() )
return Ewkt();

Ewkt ewktStruct;
ewktStruct.wkt = ewkt.mid( regularExpressionMatch.captured( 0 ).size() );
ewktStruct.srid = regularExpressionMatch.captured( 1 ).toInt();
return ewktStruct;
}
30 changes: 0 additions & 30 deletions src/core/geometry/qgsreferencedgeometry.h
Expand Up @@ -183,36 +183,6 @@ class CORE_EXPORT QgsReferencedGeometry : public QgsGeometry, public QgsReferenc
*/
static QgsReferencedGeometry fromReferencedRect( const QgsReferencedRectangle &rectangle );

/**
* Creates a new geometry from a EWKT string
*
* \note Assumes a string in the format SRID={EPSG Id};WKT
*
* \see asEwkt()
* \since QGIS 3.22
*/
static QgsReferencedGeometry fromEwkt( const QString &ewkt );

/**
* Exports the geometry to EWKT
*
* \param precision number of decimal places for coordinates
* \returns the EWKT string in format SRID={EPSG Id};WKT
*
* \see fromEwkt()
* \since QGIS 3.22
*/
QString asEwkt( int precision = 17 ) const;

private:

struct Ewkt
{
QString wkt;
int srid = -1;
};
static Ewkt parseEwkt( const QString &ewkt );

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
Expand Down
15 changes: 0 additions & 15 deletions src/core/labeling/qgslabeling.h
Expand Up @@ -18,7 +18,6 @@

#include "qgis_core.h"
#include "qgis_sip.h"
#include <QObject>
#include <QFlags>

/**
Expand All @@ -31,8 +30,6 @@
*/
class CORE_EXPORT QgsLabeling
{
Q_GADGET

public:

/**
Expand All @@ -59,18 +56,6 @@ class CORE_EXPORT QgsLabeling
};
Q_DECLARE_FLAGS( PolygonPlacementFlags, PolygonPlacementFlag )

/**
* Types of coordinate definitions
*
* \since QGIS 3.22
*/
enum class CoordinateType : int
{
XY, //!< Coordinate defined by X and Y values
Point //!< Coordinate defined by a point
};
Q_ENUM( CoordinateType )

};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLabeling::LinePlacementFlags )
Expand Down
19 changes: 7 additions & 12 deletions src/core/labeling/qgspallabeling.cpp
Expand Up @@ -621,12 +621,12 @@ void QgsPalLayerSettings::setRotationUnit( QgsUnitTypes::AngleUnit angleUnit )
mRotationUnit = angleUnit;
}

QgsLabeling::CoordinateType QgsPalLayerSettings::placementCoordinateType() const
Qgis::CoordinateType QgsPalLayerSettings::placementCoordinateType() const
{
return mPlacementCoordinateType;
}

void QgsPalLayerSettings::setPlacementCoordinateType( QgsLabeling::CoordinateType placementCoordinateType )
void QgsPalLayerSettings::setPlacementCoordinateType( Qgis::CoordinateType placementCoordinateType )
{
mPlacementCoordinateType = placementCoordinateType;
}
Expand Down Expand Up @@ -854,7 +854,7 @@ void QgsPalLayerSettings::readFromLayerCustomProperties( QgsVectorLayer *layer )
{
repeatDistanceMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( layer->customProperty( QStringLiteral( "labeling/repeatDistanceMapUnitScale" ) ).toString() );
}
mPlacementCoordinateType = layer->customEnumProperty( QStringLiteral( "labeling/placementCoordinateType" ), QgsLabeling::CoordinateType::XY );
mPlacementCoordinateType = layer->customEnumProperty( QStringLiteral( "labeling/placementCoordinateType" ), Qgis::CoordinateType::XY );

// rendering
double scalemn = layer->customProperty( QStringLiteral( "labeling/scaleMin" ), QVariant( 0 ) ).toDouble();
Expand Down Expand Up @@ -1105,7 +1105,7 @@ void QgsPalLayerSettings::readXml( const QDomElement &elem, const QgsReadWriteCo

layerType = qgsEnumKeyToValue( placementElem.attribute( QStringLiteral( "layerType" ) ), QgsWkbTypes::UnknownGeometry );

mPlacementCoordinateType = qgsEnumKeyToValue( placementElem.attribute( QStringLiteral( "coordinateType" ), qgsEnumValueToKey( QgsLabeling::CoordinateType::XY ) ), QgsLabeling::CoordinateType::XY );
mPlacementCoordinateType = qgsEnumKeyToValue( placementElem.attribute( QStringLiteral( "coordinateType" ), qgsEnumValueToKey( Qgis::CoordinateType::XY ) ), Qgis::CoordinateType::XY );

// rendering
QDomElement renderingElem = elem.firstChildElement( QStringLiteral( "rendering" ) );
Expand Down Expand Up @@ -2399,7 +2399,7 @@ std::unique_ptr<QgsLabelFeature> QgsPalLayerSettings::registerFeatureWithDetails
bool ddPosition = false;
switch ( mPlacementCoordinateType )
{
case QgsLabeling::CoordinateType::XY:
case Qgis::CoordinateType::XY:
{
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::PositionX )
&& mDataDefinedProperties.isActive( QgsPalLayerSettings::PositionY )
Expand All @@ -2416,7 +2416,7 @@ std::unique_ptr<QgsLabelFeature> QgsPalLayerSettings::registerFeatureWithDetails
}
}
break;
case QgsLabeling::CoordinateType::Point:
case Qgis::CoordinateType::Point:
{
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::PositionPoint )
&& !mDataDefinedProperties.value( QgsPalLayerSettings::PositionPoint, context.expressionContext() ).isNull() )
Expand All @@ -2431,12 +2431,7 @@ std::unique_ptr<QgsLabelFeature> QgsPalLayerSettings::registerFeatureWithDetails
}
else if ( !pointAsVariant.toString().isEmpty() )
{
if ( !point.fromWkt( pointAsVariant.toString() ) )
{
QgsReferencedGeometry referencedGeometryPoint = QgsReferencedGeometry::fromEwkt( pointAsVariant.toString() );
if ( !referencedGeometryPoint.isNull() )
point = QgsPoint( referencedGeometryPoint.asPoint() );
}
point.fromWkt( pointAsVariant.toString() );
}

if ( !point.isEmpty() )
Expand Down

0 comments on commit d7a58c6

Please sign in to comment.