Skip to content

Commit 50d4bb6

Browse files
committed
WMS identify feature support - get vector features from GML GetFeatureInfo
1 parent 1fe82b2 commit 50d4bb6

38 files changed

+2217
-356
lines changed

python/core/conversions.sip

+86-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ which are not wrapped by PyQt:
1818
- QMap<qint64, QgsOverlayObject*>
1919
- QList< QPair< QString, QList<QString> > >
2020
- QVector<TYPE*>
21+
- QMap<qint64, QgsFeature*>
2122
*/
2223

2324
%Feature QSETINT_CONVERSION
@@ -1386,7 +1387,8 @@ template<double, TYPE2>
13861387
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
13871388
{
13881389
int state;
1389-
int t1 = (int)(PyFloat_AsDouble(t1obj));
1390+
//int t1 = (int)(PyFloat_AsDouble(t1obj));
1391+
qint64 t1 = PyLong_AsLongLong(t1obj);
13901392
QgsOverlayObject* t2 = reinterpret_cast<QgsOverlayObject*>(sipConvertToInstance(t2obj, sipClass_QgsOverlayObject, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
13911393

13921394
if (*sipIsErr)
@@ -1581,3 +1583,86 @@ template <TYPE>
15811583
return sipGetState(sipTransferObj);
15821584
%End
15831585
};
1586+
1587+
%MappedType QMap<qint64, QgsFeature*>
1588+
{
1589+
%TypeHeaderCode
1590+
#include <QMap>
1591+
#if (SIP_VERSION >= 0x040900)
1592+
#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString))
1593+
#endif
1594+
#if (SIP_VERSION >= 0x040900 && SIP_VERSION < 0x040c01)
1595+
#define sipClass_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant))
1596+
#endif
1597+
%End
1598+
1599+
%ConvertFromTypeCode
1600+
1601+
//convert map to a python dictionary
1602+
PyObject *d;
1603+
1604+
if ((d = PyDict_New()) == NULL)
1605+
return NULL;
1606+
1607+
for (QMap<qint64, QgsFeature*>::iterator it = sipCpp->begin(); it != sipCpp->end(); ++it)
1608+
{
1609+
QgsFeature* oobj = new QgsFeature(*it.value());
1610+
1611+
PyObject* keyobj = PyInt_FromLong(it.key());
1612+
PyObject* pyOobj = sipConvertFromInstance(oobj, sipClass_QgsFeature, sipTransferObj);
1613+
PyDict_SetItem(d, keyobj, pyOobj);
1614+
1615+
if(pyOobj == NULL || keyobj == NULL || PyDict_SetItem(d, keyobj, pyOobj) < 0)
1616+
{
1617+
Py_DECREF(d);
1618+
1619+
if (pyOobj)
1620+
{
1621+
Py_DECREF(pyOobj);
1622+
}
1623+
1624+
if (keyobj)
1625+
{
1626+
Py_DECREF(keyobj);
1627+
}
1628+
return NULL;
1629+
}
1630+
Py_DECREF(pyOobj);
1631+
Py_DECREF(keyobj);
1632+
}
1633+
return d;
1634+
1635+
%End
1636+
%ConvertToTypeCode
1637+
PyObject *t1obj, *t2obj;
1638+
#if PY_VERSION_HEX >= 0x02050000
1639+
Py_ssize_t i = 0;
1640+
#else
1641+
int i = 0;
1642+
#endif
1643+
1644+
QMap<qint64, QgsFeature*> *qm = new QMap<qint64, QgsFeature*>;
1645+
1646+
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
1647+
{
1648+
int state;
1649+
qint64 t1 = PyLong_AsLongLong(t1obj);
1650+
QgsFeature* t2 = reinterpret_cast<QgsFeature*>(sipConvertToInstance(t2obj, sipClass_QgsFeature, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
1651+
1652+
if (*sipIsErr)
1653+
{
1654+
sipReleaseInstance(t2, sipClass_QgsFeature, state);
1655+
delete qm;
1656+
return 0;
1657+
}
1658+
1659+
qm->insert(t1, t2);
1660+
1661+
sipReleaseInstance(t2, sipClass_QgsFeature, state);
1662+
}
1663+
1664+
*sipCppPtr = qm;
1665+
1666+
return sipGetState(sipTransferObj);
1667+
%End
1668+
};

python/core/core.sip

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
%Include qgsfield.sip
3232
%Include qgsgeometry.sip
3333
%Include qgsgeometryvalidator.sip
34+
%Include qgsgml.sip
35+
%Include qgsgmlschema.sip
3436
%Include qgshttptransaction.sip
3537
%Include qgslabel.sip
3638
%Include qgslabelattributes.sip

python/core/qgsgml.sip

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class QgsGml: QObject
2+
{
3+
4+
%TypeHeaderCode
5+
#include <qgsgml.h>
6+
%End
7+
8+
public:
9+
10+
QgsGml(
11+
const QString& typeName,
12+
const QString& geometryAttribute,
13+
const QgsFields & fields );
14+
15+
~QgsGml();
16+
17+
/** Read from GML data. */
18+
int getFeatures( const QByteArray &data, QGis::WkbType* wkbType, QgsRectangle* extent = 0 );
19+
20+
QMap<qint64, QgsFeature* > featuresMap() const;
21+
22+
};

python/core/qgsgmlschema.sip

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//typedef QMap<int, QgsField> QgsFieldMap;
2+
3+
class QgsGmlSchema: QObject
4+
{
5+
6+
%TypeHeaderCode
7+
#include <qgsgmlschema.h>
8+
%End
9+
10+
public:
11+
QgsGmlSchema();
12+
~QgsGmlSchema();
13+
14+
/** Get fields info from XSD */
15+
bool parseXSD( const QByteArray &xml );
16+
17+
/** Guess GML schema from data if XSD does not exist.
18+
* Currently only recognizes UMN Mapserver GetFeatureInfo GML response.
19+
* @param data GML data
20+
* @return true in case of success */
21+
bool guessSchema( const QByteArray &data );
22+
23+
QStringList typeNames() const;
24+
25+
QList<QgsField> fields( const QString & typeName );
26+
27+
QStringList geometryAttributes( const QString & typeName );
28+
};

python/core/raster/qgsrasterdataprovider.sip

+5-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
4141

4242
enum IdentifyFormat
4343
{
44-
IdentifyFormatValue,
45-
IdentifyFormatText,
46-
IdentifyFormatHtml,
47-
IdentifyFormatFeature
44+
IdentifyFormatUndefined = 0,
45+
IdentifyFormatValue = 1,
46+
IdentifyFormatText = 2,
47+
IdentifyFormatHtml = 4,
48+
IdentifyFormatFeature = 8
4849
};
4950

5051
// Progress types

python/gui/qgsmaptoolidentify.sip

+8-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ class QgsMapToolIdentify : QgsMapTool
3232

3333
struct RasterResult
3434
{
35-
RasterResult();
36-
RasterResult( QgsRasterLayer* layer, QString label, QMap< QString, QString > attributes, QMap< QString, QString > derivedAttributes);
37-
QgsRasterLayer* mLayer;
38-
QString mLabel;
39-
QMap< QString, QString > mAttributes;
40-
QMap< QString, QString > mDerivedAttributes;
35+
RasterResult();
36+
RasterResult( QgsRasterLayer * layer, QString label, QgsFields fields, QgsFeature feature, QMap< QString, QString > derivedAttributes );
37+
QgsRasterLayer* mLayer;
38+
QString mLabel;
39+
QgsFields mFields;
40+
QgsFeature mFeature;
41+
QMap< QString, QString > mAttributes;
42+
QMap< QString, QString > mDerivedAttributes;
4143
};
4244

4345
struct IdentifyResults

src/app/qgisapp.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1863,6 +1863,8 @@ void QgisApp::createCanvasTools()
18631863
#endif
18641864
mMapTools.mIdentify = new QgsMapToolIdentifyAction( mMapCanvas );
18651865
mMapTools.mIdentify->setAction( mActionIdentify );
1866+
connect( mMapTools.mIdentify, SIGNAL( copyToClipboard( QgsFeatureStore & ) ),
1867+
this, SLOT( copyFeatures( QgsFeatureStore & ) ) );
18661868
mMapTools.mFeatureAction = new QgsMapToolFeatureAction( mMapCanvas );
18671869
mMapTools.mFeatureAction->setAction( mActionFeatureAction );
18681870
mMapTools.mMeasureDist = new QgsMeasureTool( mMapCanvas, false /* area */ );
@@ -5260,6 +5262,11 @@ void QgisApp::pasteTransformations()
52605262
}
52615263
#endif
52625264

5265+
void QgisApp::copyFeatures( QgsFeatureStore & featureStore )
5266+
{
5267+
clipboard()->replaceWithCopyOf( featureStore );
5268+
}
5269+
52635270
void QgisApp::refreshMapCanvas()
52645271
{
52655272
//clear all caches first

src/app/qgisapp.h

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class QgsTileScaleWidget;
8787

8888
#include "qgsconfig.h"
8989
#include "qgsfeature.h"
90+
#include "qgsfeaturestore.h"
9091
#include "qgspoint.h"
9192
#include "qgsrasterlayer.h"
9293
#include "qgssnappingdialog.h"
@@ -522,6 +523,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
522523
(defaults to the active layer on the legend)
523524
*/
524525
void pasteStyle( QgsMapLayer * destinationLayer = 0 );
526+
527+
//! copies features to internal clipboard
528+
void copyFeatures( QgsFeatureStore & featureStore );
529+
525530
void loadOGRSublayers( QString layertype, QString uri, QStringList list );
526531
void loadGDALSublayers( QString uri, QStringList list );
527532

src/app/qgsclipboard.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,31 @@ void QgsClipboard::replaceWithCopyOf( QgsVectorLayer *src )
4747
if ( !src )
4848
return;
4949

50-
QSettings settings;
51-
bool copyWKT = settings.value( "qgis/copyGeometryAsWKT", true ).toBool();
52-
5350
// Replace the QGis clipboard.
5451
mFeatureFields = src->pendingFields();
5552
mFeatureClipboard = src->selectedFeatures();
5653
mCRS = src->crs();
5754

5855
QgsDebugMsg( "replaced QGis clipboard." );
5956

57+
setSystemClipboard();
58+
}
59+
60+
void QgsClipboard::replaceWithCopyOf( QgsFeatureStore & featureStore )
61+
{
62+
QgsDebugMsg( QString( "features count = %1" ).arg( featureStore.features().size() ) );
63+
mFeatureFields = featureStore.fields();
64+
mFeatureClipboard = featureStore.features();
65+
mCRS = featureStore.crs();
66+
setSystemClipboard();
67+
}
68+
69+
void QgsClipboard::setSystemClipboard()
70+
{
6071
// Replace the system clipboard.
72+
QSettings settings;
73+
bool copyWKT = settings.value( "qgis/copyGeometryAsWKT", true ).toBool();
74+
6175
QStringList textLines;
6276
QStringList textFields;
6377

src/app/qgsclipboard.h

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "qgsfield.h"
2525
#include "qgsfeature.h"
26+
#include "qgsfeaturestore.h"
2627
#include "qgscoordinatereferencesystem.h"
2728

2829
/**
@@ -65,6 +66,12 @@ class QgsClipboard
6566
*/
6667
void replaceWithCopyOf( QgsVectorLayer *src );
6768

69+
/*
70+
* Place a copy of features on the internal clipboard,
71+
* destroying the previous contents.
72+
*/
73+
void replaceWithCopyOf( QgsFeatureStore & featureStore );
74+
6875
/*
6976
* Returns a copy of features on the internal clipboard,
7077
* the caller assumes responsibility for destroying the contents
@@ -133,6 +140,10 @@ class QgsClipboard
133140
const QgsFields &fields() { return mFeatureFields; }
134141

135142
private:
143+
/*
144+
* Set system clipboard from previously set features.
145+
*/
146+
void setSystemClipboard();
136147

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

0 commit comments

Comments
 (0)