SWMMVis  6.0.0-alpha.4
Qt6/C++ GIS-based graphical user interface for the SWMMVis engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
featurestore.h
Go to the documentation of this file.
1
33#ifndef FEATURESTORE_H
34#define FEATURESTORE_H
35
38
39#include <QString>
40#include <QStringList>
41#include <QVector>
42
43class GDALDataset;
44class OGRLayer;
45class OGRFeature;
46
47namespace openswmmvis::feature {
48
56{
57public:
60
61 FeatureStore(const FeatureStore &) = delete;
63
64 // ----- Container-level operations (static; open nothing on success) ----
65
71 [[nodiscard]] static bool ensureGeoPackage(const QString &gpkgPath,
72 QString *error = nullptr);
73
75 [[nodiscard]] static QStringList tables(const QString &gpkgPath);
76
77 [[nodiscard]] static bool tableExists(const QString &gpkgPath,
78 const QString &table);
79
84 [[nodiscard]] static QString uniqueTableName(const QString &gpkgPath,
85 const QString &desired);
86
98 [[nodiscard]] static bool createTable(const QString &gpkgPath,
99 const QString &table,
101 bool hasZ,
102 const Schema &schema,
103 const QString &srsWkt,
104 QString *error = nullptr);
105
107 [[nodiscard]] static bool dropTable(const QString &gpkgPath,
108 const QString &table,
109 QString *error = nullptr);
110
111 // ----- Session --------------------------------------------------------
112
115 [[nodiscard]] bool open(const QString &gpkgPath, const QString &table,
116 QString *error = nullptr);
117
130 void attach(GDALDataset *ds, OGRLayer *layer,
131 const QString &gpkgPath, const QString &table);
132
133 void close();
134 [[nodiscard]] bool isOpen() const { return m_layer != nullptr; }
135
136 [[nodiscard]] QString gpkgPath() const { return m_gpkgPath; }
137 [[nodiscard]] QString tableName() const { return m_table; }
138
139 // ----- Introspection --------------------------------------------------
140
143 [[nodiscard]] Schema schema() const;
144 [[nodiscard]] GeometryType geometryType() const;
145 [[nodiscard]] bool hasZ() const;
149 [[nodiscard]] QString srsWkt() const;
150 [[nodiscard]] int count() const;
151
152 // ----- Reads ----------------------------------------------------------
153
154 [[nodiscard]] QVector<FeatureId> featureIds() const;
155 [[nodiscard]] bool feature(FeatureId id, Feature &out) const;
156 [[nodiscard]] QVector<Feature> allFeatures() const;
157
158 // ----- Writes ---------------------------------------------------------
159
169 [[nodiscard]] FeatureId addFeature(const Feature &f, QString *error = nullptr);
170
171 [[nodiscard]] bool setGeometry(FeatureId id, const FeatureGeometry &g,
172 QString *error = nullptr);
173 [[nodiscard]] bool setAttributes(FeatureId id, const QVariantMap &attrs,
174 QString *error = nullptr);
175 [[nodiscard]] bool setFeature(FeatureId id, const Feature &f,
176 QString *error = nullptr);
177 [[nodiscard]] bool removeFeature(FeatureId id, QString *error = nullptr);
178
179 // ----- Schema evolution ----------------------------------------------
180
181 [[nodiscard]] bool addField(const FieldDef &f, QString *error = nullptr);
188 [[nodiscard]] bool removeField(const QString &name, QString *error = nullptr);
189
193 bool flush();
194
195private:
197 [[nodiscard]] OGRFeature *fetch(FeatureId id) const;
199 void applyAttributes(OGRFeature *feat, const QVariantMap &attrs) const;
201 [[nodiscard]] QVariantMap readAttributes(const OGRFeature *feat) const;
202
203 GDALDataset *m_dataset = nullptr;
204 OGRLayer *m_layer = nullptr;
207 bool m_ownsDataset = true;
208 QString m_gpkgPath;
209 QString m_table;
210};
211
212} // namespace openswmmvis::feature
213
214#endif // FEATURESTORE_H
A complete feature geometry: a type plus zero or more parts.
Definition featuregeometry.h:205
One open, writable OGR table inside a GeoPackage.
Definition featurestore.h:56
void close()
Definition featurestore.cpp:308
~FeatureStore()
Definition featurestore.cpp:88
static QString uniqueTableName(const QString &gpkgPath, const QString &desired)
Derive a table name from desired that is not yet used in gpkgPath, appending _1, _2,...
Definition featurestore.cpp:169
static bool ensureGeoPackage(const QString &gpkgPath, QString *error=nullptr)
Create an empty GeoPackage at gpkgPath if it does not exist.
Definition featurestore.cpp:97
FeatureStore & operator=(const FeatureStore &)=delete
FeatureStore(const FeatureStore &)=delete
bool hasZ() const
Definition featurestore.cpp:367
FeatureStore()
Definition featurestore.cpp:83
void attach(GDALDataset *ds, OGRLayer *layer, const QString &gpkgPath, const QString &table)
Adopt a dataset and layer someone else owns.
Definition featurestore.cpp:297
bool removeField(const QString &name, QString *error=nullptr)
Drop the column name.
Definition featurestore.cpp:691
QString gpkgPath() const
Definition featurestore.h:136
FeatureId addFeature(const Feature &f, QString *error=nullptr)
Insert f.
Definition featurestore.cpp:522
static bool dropTable(const QString &gpkgPath, const QString &table, QString *error=nullptr)
Permanently drop table from gpkgPath.
Definition featurestore.cpp:241
bool setAttributes(FeatureId id, const QVariantMap &attrs, QString *error=nullptr)
Definition featurestore.cpp:593
bool flush()
Flush pending writes to disk. Called after every command so a crash cannot lose an edit and so a conc...
Definition featurestore.cpp:715
bool addField(const FieldDef &f, QString *error=nullptr)
Definition featurestore.cpp:664
Schema schema() const
The schema read back from the open table. Reflects any field added or removed since open.
Definition featurestore.cpp:323
bool isOpen() const
Definition featurestore.h:134
QVector< Feature > allFeatures() const
Definition featurestore.cpp:465
bool removeFeature(FeatureId id, QString *error=nullptr)
Definition featurestore.cpp:645
GeometryType geometryType() const
Definition featurestore.cpp:353
bool setGeometry(FeatureId id, const FeatureGeometry &g, QString *error=nullptr)
Definition featurestore.cpp:566
QVector< FeatureId > featureIds() const
Definition featurestore.cpp:395
static bool tableExists(const QString &gpkgPath, const QString &table)
Definition featurestore.cpp:161
QString tableName() const
Definition featurestore.h:137
bool open(const QString &gpkgPath, const QString &table, QString *error=nullptr)
Open table in gpkgPath for update. The store owns the dataset and closes it in close.
Definition featurestore.cpp:275
bool setFeature(FeatureId id, const Feature &f, QString *error=nullptr)
Definition featurestore.cpp:617
int count() const
Definition featurestore.cpp:385
QString srsWkt() const
CRS WKT of the geometry column; empty when the table declares none (the layer then assumes canvas CRS...
Definition featurestore.cpp:373
static QStringList tables(const QString &gpkgPath)
Table names inside gpkgPath; empty when it cannot be read.
Definition featurestore.cpp:147
static bool createTable(const QString &gpkgPath, const QString &table, GeometryType type, bool hasZ, const Schema &schema, const QString &srsWkt, QString *error=nullptr)
Create a new table.
Definition featurestore.cpp:181
An ordered list of FieldDef, with name lookup.
Definition featuretypes.h:104
enum OpenSWMM::Render::@788::Value::Type type
GDALDataset * ds
Definition meshattributeassigndialog.cpp:86
Definition featuregeometry.h:40
qint64 FeatureId
Definition featuretypes.h:33
GeometryType
Geometry kinds an editable feature layer can hold.
Definition featuregeometry.h:52
QString name
Definition sectionmodelbuilders.cpp:474
One editable feature: identity, geometry, attributes.
Definition featuretypes.h:150
One user-defined attribute column.
Definition featuretypes.h:67