Skip to content

Commit

Permalink
Merged provider0_9-branch (r6844:6878) back to trunk.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6879 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Apr 11, 2007
1 parent 0a93d83 commit 5f75c23
Show file tree
Hide file tree
Showing 55 changed files with 2,072 additions and 2,672 deletions.
1 change: 1 addition & 0 deletions python/core/core.sip
Expand Up @@ -49,5 +49,6 @@
%Include qgssymbologyutils.sip
%Include qgsuniquevaluerenderer.sip
%Include qgsvectordataprovider.sip
%Include qgsvectorfilewriter.sip
%Include qgsvectorlayer.sip

9 changes: 0 additions & 9 deletions python/core/qgsdataprovider.sip
Expand Up @@ -15,15 +15,6 @@ class QgsDataProvider : QObject
*/
virtual ~QgsDataProvider();

/**
* 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(const QgsSpatialRefSys& theSRS) = 0;

/*! Get the QgsSpatialRefSys for this layer
* @note Must be reimplemented by each provider.
* If the provider isn't capable of returning
Expand Down
6 changes: 5 additions & 1 deletion python/core/qgsfeature.sip
Expand Up @@ -112,12 +112,16 @@ class QgsFeature
*/
void setGeometry(QgsGeometry& geom);

/** Set this feature's geometry (takes geometry ownership)
*/
void setGeometry(QgsGeometry* geom);

/**
* Set this feature's geometry from WKB
*
* This feature assumes responsibility for destroying geom.
*/
void setGeometryAndOwnership(unsigned char * geom, size_t length);
void setGeometryAndOwnership(unsigned char * geom /Transfer/, size_t length);


}; // class QgsFeature
Expand Down
49 changes: 28 additions & 21 deletions python/core/qgsgeometry.sip
Expand Up @@ -188,6 +188,15 @@ class QgsGeometry
/** static method that creates geometry from WKT */
static QgsGeometry* fromWkt(QString wkt) /Factory/;

/** construct geometry from a point */
static QgsGeometry* fromPoint(const QgsPoint& point) /Factory/;
/** construct geometry from a polyline */
static QgsGeometry* fromPolyline(const QgsPolyline& polyline) /Factory/;
/** construct geometry from a polygon */
static QgsGeometry* fromPolygon(const QgsPolygon& polygon) /Factory/;
/** construct geometry from a rectangle */
static QgsGeometry* fromRect(const QgsRect& rect) /Factory/;

typedef unsigned int size_t;


Expand All @@ -203,26 +212,21 @@ class QgsGeometry
Returns the buffer containing this geometry in WKB format.
You may wish to use in conjunction with wkbSize().
*/
unsigned char * wkbBuffer() const;
unsigned char * wkbBuffer();

/**
Returns the size of the WKB in wkbBuffer().
*/
size_t wkbSize() const;
size_t wkbSize();

/**
Returns the QString containing this geometry in WKT format.
*/
const QString & wkt() const;

/** Returns type of wkb (point / linestring / polygon etc.) */
QGis::WKBTYPE wkbType() const;
QGis::WKBTYPE wkbType();

/** Returns type of the vector */
QGis::VectorType vectorType() const;
QGis::VectorType vectorType();

/** Returns true if wkb of the geometry is of WKBMulti* type */
bool isMultipart() const;
bool isMultipart();

/**
Set the geometry, feeding in a geometry in GEOS format.
Expand All @@ -236,7 +240,7 @@ class QgsGeometry
Returns the vertex closest to the given point
(and also vertex index, squared distance and indexes of the vertices before/after)
*/
QgsPoint closestVertex(const QgsPoint& point, QgsGeometryVertexIndex& atVertex, int& beforeVertex, int& afterVertex, double& sqrDist) const;
QgsPoint closestVertex(const QgsPoint& point, QgsGeometryVertexIndex& atVertex, int& beforeVertex, int& afterVertex, double& sqrDist);


/**
Expand All @@ -251,7 +255,7 @@ class QgsGeometry
account the first vertex is equal to the last vertex (and will
skip equal vertex positions).
*/
void adjacentVerticies(const QgsGeometryVertexIndex& atVertex, int& beforeVertex, int& afterVertex) const;
void adjacentVerticies(const QgsGeometryVertexIndex& atVertex, int& beforeVertex, int& afterVertex);


/** Insert a new vertex before the given vertex index,
Expand Down Expand Up @@ -294,7 +298,7 @@ class QgsGeometry

*/
double sqrDistToVertexAt(QgsPoint& point,
QgsGeometryVertexIndex& atVertex) const;
QgsGeometryVertexIndex& atVertex);

/**
* Modifies x and y to indicate the location of
Expand All @@ -307,7 +311,7 @@ class QgsGeometry
*
* If FALSE, x and y are not modified.
*/
bool vertexAt(double &x, double &y, QgsGeometryVertexIndex atVertex) const;
bool vertexAt(double &x, double &y, QgsGeometryVertexIndex atVertex);

/**
Returns, in atVertex, the closest vertex in this geometry to the given point.
Expand All @@ -326,21 +330,24 @@ class QgsGeometry
double& sqrDist);

/**Returns the bounding box of this feature*/
QgsRect boundingBox() const;
QgsRect boundingBox();

/**Test for intersection with a rectangle (uses GEOS)*/
bool intersects(const QgsRect& r) const;

/**Also tests for intersection, but uses direct geos export of QgsGeometry instead wkb export and geos wkb import. Therefore this method is faster and could replace QgsGeometry::intersects in the future*/
bool fast_intersects(const QgsRect& r) const;
/** Test for intersection with a rectangle (uses GEOS) */
bool intersects(const QgsRect& r);
/** Test for intersection with a geoemetry (uses GEOS) */
bool intersects(QgsGeometry* geometry);

/** Test for containment of a point (uses GEOS) */
bool contains(QgsPoint* p) const;
bool contains(QgsPoint* p);

/**Creates a geos geometry from this features geometry. Note, that the returned object needs to be deleted*/
// TODO: unsupported class... would be possible to use PyGEOS?
//geos::Geometry* geosGeometry() const;

/** Exports the geometry to mWkt
@return true in case of success and false else
*/
QString exportToWkt();

/* Accessor functions for getting geometry data */

Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsspatialrefsys.sip
Expand Up @@ -172,7 +172,7 @@ class QgsSpatialRefSys
/*! A helper to get an wkt representation of this srs
* @return string containing Wkt of the srs
*/
QString toWkt();
QString toWkt() const;

/*! Restores state from the given DOM node.
* @param theNode The node from which state will be restored
Expand Down
75 changes: 34 additions & 41 deletions python/core/qgsvectordataprovider.sip
Expand Up @@ -48,6 +48,7 @@

};


template<TYPE>
%MappedType QMap<int, QMap<int, TYPE> >
{
Expand Down Expand Up @@ -208,17 +209,17 @@ class QgsVectorDataProvider : QgsDataProvider
*/
virtual QString storageType() const;

/**
* 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.
*
/** 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(QgsRect mbr, bool useIntersect = false) = 0;
virtual void select(QList<int> fetchAttributes = QList<int>(),
QgsRect rect = QgsRect(),
bool fetchGeometry = true,
bool useIntersect = false) = 0;

/**
* Update the feature count based on current spatial filter. If not
Expand All @@ -242,15 +243,9 @@ class QgsVectorDataProvider : QgsDataProvider
/**
* Get the next feature resulting from a select operation.
* @param feature feature which will receive data from the provider
* @param fetchGeoemtry if true, geometry will be fetched from the provider
* @param fetchAttributes a list containing the indexes of the attribute fields to copy
* @param featureQueueSize a hint to the provider as to how many features are likely to be retrieved in a batch
* @return true when there was a feature to fetch, false when end was hit
*/
virtual bool getNextFeature(QgsFeature& feature,
bool fetchGeometry = true,
QList<int> fetchAttributes = QList<int>(),
uint featureQueueSize = 1) = 0;
virtual bool getNextFeature(QgsFeature& feature) = 0;

/**
* Get feature type.
Expand All @@ -265,20 +260,6 @@ class QgsVectorDataProvider : QgsDataProvider
*/
virtual long featureCount() const = 0;

/**
* Get the attributes associated with a feature
* TODO: Get rid of "row" and set up provider-internal caching instead
*/
virtual void getFeatureAttributes(int key, int& row, QgsFeature *f);

/**
* Fetch geometry for a particular feature with id "key",
* modifies "f" in-place.
*
* This function is enabled if capabilities() returns "SelectGeometryAtId".
*/
virtual void getFeatureGeometry(int key, QgsFeature *f);

/**
* Number of attribute fields for a feature in the layer
*/
Expand All @@ -290,26 +271,34 @@ class QgsVectorDataProvider : QgsDataProvider
*/
virtual const QMap<int, QgsField> & fields() 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.
/**
* Return a short comment for the data that this provider is
* providing access to (e.g. the comment for postgres table).
*/
virtual QString dataComment() const;

/** Restart reading features from previous select operation */
virtual void reset() = 0;

/**
* Returns the minimum value of an attributs
* @param position the number of the attribute
* @param index the index of the attribute
*
* Default implementation walks all numeric attributes and caches minimal
* and maximal values. If provider has facilities to retreive minimal
* value directly, override this function.
*/
virtual QString minValue(uint position) = 0;
virtual QVariant minValue(int index);

/**
* Returns the maximum value of an attributs
* @param position the number of the attribute
* @param index the index of the attribute
*
* Default implementation walks all numeric attributes and caches minimal
* and maximal values. If provider has facilities to retreive maximal
* value directly, override this function.
*/
virtual QString maxValue(uint position) = 0;
virtual QVariant maxValue(int index);

/**
* Adds a list of features
Expand Down Expand Up @@ -396,6 +385,10 @@ class QgsVectorDataProvider : QgsDataProvider
*/
QList<int> allAttributesList();

/**Returns the names of the numerical types*/
// TODO: wrap, must wrap QSet<TYPE> first
//const QSet<QString>& supportedNativeTypes() const;

/**
* Set whether provider should return also features that don't have
* associated geometry. FALSE by default
Expand Down
50 changes: 50 additions & 0 deletions python/core/qgsvectorfilewriter.sip
@@ -0,0 +1,50 @@

/**
There are two possibilities how to use this class:
1. static call to QgsVectorFileWriter::writeAsShapefile(...) which saves the whole vector layer
2. create an instance of the class and issue calls to addFeature(...)

Currently supports only writing to shapefiles, but shouldn't be a problem to add capability
to support other OGR-writable formats.
*/
class QgsVectorFileWriter
{
%TypeHeaderCode
#include <qgsvectorfilewriter.h>
#include <qgsfield.h>
%End

public:

enum WriterError
{
NoError = 0,
ErrDriverNotFound,
ErrCreateDataSource,
ErrCreateLayer
};

/** Write contents of vector layer to a shapefile */
static WriterError writeAsShapefile(QgsVectorLayer* layer,
const QString& shapefileName,
const QString& fileEncoding);


/** create shapefile and initialize it */
QgsVectorFileWriter(const QString& shapefileName,
const QString& fileEncoding,
const QMap<int, QgsField>& fields,
QGis::WKBTYPE geometryType,
const QgsSpatialRefSys* srs);

/** checks whether there were any errors in constructor */
WriterError hasError();

/** add feature to the currently opened shapefile */
bool addFeature(QgsFeature& feature);

/** close opened shapefile for writing */
~QgsVectorFileWriter();

};

0 comments on commit 5f75c23

Please sign in to comment.