📄 qgspostgresprovider.h
字号:
//Added by qt3to4:#include <QCustomEvent>/*************************************************************************** qgspostgresprovider.h - Data provider for PostgreSQL/PostGIS layers ------------------- begin : Jan 2, 2004 copyright : (C) 2003 by Gary E.Sherman email : sherman at mrcc.com ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************//* $Id: qgspostgresprovider.h 8313 2008-04-02 22:35:33Z jef $ */#ifndef QGSPOSTGRESPROVIDER_H#define QGSPOSTGRESPROVIDER_Hextern "C"{#include <libpq-fe.h>}#include "qgsvectordataprovider.h"#include "qgsrect.h"#include <list>#include <queue>#include <fstream>#include <set>class QgsFeature;class QgsField;class QgsGeometry;#include "qgsdatasourceuri.h"#include "qgspostgrescountthread.h"#include "qgspostgresextentthread.h"/** \class QgsPostgresProvider \brief Data provider for PostgreSQL/PostGIS layers. This provider implements the interface defined in the QgsDataProvider class to provide access to spatial data residing in a PostgreSQL/PostGIS enabled database. */class QgsPostgresProvider:public QgsVectorDataProvider{ Q_OBJECT public: /** * Constructor for the provider. The uri must be in the following format: * host=localhost user=gsherman dbname=test password=xxx table=test.alaska (the_geom) * @param uri String containing the required parameters to connect to the database * and query the table. */ QgsPostgresProvider(QString const & uri = ""); //! Destructor virtual ~ QgsPostgresProvider(); /** * Returns the permanent storage type for this layer as a friendly name. */ virtual QString storageType() const; /*! Get the QgsSpatialRefSys for this layer * @note Must be reimplemented by each provider. * If the provider isn't capable of returning * its projection an empty srs will be return, ti will return 0 */ virtual QgsSpatialRefSys getSRS(); /** Select features based on a bounding rectangle. Features can be retrieved with calls to getNextFeature. * @param fetchAttributes list of attributes which should be fetched * @param rect spatial filter * @param fetchGeometry true if the feature geometry should be fetched * @param useIntersect true if an accurate intersection test should be used, * false if a test based on bounding box is sufficient */ virtual void select(QgsAttributeList fetchAttributes = QgsAttributeList(), QgsRect rect = QgsRect(), bool fetchGeometry = true, bool useIntersect = false); /** * Get the next feature resulting from a select operation. * @param feature feature which will receive data from the provider * @return true when there was a feature to fetch, false when end was hit */ virtual bool getNextFeature(QgsFeature& feature); /** * Gets the feature at the given feature ID. * @param featureId id of the feature * @param feature feature which will receive the data * @param fetchGeoemtry if true, geometry will be fetched from the provider * @param fetchAttributes a list containing the indexes of the attribute fields to copy * @return True when feature was found, otherwise false */ virtual bool getFeatureAtId(int featureId, QgsFeature& feature, bool fetchGeometry = true, QgsAttributeList fetchAttributes = QgsAttributeList()); /** Get the feature type. This corresponds to * WKBPoint, * WKBLineString, * WKBPolygon, * WKBMultiPoint, * WKBMultiLineString or * WKBMultiPolygon * as defined in qgis.h */ QGis::WKBTYPE geometryType() const; /** return the number of layers for the current data source @note Should this be subLayerCount() instead? */ size_t layerCount() const; /** * Get the number of features in the layer */ long featureCount() const; /** * Get the number of fields in the layer */ uint fieldCount() const; /** * Get the data source URI structure used by this layer */ QgsDataSourceURI& getURI(); /** * Return a string representation of the endian-ness for the layer */ QString endianString(); /** * Changes the stored extent for this layer to the supplied extent. * For example, this is called when the extent worker thread has a result. */ void setExtent( QgsRect& newExtent ); /** Return the extent for this data layer */ virtual QgsRect extent(); /** * Get the name of the primary key for the layer */ QString getPrimaryKey(); /** * Get the field information for the layer * @return vector of QgsField objects */ const QgsFieldMap & fields() const; /** * Return a short comment for the data that this provider is * providing access to (e.g. the comment for postgres table). */ QString dataComment() const; /** Reset the layer - for a PostgreSQL layer, this means clearing the PQresult * pointer, setting it to 0 and reloading the field list */ void reset(); /** Returns the minimum value of an attribute * @param index the index of the attribute */ QVariant minValue(int index); /** Returns the maximum value of an attribute * @param index the index of the attribute */ QVariant maxValue(int index); /** Return the unique values of an attribute * @param index the index of the attribute * @param values reference to the list of unique values */ virtual void getUniqueValues(int index, QStringList &uniqueValues); /**Returns true if layer is valid */ bool isValid(); QgsAttributeList allAttributesList(); //! get postgis version string QString postgisVersion(PGconn *); //! get status of GEOS capability bool hasGEOS(PGconn *); //! get status of GIST capability bool hasGIST(PGconn *); //! get status of PROJ4 capability bool hasPROJ(PGconn *); /**Returns the default value for field specified by @c fieldId */ QVariant getDefaultValue(int fieldId); /**Adds a list of features @return true in case of success and false in case of failure*/ bool addFeatures(QgsFeatureList & flist); /**Deletes a list of features @param id list of feature ids @return true in case of success and false in case of failure*/ bool deleteFeatures(const QgsFeatureIds & id); /**Adds new attributes @param name map with attribute name as key and type as value @return true in case of success and false in case of failure*/ bool addAttributes(const QgsNewAttributesMap & name); /**Deletes existing attributes @param names of the attributes to delete @return true in case of success and false in case of failure*/ bool deleteAttributes(const QgsAttributeIds & name); /**Changes attribute values of existing features @param attr_map a map containing the new attributes. The integer is the feature id, the first QString is the attribute name and the second one is the new attribute value @return true in case of success and false in case of failure*/ bool changeAttributeValues(const QgsChangedAttributesMap & attr_map); /** Changes geometries of existing features @param geometry_map A std::map containing the feature IDs to change the geometries of. the second map parameter being the new geometries themselves @return true in case of success and false in case of failure */ bool changeGeometryValues(QgsGeometryMap & geometry_map); //! Get the postgres connection PGconn * pgConnection(); //! Get the table name associated with this provider instance QString getTableName(); /** Accessor for sql where clause used to limit dataset */ QString subsetString(); /** mutator for sql where clause used to limit dataset size */ void setSubsetString(QString theSQL); /**Returns a bitmask containing the supported capabilities*/ int capabilities() const; /** The Postgres provider does its own transforms so we return * true for the following three functions to indicate that transforms * should not be handled by the QgsCoordinateTransform object. See the * documentation on QgsVectorDataProvider for details on these functions. */ // XXX For now we have disabled native transforms in the PG provider since // it appears there are problems with some of the projection definitions bool supportsNativeTransform(){return false;} /** return a provider name Essentially just returns the provider key. Should be used to build file dialogs so that providers can be shown with their supported types. Thus if more than one provider supports a given format, the user is able to select a specific provider to open that file. @note Instead of being pure virtual, might be better to generalize this behavior and presume that none of the sub-classes are going to do anything strange with regards to their name or description? */ QString name() const; /** return description Return a terse string describing what the provider is. @note Instead of being pure virtual, might be better to generalize this behavior and presume that none of the sub-classes are going to do anything strange with regards to their name or description? */ QString description() const; signals: /** * This is emitted whenever the worker thread has fully calculated the * PostGIS extents for this layer, and its event has been received by this
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -