Skip to content

Commit 5f75c23

Browse files
author
wonder
committed
Merged provider0_9-branch (r6844:6878) back to trunk.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6879 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 0a93d83 commit 5f75c23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2072
-2672
lines changed

python/core/core.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@
4949
%Include qgssymbologyutils.sip
5050
%Include qgsuniquevaluerenderer.sip
5151
%Include qgsvectordataprovider.sip
52+
%Include qgsvectorfilewriter.sip
5253
%Include qgsvectorlayer.sip
5354

python/core/qgsdataprovider.sip

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ class QgsDataProvider : QObject
1515
*/
1616
virtual ~QgsDataProvider();
1717

18-
/**
19-
* Set the QgsSpatialReferenceSystem for this layer.
20-
* @note Must be reimplemented by each provider.
21-
*
22-
* @param theSRS QgsSpatialRefSys to be assigned to this layer
23-
* A complete copy of the passed in SRS will be made.
24-
*/
25-
virtual void setSRS(const QgsSpatialRefSys& theSRS) = 0;
26-
2718
/*! Get the QgsSpatialRefSys for this layer
2819
* @note Must be reimplemented by each provider.
2920
* If the provider isn't capable of returning

python/core/qgsfeature.sip

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,16 @@ class QgsFeature
112112
*/
113113
void setGeometry(QgsGeometry& geom);
114114

115+
/** Set this feature's geometry (takes geometry ownership)
116+
*/
117+
void setGeometry(QgsGeometry* geom);
118+
115119
/**
116120
* Set this feature's geometry from WKB
117121
*
118122
* This feature assumes responsibility for destroying geom.
119123
*/
120-
void setGeometryAndOwnership(unsigned char * geom, size_t length);
124+
void setGeometryAndOwnership(unsigned char * geom /Transfer/, size_t length);
121125

122126

123127
}; // class QgsFeature

python/core/qgsgeometry.sip

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ class QgsGeometry
188188
/** static method that creates geometry from WKT */
189189
static QgsGeometry* fromWkt(QString wkt) /Factory/;
190190

191+
/** construct geometry from a point */
192+
static QgsGeometry* fromPoint(const QgsPoint& point) /Factory/;
193+
/** construct geometry from a polyline */
194+
static QgsGeometry* fromPolyline(const QgsPolyline& polyline) /Factory/;
195+
/** construct geometry from a polygon */
196+
static QgsGeometry* fromPolygon(const QgsPolygon& polygon) /Factory/;
197+
/** construct geometry from a rectangle */
198+
static QgsGeometry* fromRect(const QgsRect& rect) /Factory/;
199+
191200
typedef unsigned int size_t;
192201

193202

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

208217
/**
209218
Returns the size of the WKB in wkbBuffer().
210219
*/
211-
size_t wkbSize() const;
220+
size_t wkbSize();
212221

213-
/**
214-
Returns the QString containing this geometry in WKT format.
215-
*/
216-
const QString & wkt() const;
217-
218222
/** Returns type of wkb (point / linestring / polygon etc.) */
219-
QGis::WKBTYPE wkbType() const;
223+
QGis::WKBTYPE wkbType();
220224

221225
/** Returns type of the vector */
222-
QGis::VectorType vectorType() const;
226+
QGis::VectorType vectorType();
223227

224228
/** Returns true if wkb of the geometry is of WKBMulti* type */
225-
bool isMultipart() const;
229+
bool isMultipart();
226230

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

241245

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

256260

257261
/** Insert a new vertex before the given vertex index,
@@ -294,7 +298,7 @@ class QgsGeometry
294298

295299
*/
296300
double sqrDistToVertexAt(QgsPoint& point,
297-
QgsGeometryVertexIndex& atVertex) const;
301+
QgsGeometryVertexIndex& atVertex);
298302

299303
/**
300304
* Modifies x and y to indicate the location of
@@ -307,7 +311,7 @@ class QgsGeometry
307311
*
308312
* If FALSE, x and y are not modified.
309313
*/
310-
bool vertexAt(double &x, double &y, QgsGeometryVertexIndex atVertex) const;
314+
bool vertexAt(double &x, double &y, QgsGeometryVertexIndex atVertex);
311315

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

328332
/**Returns the bounding box of this feature*/
329-
QgsRect boundingBox() const;
333+
QgsRect boundingBox();
330334

331-
/**Test for intersection with a rectangle (uses GEOS)*/
332-
bool intersects(const QgsRect& r) const;
333-
334-
/**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*/
335-
bool fast_intersects(const QgsRect& r) const;
335+
/** Test for intersection with a rectangle (uses GEOS) */
336+
bool intersects(const QgsRect& r);
337+
/** Test for intersection with a geoemetry (uses GEOS) */
338+
bool intersects(QgsGeometry* geometry);
336339

337340
/** Test for containment of a point (uses GEOS) */
338-
bool contains(QgsPoint* p) const;
341+
bool contains(QgsPoint* p);
339342

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

347+
/** Exports the geometry to mWkt
348+
@return true in case of success and false else
349+
*/
350+
QString exportToWkt();
344351

345352
/* Accessor functions for getting geometry data */
346353

python/core/qgsspatialrefsys.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class QgsSpatialRefSys
172172
/*! A helper to get an wkt representation of this srs
173173
* @return string containing Wkt of the srs
174174
*/
175-
QString toWkt();
175+
QString toWkt() const;
176176

177177
/*! Restores state from the given DOM node.
178178
* @param theNode The node from which state will be restored

python/core/qgsvectordataprovider.sip

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
};
5050

51+
5152
template<TYPE>
5253
%MappedType QMap<int, QMap<int, TYPE> >
5354
{
@@ -208,17 +209,17 @@ class QgsVectorDataProvider : QgsDataProvider
208209
*/
209210
virtual QString storageType() const;
210211

211-
/**
212-
* Select features based on a bounding rectangle. Features can be retrieved
213-
* with calls to getFirstFeature and getNextFeature. Request for features
214-
* for use in drawing the map canvas should set useIntersect to false.
215-
* @param mbr QgsRect containing the extent to use in selecting features
216-
* @param useIntersect If true, use the intersects function to select features
217-
* rather than the PostGIS && operator that selects based on bounding box
218-
* overlap.
219-
*
212+
/** Select features based on a bounding rectangle. Features can be retrieved with calls to getNextFeature.
213+
* @param fetchAttributes list of attributes which should be fetched
214+
* @param rect spatial filter
215+
* @param fetchGeometry true if the feature geometry should be fetched
216+
* @param useIntersect true if an accurate intersection test should be used,
217+
* false if a test based on bounding box is sufficient
220218
*/
221-
virtual void select(QgsRect mbr, bool useIntersect = false) = 0;
219+
virtual void select(QList<int> fetchAttributes = QList<int>(),
220+
QgsRect rect = QgsRect(),
221+
bool fetchGeometry = true,
222+
bool useIntersect = false) = 0;
222223

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

255250
/**
256251
* Get feature type.
@@ -265,20 +260,6 @@ class QgsVectorDataProvider : QgsDataProvider
265260
*/
266261
virtual long featureCount() const = 0;
267262

268-
/**
269-
* Get the attributes associated with a feature
270-
* TODO: Get rid of "row" and set up provider-internal caching instead
271-
*/
272-
virtual void getFeatureAttributes(int key, int& row, QgsFeature *f);
273-
274-
/**
275-
* Fetch geometry for a particular feature with id "key",
276-
* modifies "f" in-place.
277-
*
278-
* This function is enabled if capabilities() returns "SelectGeometryAtId".
279-
*/
280-
virtual void getFeatureGeometry(int key, QgsFeature *f);
281-
282263
/**
283264
* Number of attribute fields for a feature in the layer
284265
*/
@@ -290,26 +271,34 @@ class QgsVectorDataProvider : QgsDataProvider
290271
*/
291272
virtual const QMap<int, QgsField> & fields() const = 0;
292273

293-
/**
294-
* Reset the layer to clear any spatial filtering or other contstraints that
295-
* would prevent the entire record set from being traversed by call to
296-
* getNextFeature(). Some data stores may not require any special action to
297-
* reset the layer. In this case, the provider should simply implement an empty
298-
* function body.
274+
/**
275+
* Return a short comment for the data that this provider is
276+
* providing access to (e.g. the comment for postgres table).
299277
*/
278+
virtual QString dataComment() const;
279+
280+
/** Restart reading features from previous select operation */
300281
virtual void reset() = 0;
301282

302283
/**
303284
* Returns the minimum value of an attributs
304-
* @param position the number of the attribute
285+
* @param index the index of the attribute
286+
*
287+
* Default implementation walks all numeric attributes and caches minimal
288+
* and maximal values. If provider has facilities to retreive minimal
289+
* value directly, override this function.
305290
*/
306-
virtual QString minValue(uint position) = 0;
291+
virtual QVariant minValue(int index);
307292

308293
/**
309294
* Returns the maximum value of an attributs
310-
* @param position the number of the attribute
295+
* @param index the index of the attribute
296+
*
297+
* Default implementation walks all numeric attributes and caches minimal
298+
* and maximal values. If provider has facilities to retreive maximal
299+
* value directly, override this function.
311300
*/
312-
virtual QString maxValue(uint position) = 0;
301+
virtual QVariant maxValue(int index);
313302

314303
/**
315304
* Adds a list of features
@@ -396,6 +385,10 @@ class QgsVectorDataProvider : QgsDataProvider
396385
*/
397386
QList<int> allAttributesList();
398387

388+
/**Returns the names of the numerical types*/
389+
// TODO: wrap, must wrap QSet<TYPE> first
390+
//const QSet<QString>& supportedNativeTypes() const;
391+
399392
/**
400393
* Set whether provider should return also features that don't have
401394
* associated geometry. FALSE by default

python/core/qgsvectorfilewriter.sip

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
/**
3+
There are two possibilities how to use this class:
4+
1. static call to QgsVectorFileWriter::writeAsShapefile(...) which saves the whole vector layer
5+
2. create an instance of the class and issue calls to addFeature(...)
6+
7+
Currently supports only writing to shapefiles, but shouldn't be a problem to add capability
8+
to support other OGR-writable formats.
9+
*/
10+
class QgsVectorFileWriter
11+
{
12+
%TypeHeaderCode
13+
#include <qgsvectorfilewriter.h>
14+
#include <qgsfield.h>
15+
%End
16+
17+
public:
18+
19+
enum WriterError
20+
{
21+
NoError = 0,
22+
ErrDriverNotFound,
23+
ErrCreateDataSource,
24+
ErrCreateLayer
25+
};
26+
27+
/** Write contents of vector layer to a shapefile */
28+
static WriterError writeAsShapefile(QgsVectorLayer* layer,
29+
const QString& shapefileName,
30+
const QString& fileEncoding);
31+
32+
33+
/** create shapefile and initialize it */
34+
QgsVectorFileWriter(const QString& shapefileName,
35+
const QString& fileEncoding,
36+
const QMap<int, QgsField>& fields,
37+
QGis::WKBTYPE geometryType,
38+
const QgsSpatialRefSys* srs);
39+
40+
/** checks whether there were any errors in constructor */
41+
WriterError hasError();
42+
43+
/** add feature to the currently opened shapefile */
44+
bool addFeature(QgsFeature& feature);
45+
46+
/** close opened shapefile for writing */
47+
~QgsVectorFileWriter();
48+
49+
};
50+

0 commit comments

Comments
 (0)