~ubuntu-branches/ubuntu/hardy/qgis/hardy

« back to all changes in this revision

Viewing changes to src/qgsfeature.h

  • Committer: Bazaar Package Importer
  • Author(s): William Grant
  • Date: 2007-05-06 13:42:32 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070506134232-pyli6t388w5asd8x
Tags: 0.8.0-3ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules, debian/qgis.install, debian/qgis.dirs debian/qgis.desktop:
    Add and install .desktop.
* debian/qgis.desktop: Remove Applications category; it's not real.
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
                      qgsfeature.h - Spatial Feature Class
3
 
                     --------------------------------------
4
 
Date                 : 09-Sep-2003
5
 
Copyright            : (C) 2003 by Gary E.Sherman
6
 
email                : sherman at mrcc.com
7
 
 ***************************************************************************
8
 
 *                                                                         *
9
 
 *   This program is free software; you can redistribute it and/or modify  *
10
 
 *   it under the terms of the GNU General Public License as published by  *
11
 
 *   the Free Software Foundation; either version 2 of the License, or     *
12
 
 *   (at your option) any later version.                                   *
13
 
 *                                                                         *
14
 
 ***************************************************************************/
15
 
/* $Id: qgsfeature.h,v 1.14.2.1 2005/10/10 20:05:09 gsherman Exp $ */
16
 
 
17
 
#ifndef QGSFEATURE_H
18
 
#define QGSFEATURE_H
19
 
 
20
 
#include <geos.h>
21
 
#include <qstring.h>
22
 
#include <map>
23
 
#include <vector>
24
 
 
25
 
#include "qgsfeatureattribute.h"
26
 
#include "qgis.h"
27
 
#include "qgspoint.h"
28
 
 
29
 
class QgsRect;
30
 
 
31
 
/** \class QgsFeature - Feature attribute class.
32
 
 * Encapsulates a single feature including id and field/value.
33
 
 *@author Gary E.Sherman
34
 
 */
35
 
 
36
 
class QgsFeature {
37
 
 
38
 
  public:
39
 
 
40
 
    //! Constructor
41
 
    QgsFeature();
42
 
    QgsFeature(int id, QString const & typeName = "" );
43
 
 
44
 
 
45
 
    /** copy ctor needed due to internal pointer */
46
 
    QgsFeature( QgsFeature const & );
47
 
 
48
 
    /** assignment operator needed due to internal pointer */
49
 
    QgsFeature & operator=( QgsFeature const & rhs );
50
 
 
51
 
    //! Destructor
52
 
    ~QgsFeature();
53
 
 
54
 
    /**
55
 
     * Get the feature id for this feature
56
 
     * @return Feature id
57
 
     */
58
 
    int featureId() const;
59
 
 
60
 
    /**
61
 
     * Set the feature id for this feature
62
 
     * @param id Feature id
63
 
     */
64
 
     void setFeatureId(int id);
65
 
 
66
 
 
67
 
    /** returns the feature's type name
68
 
     */
69
 
     QString const & typeName() const;
70
 
 
71
 
 
72
 
    /** sets the feature's type name
73
 
     */
74
 
     void typeName( QString const & typeName );
75
 
 
76
 
    /**
77
 
     * Get the attributes for this feature.
78
 
     * @return A std::map containing the field name/value mapping
79
 
     */
80
 
    const std::vector<QgsFeatureAttribute>& attributeMap();
81
 
 
82
 
    /** 
83
 
     * Add an attribute to the map
84
 
     */
85
 
    void addAttribute(QString const & field, QString const & value = "");
86
 
 
87
 
    /**Deletes an attribute and its value*/
88
 
    void deleteAttribute(const QString& name);
89
 
 
90
 
    /**Changes an existing attribute value
91
 
       @param name attribute name
92
 
       @param newval new value*/
93
 
    void changeAttributeValue(const QString& name, const QString& newval);
94
 
 
95
 
    /**
96
 
     * Get the fields for this feature
97
 
     * @return A std::map containing field position (index) and field name
98
 
     */
99
 
    const std::map<int, QString>& fields();
100
 
 
101
 
    /**
102
 
     * Return the validity of this feature. This is normally set by
103
 
     * the provider to indicate some problem that makes the feature
104
 
     * invalid or to indicate a null feature.
105
 
     */
106
 
    bool isValid() const;
107
 
 
108
 
    /**
109
 
     * Validate the feature
110
 
     */
111
 
    bool validate() const;
112
 
 
113
 
    /** 
114
 
     * Set the validity of the feature.
115
 
     */
116
 
    void setValid(bool validity);
117
 
 
118
 
    unsigned char * getGeometry() const;
119
 
 
120
 
    size_t getGeometrySize() const;
121
 
 
122
 
    QString const& wellKnownText() const; 
123
 
 
124
 
    /** Set WKB geometry*/
125
 
    void setGeometry(unsigned char * geometry, size_t length);
126
 
 
127
 
    /**Shows a popup dialog to change attribute values
128
 
     @return true if dialog is accepted, false if rejected*/
129
 
    bool attributeDialog();
130
 
 
131
 
    /**Test for intersection with a rectangle (uses GEOS)*/
132
 
    bool intersects(QgsRect* r) const;
133
 
 
134
 
    /**Returns the Vertex closest to a given point*/
135
 
    QgsPoint closestVertex(const QgsPoint& point) const;
136
 
 
137
 
    /**Returns the bounding box of this feature*/
138
 
    QgsRect boundingBox() const;
139
 
 
140
 
    /**Creates a geos geometry from this features geometry. Note, that the returned object needs to be deleted*/
141
 
    geos::Geometry* geosGeometry() const;
142
 
 
143
 
  private:
144
 
 
145
 
    //! feature id
146
 
    int mFid;
147
 
 
148
 
    //! std::map containing field name/value pairs
149
 
    std::vector<QgsFeatureAttribute> attributes;
150
 
 
151
 
    //! std::map containing the field index and name
152
 
    std::map<int, QString> fieldNames;
153
 
 
154
 
    /** pointer to geometry in binary WKB format
155
 
 
156
 
       This is usually set by a call to OGRGeometry::exportToWkb()
157
 
     */
158
 
    unsigned char * geometry;
159
 
 
160
 
    /** size of geometry */
161
 
    size_t geometrySize;
162
 
 
163
 
    //! Flag to indicate if this feature is valid
164
 
    bool mValid;
165
 
 
166
 
    /// feature type name
167
 
    QString mTypeName;
168
 
 
169
 
    /**WKT representation of the geometry*/
170
 
    mutable QString mWKT;
171
 
 
172
 
    /**Exports the current WKB to mWKT
173
 
     @return true in case of success and false else*/
174
 
    bool exportToWKT() const;
175
 
 
176
 
}; // class QgsFeature
177
 
 
178
 
#endif