~ubuntu-branches/ubuntu/trusty/qgis/trusty

« back to all changes in this revision

Viewing changes to python/core/qgsgeometry.sip

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/** polyline is just a list of points */
 
3
typedef QVector<QgsPoint> QgsPolyline;
 
4
 
 
5
/** polygon: first item of the list is outer ring, inner rings (if any) start from second item */
 
6
typedef QVector< QVector<QgsPoint> > QgsPolygon;
 
7
    
 
8
/** a collection of QgsPoints that share a common collection of attributes */
 
9
typedef QVector<QgsPoint> QgsMultiPoint;
 
10
 
 
11
/** a collection of QgsPolylines that share a common collection of attributes */
 
12
typedef QVector< QVector<QgsPoint> > QgsMultiPolyline;
 
13
 
 
14
/** a collection of QgsPolygons that share a common collection of attributes */
 
15
typedef QVector< QVector< QVector<QgsPoint> > > QgsMultiPolygon;
 
16
 
 
17
typedef unsigned int size_t;
 
18
    
 
19
class QgsGeometry
 
20
{
 
21
%TypeHeaderCode
 
22
#include <qgsgeometry.h>
 
23
%End
 
24
 
 
25
  public:
 
26
 
 
27
    //! Constructor
 
28
    QgsGeometry();
 
29
    
 
30
    /** copy constructor will prompt a deep copy of the object */
 
31
    QgsGeometry( const QgsGeometry & );
 
32
    
 
33
 
 
34
    //! Destructor
 
35
    ~QgsGeometry();
 
36
 
 
37
 
 
38
    /** static method that creates geometry from Wkt */
 
39
    static QgsGeometry* fromWkt(QString wkt) /Factory/;
 
40
    
 
41
    /** construct geometry from a point */
 
42
    static QgsGeometry* fromPoint(const QgsPoint& point) /Factory/;
 
43
    /** construct geometry from a multipoint */
 
44
    static QgsGeometry* fromMultiPoint(const QgsMultiPoint& multipoint) /Factory/;
 
45
    /** construct geometry from a polyline */
 
46
    static QgsGeometry* fromPolyline(const QgsPolyline& polyline) /Factory/;
 
47
    /** construct geometry from a multipolyline*/
 
48
    static QgsGeometry* fromMultiPolyline(const QgsMultiPolyline& multiline) /Factory/;
 
49
    /** construct geometry from a polygon */
 
50
    static QgsGeometry* fromPolygon(const QgsPolygon& polygon) /Factory/;
 
51
    /** construct geometry from a multipolygon */
 
52
    static QgsGeometry* fromMultiPolygon(const QgsMultiPolygon& multipoly) /Factory/;
 
53
    /** construct geometry from a rectangle */
 
54
    static QgsGeometry* fromRect(const QgsRectangle& rect) /Factory/;
 
55
        
 
56
 
 
57
    
 
58
    /** 
 
59
       Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
 
60
       This class will take ownership of the buffer.
 
61
    */
 
62
    void fromWkb(unsigned char * wkb /Array/, size_t length /ArraySize/);
 
63
%MethodCode
 
64
  // create copy of Python's string and pass it to fromWkb()
 
65
  unsigned char * copy = new unsigned char[a1];
 
66
  memcpy(copy, a0, a1);
 
67
  sipCpp->fromWkb(copy, a1);
 
68
%End
 
69
    
 
70
    /** 
 
71
       Returns the buffer containing this geometry in WKB format.
 
72
       You may wish to use in conjunction with wkbSize().
 
73
    */
 
74
    SIP_PYOBJECT asWkb();
 
75
%MethodCode
 
76
  sipRes = PyString_FromStringAndSize((const char *)sipCpp->asWkb(), sipCpp->wkbSize());
 
77
%End
 
78
    
 
79
    /** 
 
80
       Returns the size of the WKB in asWkb().
 
81
    */
 
82
    size_t wkbSize();
 
83
    
 
84
    /** Returns type of wkb (point / linestring / polygon etc.) */
 
85
    QGis::WkbType wkbType();
 
86
 
 
87
    /** Returns type of the vector */
 
88
    QGis::GeometryType type();
 
89
 
 
90
    /** Returns true if wkb of the geometry is of WKBMulti* type */
 
91
    bool isMultipart();
 
92
 
 
93
    /**
 
94
       Set the geometry, feeding in a geometry in GEOS format.
 
95
    */
 
96
    // TODO: unsupported class... would be possible to use PyGEOS?
 
97
    //void fromGeos(geos::Geometry* geos);
 
98
 
 
99
    double distance(QgsGeometry& geom);
 
100
 
 
101
    /**
 
102
       Returns the vertex closest to the given point 
 
103
       (and also vertex index, squared distance and indexes of the vertices before/after)
 
104
    */
 
105
    QgsPoint closestVertex(const QgsPoint& point, int& atVertex /Out/, int& beforeVertex /Out/, int& afterVertex /Out/, double& sqrDist /Out/);
 
106
 
 
107
    /**
 
108
       Returns the indexes of the vertices before and after the given vertex index.
 
109
 
 
110
       This function takes into account the following factors:
 
111
 
 
112
       1. If the given vertex index is at the end of a linestring,
 
113
          the adjacent index will be -1 (for "no adjacent vertex")
 
114
       2. If the given vertex index is at the end of a linear ring
 
115
          (such as in a polygon), the adjacent index will take into
 
116
          account the first vertex is equal to the last vertex (and will
 
117
          skip equal vertex positions).
 
118
    */
 
119
    void adjacentVertices(int atVertex, int& beforeVertex /Out/, int& afterVertex /Out/);
 
120
 
 
121
    /** Insert a new vertex before the given vertex index,
 
122
     *  ring and item (first number is index 0)
 
123
     *  If the requested vertex number (beforeVertex.back()) is greater
 
124
     *  than the last actual vertex on the requested ring and item,
 
125
     *  it is assumed that the vertex is to be appended instead of inserted.
 
126
     *  Returns FALSE if atVertex does not correspond to a valid vertex
 
127
     *  on this geometry (including if this geometry is a Point).
 
128
     *  It is up to the caller to distinguish between
 
129
     *  these error conditions.  (Or maybe we add another method to this
 
130
     *  object to help make the distinction?)
 
131
     */
 
132
        bool insertVertex(double x, double y, int beforeVertex);
 
133
 
 
134
    /** Moves the vertex at the given position number,
 
135
     *  ring and item (first number is index 0)
 
136
     *  to the given coordinates.
 
137
     *  Returns FALSE if atVertex does not correspond to a valid vertex
 
138
     *  on this geometry 
 
139
     */
 
140
        bool moveVertex(double x, double y, int atVertex);
 
141
    
 
142
        /** Deletes the vertex at the given position number,
 
143
     *  ring and item (first number is index 0)
 
144
     *  Returns FALSE if atVertex does not correspond to a valid vertex
 
145
     *  on this geometry (including if this geometry is a Point),
 
146
     *  or if the number of remaining verticies in the linestring
 
147
     *  would be less than two.
 
148
     *  It is up to the caller to distinguish between
 
149
     *  these error conditions.  (Or maybe we add another method to this
 
150
     *  object to help make the distinction?)
 
151
     */
 
152
        bool deleteVertex(int atVertex);
 
153
 
 
154
    /**
 
155
     *  Returns coordinates of a vertex.
 
156
     *  @param atVertex index of the vertex
 
157
     *  @return Coordinates of the vertex or QgsPoint(0,0) on error
 
158
     */
 
159
    QgsPoint vertexAt(int atVertex);
 
160
 
 
161
    /**
 
162
        Returns the squared cartesian distance between the given point
 
163
        to the given vertex index*/
 
164
        double sqrDistToVertexAt(QgsPoint& point /In/, int atVertex);
 
165
 
 
166
        
 
167
        /**
 
168
     * Searches for the the closest vertex in this geometry to the given point.
 
169
     * @param point Specifiest the point for search
 
170
     * @param atVertex Receives index of the closest vertex
 
171
     * @return The squared cartesian distance is also returned in sqrDist, negative number on error
 
172
     */
 
173
    double closestVertexWithContext(const QgsPoint& point, int& atVertex /Out/);
 
174
 
 
175
    /**
 
176
     * Searches for the closest segment of geometry to the given point
 
177
     * @param point Specifies the point for search
 
178
     * @param minDistPoint Receives the nearest point on the segment
 
179
     * @param beforeVertex Receives index of the vertex before the closest segment
 
180
     * @return The squared cartesian distance is also returned in sqrDist, negative number on error
 
181
     */
 
182
    double closestSegmentWithContext(const QgsPoint& point, QgsPoint& minDistPoint /Out/, int& beforeVertex /Out/);
 
183
 
 
184
 /**Adds a new ring to this geometry. This makes only sense for polygon and multipolygons.
 
185
     @return 0 in case of success (ring added), 1 problem with geometry type, 2 ring not closed, \
 
186
     3 ring is not valid geometry, 4 ring not disjoint with existing rings, 5 no polygon found which contained the ring*/
 
187
    int addRing(const QList<QgsPoint>& ring);
 
188
 
 
189
 /**Adds a new island polygon to a multipolygon feature
 
190
     @return 0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring \
 
191
not disjoint with existing polygons of the feature*/
 
192
    int addIsland(const QList<QgsPoint>& ring);
 
193
 
 
194
 /**Translate this geometry by dx, dy
 
195
     @return 0 in case of success*/
 
196
    int translate(double dx, double dy);
 
197
 
 
198
 /**Transform this geometry as described by CoordinateTranasform ct
 
199
     @return 0 in case of success*/
 
200
    int transform( const QgsCoordinateTransform& ct );
 
201
 
 
202
 /**Splits this geometry according to a given line. Note that the geometry is only split once. If there are several intersections
 
203
    between geometry and splitLine, only the first one is considered.
 
204
    @param splitLine the line that splits the geometry
 
205
    @param newGeometrys OUT: list of new geometries that have been created with the split
 
206
    @param topological true if topological editing is enabled
 
207
    @topologyTestPoints OUT: points that need to be tested for topological completeness in the dataset
 
208
    @return 0 in case of success, 1 if geometry has not been split, error else*/
 
209
    int splitGeometry(const QList<QgsPoint>& splitLine, QList<QgsGeometry*>& newGeometries, bool topological, QList<QgsPoint>& topologyTestPoints);
 
210
 
 
211
/**Replaces a part of this geometry with another line
 
212
      @return 0 in case of success
 
213
      @note: this function was added in version 1.3*/
 
214
    int reshapeGeometry( const QList<QgsPoint>& reshapeWithLine );
 
215
 
 
216
 /**Changes this geometry such that it does not intersect the other geometry
 
217
       @param other geometry that should not be intersect
 
218
       @return 0 in case of success*/
 
219
    int makeDifference(QgsGeometry* other);     
 
220
 
 
221
    /**Returns the bounding box of this feature*/
 
222
    QgsRectangle boundingBox();
 
223
 
 
224
    /** Test for intersection with a rectangle (uses GEOS) */
 
225
    bool intersects(const QgsRectangle& r);
 
226
    /** Test for intersection with a geoemetry (uses GEOS) */
 
227
    bool intersects(QgsGeometry* geometry);
 
228
 
 
229
    /** Test for containment of a point (uses GEOS) */
 
230
    bool contains(QgsPoint* p);
 
231
 
 
232
    /** Returns a buffer region around this geometry having the given width and with a specified number
 
233
        of segments used to approximate curves */
 
234
    QgsGeometry* buffer(double distance, int segments) /Factory/;
 
235
 
 
236
    /** Returns a simplified version of this geometry using a specified tolerance value */
 
237
    QgsGeometry* simplify(double tolerance) /Factory/;
 
238
    
 
239
    /** Returns the center of mass of a geometry
 
240
    * @note for line based geometries, the center point of the line is returned,
 
241
    * and for point based geometries, the point itself is returned */
 
242
    QgsGeometry* centroid() /Factory/;
 
243
 
 
244
    /** Returns the smallest convex polygon that contains all the points in the geometry. */
 
245
    QgsGeometry* convexHull() /Factory/;
 
246
    
 
247
    /** Returns a geometry representing the points shared by this geometry and other. */
 
248
    QgsGeometry* intersection(QgsGeometry* geometry) /Factory/;
 
249
    
 
250
    /** Returns a geometry representing all the points in this geometry and other (a 
 
251
     * union geometry operation). 
 
252
     * @note this operation is not called union since its a reserved word in C++.*/
 
253
    QgsGeometry* combine( QgsGeometry* geometry ) /Factory/;
 
254
    
 
255
    /** Returns a geometry representing the points making up this geometry that do not make up other. */
 
256
    QgsGeometry* difference(QgsGeometry* geometry) /Factory/;
 
257
    
 
258
    /** Returns a Geometry representing the points making up this Geometry that do not make up other. */
 
259
    QgsGeometry* symDifference(QgsGeometry* geometry) /Factory/;
 
260
    
 
261
    /**Creates a geos geometry from this features geometry. Note, that the returned object needs to be deleted*/
 
262
    // TODO: unsupported class... would be possible to use PyGEOS?
 
263
    //geos::Geometry* geosGeometry() const;
 
264
 
 
265
    /** Exports the geometry to mWkt
 
266
        @return true in case of success and false else
 
267
     */
 
268
    QString exportToWkt();
 
269
    
 
270
    /* Accessor functions for getting geometry data */
 
271
    
 
272
    /** return contents of the geometry as a point
 
273
        if wkbType is WKBPoint, otherwise returns [0,0] */
 
274
    QgsPoint asPoint();
 
275
    
 
276
    /** return contents of the geometry as a polyline
 
277
        if wkbType is WKBLineString, otherwise an empty list */
 
278
    QgsPolyline asPolyline();
 
279
    
 
280
    /** return contents of the geometry as a polygon
 
281
        if wkbType is WKBPolygon, otherwise an empty list */
 
282
    QgsPolygon asPolygon();
 
283
    
 
284
    /** return contents of the geometry as a multi point
 
285
        if wkbType is WKBMultiPint, otherwise an empty list */
 
286
    QgsMultiPoint asMultiPoint();
 
287
    
 
288
    /** return contents of the geometry as a multi linestring
 
289
        if wkbType is WKBMultiLineString, otherwise an empty list */
 
290
    QgsMultiPolyline asMultiPolyline();
 
291
    
 
292
    /** return contents of the geometry as a multi polygon
 
293
        if wkbType is WKBMultiPolygon, otherwise an empty list */
 
294
    QgsMultiPolygon asMultiPolygon();
 
295
 
 
296
    /** return contents of the geometry as a list of geometries
 
297
     @note added in version 1.1 */
 
298
    // TODO: destruction of created geometries??
 
299
    QList<QgsGeometry*> asGeometryCollection() /Factory/;
 
300
 
 
301
    /** delete a ring in polygon or multipolygon.
 
302
      Ring 0 is outer ring and can't be deleted.
 
303
      @return TRUE on success
 
304
      @note added in version 1.2 */
 
305
    bool deleteRing( int ringNum, int partNum = 0 );
 
306
 
 
307
    /** delete part identified by the part number
 
308
      @return TRUE on success
 
309
      @note added in version 1.2 */
 
310
    bool deletePart( int partNum );
 
311
 
 
312
    /**Converts single type geometry into multitype geometry
 
313
     e.g. a polygon into a multipolygon geometry with one polygon
 
314
    @return true in case of success and false else*/
 
315
    bool convertToMultiType();
 
316
 
 
317
}; // class QgsGeometry
 
318