Skip to content

Commit

Permalink
WMS identify feature support - get vector features from GML GetFeatur…
Browse files Browse the repository at this point in the history
…eInfo
  • Loading branch information
blazek committed Feb 6, 2013
1 parent 1fe82b2 commit 50d4bb6
Show file tree
Hide file tree
Showing 38 changed files with 2,217 additions and 356 deletions.
87 changes: 86 additions & 1 deletion python/core/conversions.sip
Expand Up @@ -18,6 +18,7 @@ which are not wrapped by PyQt:
- QMap<qint64, QgsOverlayObject*>
- QList< QPair< QString, QList<QString> > >
- QVector<TYPE*>
- QMap<qint64, QgsFeature*>
*/

%Feature QSETINT_CONVERSION
Expand Down Expand Up @@ -1386,7 +1387,8 @@ template<double, TYPE2>
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
{
int state;
int t1 = (int)(PyFloat_AsDouble(t1obj));
//int t1 = (int)(PyFloat_AsDouble(t1obj));
qint64 t1 = PyLong_AsLongLong(t1obj);
QgsOverlayObject* t2 = reinterpret_cast<QgsOverlayObject*>(sipConvertToInstance(t2obj, sipClass_QgsOverlayObject, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));

if (*sipIsErr)
Expand Down Expand Up @@ -1581,3 +1583,86 @@ template <TYPE>
return sipGetState(sipTransferObj);
%End
};

%MappedType QMap<qint64, QgsFeature*>
{
%TypeHeaderCode
#include <QMap>
#if (SIP_VERSION >= 0x040900)
#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString))
#endif
#if (SIP_VERSION >= 0x040900 && SIP_VERSION < 0x040c01)
#define sipClass_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant))
#endif
%End

%ConvertFromTypeCode

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

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

for (QMap<qint64, QgsFeature*>::iterator it = sipCpp->begin(); it != sipCpp->end(); ++it)
{
QgsFeature* oobj = new QgsFeature(*it.value());

PyObject* keyobj = PyInt_FromLong(it.key());
PyObject* pyOobj = sipConvertFromInstance(oobj, sipClass_QgsFeature, sipTransferObj);
PyDict_SetItem(d, keyobj, pyOobj);

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

if (pyOobj)
{
Py_DECREF(pyOobj);
}

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

%End
%ConvertToTypeCode
PyObject *t1obj, *t2obj;
#if PY_VERSION_HEX >= 0x02050000
Py_ssize_t i = 0;
#else
int i = 0;
#endif

QMap<qint64, QgsFeature*> *qm = new QMap<qint64, QgsFeature*>;

while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
{
int state;
qint64 t1 = PyLong_AsLongLong(t1obj);
QgsFeature* t2 = reinterpret_cast<QgsFeature*>(sipConvertToInstance(t2obj, sipClass_QgsFeature, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));

if (*sipIsErr)
{
sipReleaseInstance(t2, sipClass_QgsFeature, state);
delete qm;
return 0;
}

qm->insert(t1, t2);

sipReleaseInstance(t2, sipClass_QgsFeature, state);
}

*sipCppPtr = qm;

return sipGetState(sipTransferObj);
%End
};
2 changes: 2 additions & 0 deletions python/core/core.sip
Expand Up @@ -31,6 +31,8 @@
%Include qgsfield.sip
%Include qgsgeometry.sip
%Include qgsgeometryvalidator.sip
%Include qgsgml.sip
%Include qgsgmlschema.sip
%Include qgshttptransaction.sip
%Include qgslabel.sip
%Include qgslabelattributes.sip
Expand Down
22 changes: 22 additions & 0 deletions python/core/qgsgml.sip
@@ -0,0 +1,22 @@
class QgsGml: QObject
{

%TypeHeaderCode
#include <qgsgml.h>
%End

public:

QgsGml(
const QString& typeName,
const QString& geometryAttribute,
const QgsFields & fields );

~QgsGml();

/** Read from GML data. */
int getFeatures( const QByteArray &data, QGis::WkbType* wkbType, QgsRectangle* extent = 0 );

QMap<qint64, QgsFeature* > featuresMap() const;

};
28 changes: 28 additions & 0 deletions python/core/qgsgmlschema.sip
@@ -0,0 +1,28 @@
//typedef QMap<int, QgsField> QgsFieldMap;

class QgsGmlSchema: QObject
{

%TypeHeaderCode
#include <qgsgmlschema.h>
%End

public:
QgsGmlSchema();
~QgsGmlSchema();

/** Get fields info from XSD */
bool parseXSD( const QByteArray &xml );

/** Guess GML schema from data if XSD does not exist.
* Currently only recognizes UMN Mapserver GetFeatureInfo GML response.
* @param data GML data
* @return true in case of success */
bool guessSchema( const QByteArray &data );

QStringList typeNames() const;

QList<QgsField> fields( const QString & typeName );

QStringList geometryAttributes( const QString & typeName );
};
9 changes: 5 additions & 4 deletions python/core/raster/qgsrasterdataprovider.sip
Expand Up @@ -41,10 +41,11 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface

enum IdentifyFormat
{
IdentifyFormatValue,
IdentifyFormatText,
IdentifyFormatHtml,
IdentifyFormatFeature
IdentifyFormatUndefined = 0,
IdentifyFormatValue = 1,
IdentifyFormatText = 2,
IdentifyFormatHtml = 4,
IdentifyFormatFeature = 8
};

// Progress types
Expand Down
14 changes: 8 additions & 6 deletions python/gui/qgsmaptoolidentify.sip
Expand Up @@ -32,12 +32,14 @@ class QgsMapToolIdentify : QgsMapTool

struct RasterResult
{
RasterResult();
RasterResult( QgsRasterLayer* layer, QString label, QMap< QString, QString > attributes, QMap< QString, QString > derivedAttributes);
QgsRasterLayer* mLayer;
QString mLabel;
QMap< QString, QString > mAttributes;
QMap< QString, QString > mDerivedAttributes;
RasterResult();
RasterResult( QgsRasterLayer * layer, QString label, QgsFields fields, QgsFeature feature, QMap< QString, QString > derivedAttributes );
QgsRasterLayer* mLayer;
QString mLabel;
QgsFields mFields;
QgsFeature mFeature;
QMap< QString, QString > mAttributes;
QMap< QString, QString > mDerivedAttributes;
};

struct IdentifyResults
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -1863,6 +1863,8 @@ void QgisApp::createCanvasTools()
#endif
mMapTools.mIdentify = new QgsMapToolIdentifyAction( mMapCanvas );
mMapTools.mIdentify->setAction( mActionIdentify );
connect( mMapTools.mIdentify, SIGNAL( copyToClipboard( QgsFeatureStore & ) ),
this, SLOT( copyFeatures( QgsFeatureStore & ) ) );
mMapTools.mFeatureAction = new QgsMapToolFeatureAction( mMapCanvas );
mMapTools.mFeatureAction->setAction( mActionFeatureAction );
mMapTools.mMeasureDist = new QgsMeasureTool( mMapCanvas, false /* area */ );
Expand Down Expand Up @@ -5260,6 +5262,11 @@ void QgisApp::pasteTransformations()
}
#endif

void QgisApp::copyFeatures( QgsFeatureStore & featureStore )
{
clipboard()->replaceWithCopyOf( featureStore );
}

void QgisApp::refreshMapCanvas()
{
//clear all caches first
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -87,6 +87,7 @@ class QgsTileScaleWidget;

#include "qgsconfig.h"
#include "qgsfeature.h"
#include "qgsfeaturestore.h"
#include "qgspoint.h"
#include "qgsrasterlayer.h"
#include "qgssnappingdialog.h"
Expand Down Expand Up @@ -522,6 +523,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
(defaults to the active layer on the legend)
*/
void pasteStyle( QgsMapLayer * destinationLayer = 0 );

//! copies features to internal clipboard
void copyFeatures( QgsFeatureStore & featureStore );

void loadOGRSublayers( QString layertype, QString uri, QStringList list );
void loadGDALSublayers( QString uri, QStringList list );

Expand Down
20 changes: 17 additions & 3 deletions src/app/qgsclipboard.cpp
Expand Up @@ -47,17 +47,31 @@ void QgsClipboard::replaceWithCopyOf( QgsVectorLayer *src )
if ( !src )
return;

QSettings settings;
bool copyWKT = settings.value( "qgis/copyGeometryAsWKT", true ).toBool();

// Replace the QGis clipboard.
mFeatureFields = src->pendingFields();
mFeatureClipboard = src->selectedFeatures();
mCRS = src->crs();

QgsDebugMsg( "replaced QGis clipboard." );

setSystemClipboard();
}

void QgsClipboard::replaceWithCopyOf( QgsFeatureStore & featureStore )
{
QgsDebugMsg( QString( "features count = %1" ).arg( featureStore.features().size() ) );
mFeatureFields = featureStore.fields();
mFeatureClipboard = featureStore.features();
mCRS = featureStore.crs();
setSystemClipboard();
}

void QgsClipboard::setSystemClipboard()
{
// Replace the system clipboard.
QSettings settings;
bool copyWKT = settings.value( "qgis/copyGeometryAsWKT", true ).toBool();

QStringList textLines;
QStringList textFields;

Expand Down
11 changes: 11 additions & 0 deletions src/app/qgsclipboard.h
Expand Up @@ -23,6 +23,7 @@

#include "qgsfield.h"
#include "qgsfeature.h"
#include "qgsfeaturestore.h"
#include "qgscoordinatereferencesystem.h"

/**
Expand Down Expand Up @@ -65,6 +66,12 @@ class QgsClipboard
*/
void replaceWithCopyOf( QgsVectorLayer *src );

/*
* Place a copy of features on the internal clipboard,
* destroying the previous contents.
*/
void replaceWithCopyOf( QgsFeatureStore & featureStore );

/*
* Returns a copy of features on the internal clipboard,
* the caller assumes responsibility for destroying the contents
Expand Down Expand Up @@ -133,6 +140,10 @@ class QgsClipboard
const QgsFields &fields() { return mFeatureFields; }

private:
/*
* Set system clipboard from previously set features.
*/
void setSystemClipboard();

/** QGIS-internal vector feature clipboard.
Stored as values not pointers as each clipboard operation
Expand Down

0 comments on commit 50d4bb6

Please sign in to comment.