Skip to content

Commit

Permalink
Merge pull request #5535 from nyalldawson/datum
Browse files Browse the repository at this point in the history
Datum transform handling rework, pt 1
  • Loading branch information
nyalldawson authored Dec 15, 2017
2 parents e9feeaa + 1217e59 commit 0c7cf21
Show file tree
Hide file tree
Showing 158 changed files with 4,067 additions and 1,392 deletions.
18 changes: 15 additions & 3 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,11 @@ Use QgsComposerAttributeTableV2 instead.
- QgsCRSCache was removed. QgsCoordinateReferenceSystem now internally uses a cache for CRS creation,
so there is no longer a need for the separate cache class. Code which previously called QgsCRSCache::updateCRSCache()
should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinateTransformCache::instance()->invalidateCrs( authid ).
- QgsCoordinateTransformCache was removed. QgsCoordinateTransform now transparently caches transforms.
- QgsDataDefined was removed. Use the QgsProperty framework instead.
- QgsDataDefinedButton was removed. Use QgsPropertyOverrideButton instead.
- QgsDataDefinedSymbolDialog was removed. Code using this dialog should be reworked to use QgsPropertyOverrideButton
- QgsDatumTransformStore. Use QgsCoordinateTransformContext instead.
- QgsDefaultPluginLayerLegend was removed. Use QgsMapLayer::setLegend() to provide legend nodes for plugin layers.
- DualEdgeTriangulation
- QgsFileNameWidgetWrapper was removed. Use QgsExternalResourceWidgetWrapper instead.
Expand Down Expand Up @@ -914,11 +916,12 @@ called if changes are made to the CRS database.
QgsCoordinateTransform {#qgis_api_break_3_0_QgsCoordinateTransform}
----------------------

- QgsCoordinateTransform is no longer a QObject. readXml, writeXml and initialize are all normal public members now,
- QgsCoordinateTransform is no longer a QObject. Initialize is a normal public members now,
not slots. The invalidTransformInput() signal has been removed.
- The extra QgsCoordinateTransform constructors (those not taking QgsCoordinateReferenceSystem arguments) have been
removed. Now, QgsCoordinateTransform must be created using an already existing source and destination
QgsCoordinateReferenceSystem object.
QgsCoordinateReferenceSystem object, and either a QgsCoordinateTransformContext object or a reference to the
current project instance.
- QgsCoordinateTransform::clone() has been removed. Just use direct copies instead.
- sourceCrs() and destCrs() now return a copy instead of a reference to the CRS. This has no effect on PyQGIS code, but c++
plugins calling these methods will need to be updated.
Expand All @@ -930,7 +933,15 @@ plugins calling these methods will need to be updated.
- 'p' argument in transform() has been renamed to 'point', 'theRect' to 'rectangle', 'poly' to 'polygon'
- setDestCRSID has been removed, use setDestinationCrs() instead
- 'theNode', 'theDoc' parameters in readXML and writeXML have been renamed to 'node' and 'document' respectively
- readXML() and writeXML() have been renamed to readXml() and writeXml() for consistency
- readXML() and writeXML() have been removed.
- initialize() was removed.
- datumTransformations() now returns a list of QgsCoordinateTransform.TransformPair instead of a list of lists.
- datumTransformString() was renamed to datumTransformToProj()
- datumTransformCrsInfo() was renamed to datumTransformInfo(), and now returns a QgsCoordinateTransform.TransformInfo object.
- sourceDatumTransform() was renamed to sourceDatumTransformId()
- setSourceDatumTransform() was renamed to setSourceDatumTransformId()
- destinationDatumTransform() was renamed to destinationDatumTransformId()
- setDestinationDatumTransform() was renamed to setDestinationDatumTransformId()


QgsCoordinateTransformCache {#qgis_api_break_3_0_QgsCoordinateTransformCache}
Expand Down Expand Up @@ -1636,6 +1647,7 @@ QgsMapCanvas {#qgis_api_break_3_0_QgsMapCanvas}
- setCrsTransformEnabled(), hasCrsTransformEnabled(), hasCrsTransformEnabledChanged() were removed. CRS transformation is now always enabled.
- setMapUnits() was removed. The map units are dictated by the units for the destination CRS.
- The mapUnitsChanged() signal was removed. Listen for the destinationCrsChanged() signal instead, as the destination CRS dictates the map units.
- layerCrsChange() slot was removed. Datum transforms are now handled in QgisApp.

QgsMapCanvasItem {#qgis_api_break_3_0_QgsMapCanvasItem}
----------------
Expand Down
230 changes: 230 additions & 0 deletions python/core/conversions.sip
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,236 @@ template<int, TYPE2*>
%End
};

%MappedType QMap< QPair< QString, QString>, QPair< int, int > >
{
%TypeHeaderCode
#include <QPair>
#include <QMap>
%End

%ConvertFromTypeCode
//convert map to a python dictionary
PyObject *d;

if ( ( d = PyDict_New() ) == NULL )
return NULL;

for ( auto it = sipCpp->constBegin(); it != sipCpp->constEnd(); ++ it )
{
PyObject *keyobj;
if ( ( keyobj = PyTuple_New( 2 ) ) == NULL )
{
Py_DECREF( d );
return NULL;
}
PyObject *valueobj;
if ( ( valueobj = PyTuple_New( 2 ) ) == NULL )
{
Py_DECREF( d );
return NULL;
}

// build key
PyObject *k1obj = sipConvertFromNewType( new QString( it.key().first ), sipType_QString, sipTransferObj );
PyTuple_SetItem( keyobj, 0, k1obj );
PyObject *k2obj = sipConvertFromNewType( new QString( it.key().second ), sipType_QString, sipTransferObj );
PyTuple_SetItem( keyobj, 1, k2obj );

// build value
PyObject *v1obj = PyLong_FromLong( (long)( it.value().first ) );
PyTuple_SetItem( valueobj, 0, v1obj );
PyObject *v2obj = PyLong_FromLong( (long)( it.value().second ) );
PyTuple_SetItem( valueobj, 1, v2obj );

if(keyobj == NULL || valueobj == NULL || PyDict_SetItem(d, keyobj, valueobj) < 0)
{
Py_DECREF(d);

if (valueobj)
{
Py_DECREF(valueobj);
}

if (keyobj)
{
Py_DECREF(keyobj);
}
return NULL;
}

}

return d;
%End

%ConvertToTypeCode
Py_ssize_t i = 0;

PyObject *t1obj, *t2obj;
QMap< QPair< QString, QString>, QPair< int, int > > *qm = new QMap< QPair< QString, QString>, QPair< int, int > >;

int state;
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
{
PyObject *sipKeyFirst = PyTuple_GetItem( t1obj, 0 );
PyObject *sipKeySecond = PyTuple_GetItem( t1obj, 1 );

PyObject *sipValueFirst = PyTuple_GetItem( t2obj, 0 );
qint64 v1 = PyLong_AsLongLong(sipValueFirst);
PyObject *sipValueSecond = PyTuple_GetItem( t2obj, 1 );
qint64 v2 = PyLong_AsLongLong(sipValueSecond);

QString *k1 = reinterpret_cast<QString *>(sipConvertToType(sipKeyFirst, sipType_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
if (*sipIsErr)
{
sipReleaseType(k1, sipType_QString, state);
delete qm;
return 0;
}
QString *k2 = reinterpret_cast<QString *>(sipConvertToType(sipKeySecond, sipType_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
if (*sipIsErr)
{
sipReleaseType(k1, sipType_QString, state);
sipReleaseType(k2, sipType_QString, state);
delete qm;
return 0;
}

qm->insert( qMakePair( *k1,*k2 ), qMakePair( v1, v2 ) );
sipReleaseType(k1, sipType_QString, state);
sipReleaseType(k2, sipType_QString, state);
}

*sipCppPtr = qm;

return sipGetState( sipTransferObj );
%End
};

template <TYPE>
%MappedType QMap< QPair< QString, QString>, TYPE >
{
%TypeHeaderCode
#include <QPair>
#include <QMap>
%End

%ConvertFromTypeCode
//convert map to a python dictionary
PyObject *d;

if ( ( d = PyDict_New() ) == NULL )
return NULL;

for ( auto it = sipCpp->constBegin(); it != sipCpp->constEnd(); ++ it )
{
PyObject *keyobj;
if ( ( keyobj = PyTuple_New( 2 ) ) == NULL )
{
Py_DECREF( d );
return NULL;
}

TYPE *t = new TYPE(it.value());
PyObject *tobj = sipConvertFromNewType(t, sipType_TYPE, sipTransferObj);
if ( tobj == NULL )
{
Py_DECREF(d);
delete t;
return NULL;
}

// build key
PyObject *k1obj = sipConvertFromNewType( new QString( it.key().first ), sipType_QString, sipTransferObj );
PyTuple_SetItem( keyobj, 0, k1obj );
PyObject *k2obj = sipConvertFromNewType( new QString( it.key().second ), sipType_QString, sipTransferObj );
PyTuple_SetItem( keyobj, 1, k2obj );

if(keyobj == NULL || tobj == NULL || PyDict_SetItem(d, keyobj, tobj) < 0)
{
Py_DECREF(d);

if (keyobj)
{
Py_DECREF(keyobj);
}

if (tobj)
{
Py_DECREF(tobj);
}
return NULL;
}

Py_DECREF(keyobj);
Py_DECREF(tobj);
}

return d;
%End

%ConvertToTypeCode
Py_ssize_t i = 0;
PyObject *kobj, *tobj;

// Check the type if that is all that is required.
if (sipIsErr == NULL)
{
if (!PyDict_Check(sipPy))
return 0;

while (PyDict_Next(sipPy, &i, &kobj, &tobj))
if (!sipCanConvertToType(tobj, sipType_TYPE, SIP_NOT_NONE))
return 0;

return 1;
}

PyObject *t1obj, *t2obj;
QMap< QPair< QString, QString>, TYPE > *qm = new QMap< QPair< QString, QString>, TYPE >;

int state;
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
{
PyObject *sipKeyFirst = PyTuple_GetItem( t1obj, 0 );
PyObject *sipKeySecond = PyTuple_GetItem( t1obj, 1 );
QString *k1 = reinterpret_cast<QString *>(sipConvertToType(sipKeyFirst, sipType_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
if (*sipIsErr)
{
sipReleaseType(k1, sipType_QString, state);
delete qm;
return 0;
}

QString *k2 = reinterpret_cast<QString *>(sipConvertToType(sipKeySecond, sipType_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
if (*sipIsErr)
{
sipReleaseType(k1, sipType_QString, state);
sipReleaseType(k2, sipType_QString, state);
delete qm;
return 0;
}

TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(t2obj, sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
if (*sipIsErr)
{
sipReleaseType(t, sipType_TYPE, state);

delete qm;
return 0;
}

qm->insert( qMakePair( *k1,*k2 ), *t );
sipReleaseType(k1, sipType_QString, state);
sipReleaseType(k2, sipType_QString, state);
sipReleaseType(t, sipType_TYPE, state);
}

*sipCppPtr = qm;

return sipGetState( sipTransferObj );
%End
};

template <TYPE>
%MappedType QVector< TYPE* >
Expand Down
3 changes: 1 addition & 2 deletions python/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
%Include qgsconditionalstyle.sip
%Include qgscoordinateformatter.sip
%Include qgscoordinatetransform.sip
%Include qgscrscache.sip
%Include qgscoordinatetransformcontext.sip
%Include qgsdartmeasurement.sip
%Include qgsdatadefinedsizelegend.sip
%Include qgsdataitemprovider.sip
%Include qgsdataitemproviderregistry.sip
%Include qgsdatasourceuri.sip
%Include qgsdatetimestatisticalsummary.sip
%Include qgsdatumtransformstore.sip
%Include qgsdbfilterproxymodel.sip
%Include qgsdefaultvalue.sip
%Include qgsdiagramrenderer.sip
Expand Down
Loading

0 comments on commit 0c7cf21

Please sign in to comment.