Added QgsSpatialRefSys to maplayer and dataprovider interfaces

git-svn-id: http://svn.osgeo.org/qgis/trunk@3238 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
timlinux 2005-04-27 12:59:40 +00:00
parent 92cc893ba6
commit 04887a78ba
4 changed files with 352 additions and 289 deletions

View File

@ -101,10 +101,10 @@ if [ "$LT_ERROR" = "1" ]; then
fi
echo Configuring build environment for QGIS
aclocal \
aclocal-1.8 \
&& $LIBTOOLIZE --force --copy \
&& autoheader --force -W all \
&& automake --add-missing --foreign --copy \
&& automake-1.8 --add-missing --foreign --copy \
&& autoconf --force \
&& echo Now running configure to configure QGIS \
&& ./configure $@

View File

@ -34,7 +34,7 @@ class QgsRect;
class QgsFeature;
class QgsField;
class QgsDataSourceURI;
class QgsSpatialRefSys;
/** \class QgsDataProvider
* \brief Abstract base class for spatial data provider implementations
* @author Gary E.Sherman
@ -50,127 +50,150 @@ class QgsDataSourceURI;
class QgsDataProvider : public QObject {
Q_OBJECT
Q_OBJECT
public:
/**
* We need this so the subclass destructors get called
*/
virtual ~QgsDataProvider() {};
public:
/**
* We need this so the subclass destructors get called
*/
virtual ~QgsDataProvider() {};
/** Used to ask the layer for its projection as a WKT string. Must be reimplemented by each provider. */
virtual QString getProjectionWKT() = 0 ;
/**
* Set the data source specification. This may be a path or database
* connection string
* @param data source specification
*/
virtual void setDataSourceUri(QString uri) = 0;
/**
* Get the data source specification. This may be a path or database
* connection string
* @return data source specification
*/
virtual QString getDataSourceUri() = 0;
/*! Set the QgsSpatialReferenceSystem for this layer..
* @note Must be reimplemented by each provider.
* @param theSRS QgsSpatialRefSys to be assigned to this layer
* A complete copy of the passed in SRS will be made.
*/
virtual void setSRS(QgsSpatialRefSys * theSRS){};
virtual QgsDataSourceURI * getURI()=0;
/**
* Get the extent of the layer
* @return QgsRect containing the extent of the layer
*/
virtual QgsRect * extent() = 0;
/**
* Identify features within the search radius specified by rect
* @param rect Bounding rectangle of search radius
* @return std::vector containing QgsFeature objects that intersect rect
*/
//virtual std::vector<QgsFeature>& QgsDataProvider::identify(QgsRect *rect)=0;
/*! 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(){return 0;};
/** type for byte order
XDR is for network byte order, or big-endian
NDR is for little-endian systems
/** Used to ask the layer for its projection as a WKT string.
*
* Must be reimplemented by each provider.
*
* @note XXXXX WARNING THIS METHOD WILL BE DEPRECATED
* XXXXX in favour of SpatialRefSys accessors
* XXXXX and mutators!
*
*/
virtual QString getProjectionWKT() = 0 ;
@note that default values were taken from similarly named WKB types
*/
typedef enum
{
XDR = 0, // network byte order (big-endian)
NDR = 1 // little endian
} endian_t;
/**
* Set the data source specification. This may be a path or database
* connection string
* @param data source specification
*/
virtual void setDataSourceUri(QString uri) = 0;
/**
Return the endian of this layer.
/**
* Get the data source specification. This may be a path or database
* connection string
* @return data source specification
*/
virtual QString getDataSourceUri() = 0;
XDR for network, or big-endian, byte order
NDR for little-endian byte order
virtual QgsDataSourceURI * getURI()=0;
/**
* Get the extent of the layer
* @return QgsRect containing the extent of the layer
*/
virtual QgsRect * extent() = 0;
@note
/**
* Identify features within the search radius specified by rect
* @param rect Bounding rectangle of search radius
* @return std::vector containing QgsFeature objects that intersect rect
*/
//virtual std::vector<QgsFeature>& QgsDataProvider::identify(QgsRect *rect)=0;
By default this returns the endian-ness of the current platform.
Sub-classes are free to over-ride this to perhaps return endian-ness of
data as stored persistently instead of local hardware architecture
endian-ness.
*/
virtual endian_t endian()
{
return (htonl(1) == 1) ? XDR : NDR;
}
/** type for byte order
/**
* Returns true if this is a valid layer. It is up to individual providers
* to determine what constitutes a valid layer
*/
virtual bool isValid()=0;
XDR is for network byte order, or big-endian
NDR is for little-endian systems
/* Reset the layer - for an OGRLayer, this means clearing the
* spatial filter and calling ResetReading
*/
virtual void reset()
{
// NOP by default
}
@note that default values were taken from similarly named WKB types
*/
typedef enum
{
XDR = 0, // network byte order (big-endian)
NDR = 1 // little endian
} endian_t;
/**
* Update the extents of the layer. Not implemented by default
*/
virtual void updateExtents()
{
// NOP by default
}
/**
* Set the subset string used to create a subset of features in
* the layer. This may be a sql where clause or any other string
* that can be used by the data provider to create a subset.
* Must be implemented in the dataprovider.
*/
virtual void setSubsetString(QString subset)
{
// NOP by default
}
/**
* Returns the subset definition string (typically sql) currently in
* use by the layer and used by the provider to limit the feature set.
* Must be overridden in the dataprovider, otherwise returns a null
* QString.
*/
virtual QString subsetString()
{
return QString::null;
}
/**
Return the endian of this layer.
XDR for network, or big-endian, byte order
NDR for little-endian byte order
@note
By default this returns the endian-ness of the current platform.
Sub-classes are free to over-ride this to perhaps return endian-ness of
data as stored persistently instead of local hardware architecture
endian-ness.
*/
virtual endian_t endian()
{
return (htonl(1) == 1) ? XDR : NDR;
}
/**
* Returns true if this is a valid layer. It is up to individual providers
* to determine what constitutes a valid layer
*/
virtual bool isValid()=0;
/* Reset the layer - for an OGRLayer, this means clearing the
* spatial filter and calling ResetReading
*/
virtual void reset()
{
// NOP by default
}
/**
* Update the extents of the layer. Not implemented by default
*/
virtual void updateExtents()
{
// NOP by default
}
/**
* Set the subset string used to create a subset of features in
* the layer. This may be a sql where clause or any other string
* that can be used by the data provider to create a subset.
* Must be implemented in the dataprovider.
*/
virtual void setSubsetString(QString subset)
{
// NOP by default
}
/**
* Returns the subset definition string (typically sql) currently in
* use by the layer and used by the provider to limit the feature set.
* Must be overridden in the dataprovider, otherwise returns a null
* QString.
*/
virtual QString subsetString()
{
return QString::null;
}
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
* provider.
*/
virtual void fullExtentCalculated();
/**
* This is emitted whenever the worker thread has fully calculated the
* PostGIS extents for this layer, and its event has been received by this
* provider.
*/
virtual void fullExtentCalculated();
};

View File

@ -423,6 +423,11 @@ protected:
//! A QgsCoordinateTransform is used for on the fly reprojection of map layers
QgsCoordinateTransform * mCoordinateTransform;
/** The QgsSpatialRefSys that represents the spatial ref sys for this
* layer.
* @note it will also be used to set the sourceSRS in the above coord transform object
*/
QgsSpatialRefSys * mSpatialRefSys;
private: // Private attributes
/// QgsMapLayer not copyable

View File

@ -16,223 +16,258 @@
#ifndef QGSVECTORDATAPROVIDER_H
#define QGSVECTORDATAPROVIDER_H
//Qt includes
#include <set>
#include <map>
#include <qobject.h>
#include <qgsdataprovider.h>
#include <qtextcodec.h>
//QGIS Includes
#include <qgsdataprovider.h>
#include <qgsspatialrefsys.h>
/** Base class for vector data providers
*/
class QgsVectorDataProvider : public QgsDataProvider
{
Q_OBJECT
public:
enum Capability
{
NoCapabilities = 0,
AddFeatures = 1,
DeleteFeatures = 1 << 1,
ChangeAttributeValues = 1 << 2,
AddAttributes = 1 << 3,
DeleteAttributes = 1 << 4,
SaveAsShapefile = 1 << 5
};
Q_OBJECT
QgsVectorDataProvider();
public:
virtual ~QgsVectorDataProvider() {};
/**
* Select features based on a bounding rectangle. Features can be retrieved
* with calls to getFirstFeature and getNextFeature. Request for features
* for use in drawing the map canvas should set useIntersect to false.
* @param mbr QgsRect containing the extent to use in selecting features
* @param useIntersect If true, use the intersects function to select features
* rather than the PostGIS && operator that selects based on bounding box
* overlap.
*
*/
virtual void select(QgsRect *mbr, bool useIntersect=false)=0;
/**
* Update the feature count based on current spatial filter. If not
* overridden in the data provider this function returns -1
*/
virtual long updateFeatureCount()
{
return -1;
}
/**
* Get the first feature resulting from a select operation
* @return QgsFeature
*/
virtual QgsFeature * getFirstFeature(bool fetchAttributes = false) = 0;
enum Capability
{
NoCapabilities = 0,
AddFeatures = 1,
DeleteFeatures = 1 << 1,
ChangeAttributeValues = 1 << 2,
AddAttributes = 1 << 3,
DeleteAttributes = 1 << 4,
SaveAsShapefile = 1 << 5
};
/**
* Get the next feature resutling from a select operation
* @return QgsFeature
*/
virtual QgsFeature * getNextFeature(bool fetchAttributes = false) = 0;
QgsVectorDataProvider();
/**Get the next feature resulting from a select operation.
*@param attlist a list containing the indexes of the attribute fields to copy
*@param getnotcommited flag indicating if not commited features should be returned
*/
virtual QgsFeature * getNextFeature(std::list<int> const & attlist) = 0;
virtual ~QgsVectorDataProvider() {};
/**
* Select features based on a bounding rectangle. Features can be retrieved
* with calls to getFirstFeature and getNextFeature. Request for features
* for use in drawing the map canvas should set useIntersect to false.
* @param mbr QgsRect containing the extent to use in selecting features
* @param useIntersect If true, use the intersects function to select features
* rather than the PostGIS && operator that selects based on bounding box
* overlap.
*
*/
virtual void select(QgsRect *mbr, bool useIntersect=false)=0;
/**
* Update the feature count based on current spatial filter. If not
* overridden in the data provider this function returns -1
*/
virtual long updateFeatureCount()
{
return -1;
}
/**
* Get the first feature resulting from a select operation
* @return QgsFeature
*/
virtual QgsFeature * getFirstFeature(bool fetchAttributes = false) = 0;
/**
* Get the next feature using new method
* TODO - make this pure virtual once it works and change existing providers
* to use this method of fetching features
*/
/**
* Get the next feature resutling from a select operation
* @return QgsFeature
*/
virtual QgsFeature * getNextFeature(bool fetchAttributes = false) = 0;
virtual bool getNextFeature(QgsFeature &feature, bool fetchAttributes = false) = 0;
/**Get the next feature resulting from a select operation.
*@param attlist a list containing the indexes of the attribute fields to copy
*@param getnotcommited flag indicating if not commited features should be returned
*/
virtual QgsFeature * getNextFeature(std::list<int> const & attlist) = 0;
/** Get feature type.
* Gets the feature type as defined in WKBTYPE (qgis.h).
* @return int representing the feature type
*/
virtual int geometryType() const = 0;
/**
* Get the next feature using new method
* TODO - make this pure virtual once it works and change existing providers
* to use this method of fetching features
*/
/**
* Number of features in the layer
* @return long containing number of features
*/
virtual long featureCount() const = 0;
virtual bool getNextFeature(QgsFeature &feature, bool fetchAttributes = false) = 0;
/**
* Number of attribute fields for a feature in the layer
*/
virtual int fieldCount() const = 0;
/** Get feature type.
* Gets the feature type as defined in WKBTYPE (qgis.h).
* @return int representing the feature type
*/
virtual int geometryType() const = 0;
/**
* Return a list of field names for this layer
* @return vector of field names
*/
virtual std::vector<QgsField> const & fields() const = 0;
/**
* Number of features in the layer
* @return long containing number of features
*/
virtual long featureCount() const = 0;
/**
* Reset the layer to clear any spatial filtering or other contstraints that
* would prevent the entire record set from being traversed by call to
* getNextFeature(). Some data stores may not require any special action to
* reset the layer. In this case, the provider should simply implement an empty
* function body.
*/
virtual void reset() = 0;
/**
* Number of attribute fields for a feature in the layer
*/
virtual int fieldCount() const = 0;
/**Returns the minimum value of an attributs
@param position the number of the attribute*/
virtual QString minValue(int position) = 0;
/**
* Return a list of field names for this layer
* @return vector of field names
*/
virtual std::vector<QgsField> const & fields() const = 0;
/**Returns the maximum value of an attributs
@param position the number of the attribute*/
virtual QString maxValue(int position) = 0;
/**
* Reset the layer to clear any spatial filtering or other contstraints that
* would prevent the entire record set from being traversed by call to
* getNextFeature(). Some data stores may not require any special action to
* reset the layer. In this case, the provider should simply implement an empty
* function body.
*/
virtual void reset() = 0;
/**Adds a list of features
@return true in case of success and false in case of failure*/
virtual bool addFeatures(std::list<QgsFeature*> const flist);
/**Returns the minimum value of an attributs
@param position the number of the attribute*/
virtual QString minValue(int position) = 0;
/**Deletes a feature
@param id list containing feature ids to delete
@return true in case of success and false in case of failure*/
virtual bool deleteFeatures(std::list<int> const & id);
/**Returns the maximum value of an attributs
@param position the number of the attribute*/
virtual QString maxValue(int position) = 0;
/**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*/
virtual bool addAttributes(std::map<QString,QString> const & name);
/**Adds a list of features
@return true in case of success and false in case of failure*/
virtual bool addFeatures(std::list<QgsFeature*> const flist);
/**Deletes existing attributes
@param names of the attributes to delete
@return true in case of success and false in case of failure*/
virtual bool deleteAttributes(std::set<QString> const & name);
/**Deletes a feature
@param id list containing feature ids to delete
@return true in case of success and false in case of failure*/
virtual bool deleteFeatures(std::list<int> const & id);
/**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*/
virtual bool changeAttributeValues(std::map<int,std::map<QString,QString> > const & attr_map);
/**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*/
virtual bool addAttributes(std::map<QString,QString> const & name);
/**Returns the default value for attribute @c attr for feature @c f. */
virtual QString getDefaultValue(const QString & attr, QgsFeature* f);
/**
* Identify features within the search radius specified by rect
* @param rect Bounding rectangle of search radius
* @return std::vector containing QgsFeature objects that intersect rect
*/
virtual std::vector<QgsFeature>& identify(QgsRect *rect) = 0;
/**Deletes existing attributes
@param names of the attributes to delete
@return true in case of success and false in case of failure*/
virtual bool deleteAttributes(std::set<QString> const & name);
/** saves current data as Shape file, if it can */
virtual bool saveAsShapefile()
{
/**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*/
virtual bool changeAttributeValues(std::map<int,std::map<QString,QString> > const & attr_map);
/**Returns the default value for attribute @c attr for feature @c f. */
virtual QString getDefaultValue(const QString & attr, QgsFeature* f);
/**
* Identify features within the search radius specified by rect
* @param rect Bounding rectangle of search radius
* @return std::vector containing QgsFeature objects that intersect rect
*/
virtual std::vector<QgsFeature>& identify(QgsRect *rect) = 0;
/** saves current data as Shape file, if it can */
virtual bool saveAsShapefile()
{
// NOP by default
}
}
/**Returns a bitmask containing the supported capabilities*/
virtual int capabilities() const {return QgsVectorDataProvider::NoCapabilities;}
/**Returns a bitmask containing the supported capabilities*/
virtual int capabilities() const {return QgsVectorDataProvider::NoCapabilities;}
const std::list<QString>& nonNumericalTypes(){return mNonNumericalTypes;}
const std::list<QString>& numericalTypes(){return mNumericalTypes;}
const std::list<QString>& nonNumericalTypes(){return mNonNumericalTypes;}
const std::list<QString>& numericalTypes(){return mNumericalTypes;}
void setEncoding(const QString& e);
QString encoding() const;
void setEncoding(const QString& e);
QString encoding() const;
/*! Indicates if the provider does its own coordinate transforms
* @return true if the provider transforms its coordinates, otherwise false
*/
virtual bool supportsNativeTransform(){return false;};
/*! Used to determine if the provider supports transformation using the
* SRID of the target SRS.
* @return true if SRID is used, otherwise false
*/
virtual bool usesSrid(){return false;};
/*! Used to determine if the provider supports transformation using the
* WKT of the target SRS.
* @return true if WKT is used, otherwise false
*/
virtual bool usesWKT(){return false;};
/*! Set the SRID of the target SRS.
* This is only implemented if the provider supports native
* transformation of its coordinates
* @param srid Spatial reference id of the target (map canvas)
*/
virtual void setSrid(int srid){};
/*! Get the SRID of the target SRS
* If the provider isn't capable of reporting the SRID of
* the projection, ti will return 0
*/
virtual int getSrid(){return 0;};
/*! Set the WKT of the target SRS.
* This is only implemented if the provider supports native
* transformation of its coordinates
*
* @param wkt Well known text of the target (map canvas) SRS
*/
virtual void setWKT(QString wkt){};
/*! Indicates if the provider does its own coordinate transforms
* @return true if the provider transforms its coordinates, otherwise false
*/
virtual bool supportsNativeTransform(){return false;};
/*! Used to determine if the provider supports transformation using the
* SRID of the target SRS.
*
* @note XXXXX WARNING THIS METHOD WILL BE DEPRECATED
* XXXXX in favour of SpatialRefSys accessors
* XXXXX and mutators!
*
* @return true if SRID is used, otherwise false
*/
virtual bool usesSrid(){return false;};
/*! Used to determine if the provider supports transformation using the
* WKT of the target SRS.
*
* @note XXXXX WARNING THIS METHOD WILL BE DEPRECATED
* XXXXX in favour of SpatialRefSys accessors
* XXXXX and mutators!
*
* @return true if WKT is used, otherwise false
*/
virtual bool usesWKT(){return false;};
/*! Set the SRID of the target SRS.
* This is only implemented if the provider supports native
* transformation of its coordinates
*
* @note XXXXX WARNING THIS METHOD WILL BE DEPRECATED
* XXXXX in favour of SpatialRefSys accessors
* XXXXX and mutators!
*
* @param srid Spatial reference id of the target (map canvas)
*/
virtual void setSrid(int srid){};
/*! Get the SRID of the target SRS
* If the provider isn't capable of reporting the SRID of
* the projection, ti will return 0
*
* @note XXXXX WARNING THIS METHOD WILL BE DEPRECATED
* XXXXX in favour of SpatialRefSys accessors
* XXXXX and mutators!
*
*/
virtual int getSrid(){return 0;};
/*! Set the WKT of the target SRS.
* This is only implemented if the provider supports native
* transformation of its coordinates
*
* @note XXXXX WARNING THIS METHOD WILL BE DEPRECATED
* XXXXX in favour of SpatialRefSys accessors
* XXXXX and mutators!
*
* @param wkt Well known text of the target (map canvas) SRS
*/
virtual void setWKT(QString wkt){};
protected:
/**Encoding*/
QTextCodec* mEncoding;
/**List of type names for non-numerical types*/
std::list<QString> mNonNumericalTypes;
/**List of type names for numerical types*/
std::list<QString> mNumericalTypes;
/** The spatial reference id of the map canvas. This is the
* SRID the provider should transform its coordinates to if
* supportsNativeTransform is true. Otherwise this member is unused.
*/
int mTargetSrid;
/** The WKT of the SRS of the map canvas. This is the
* SRS the provider should transform its coordinates to if
* supportsNativeTransform is true. Otherwise this member is unused.
* The provider may choose to support transformation using SRID or WKT.
*/
int mTargetWKT;
protected:
/**Encoding*/
QTextCodec* mEncoding;
/**List of type names for non-numerical types*/
std::list<QString> mNonNumericalTypes;
/**List of type names for numerical types*/
std::list<QString> mNumericalTypes;
/** The spatial reference id of the map canvas. This is the
* SRID the provider should transform its coordinates to if
* supportsNativeTransform is true. Otherwise this member is unused.
*
* @note XXXXX WARNING THIS MEMBER WILL BE DEPRECATED
* XXXXX in favour of SpatialRefSys accessors
* XXXXX and mutators!
*
*/
int mTargetSrid;
/** The WKT of the SRS of the map canvas. This is the
* SRS the provider should transform its coordinates to if
* supportsNativeTransform is true. Otherwise this member is unused.
* The provider may choose to support transformation using SRID or WKT.
*
* @note XXXXX WARNING THIS MEMBER WILL BE DEPRECATED
* XXXXX in favour of SpatialRefSys accessors
* XXXXX and mutators!
*
*/
};
#endif