forked from OSGeo/gdal-grass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathogrgrass.h
174 lines (144 loc) · 5.15 KB
/
ogrgrass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/******************************************************************************
*
* Project: OpenGIS Simple Features Reference Implementation
* Purpose: Private definitions for OGR/GRASS driver.
* Author: Radim Blazek, radim.blazek@gmail.com
*
******************************************************************************
* Copyright (c) 2005, Radim Blazek <radim.blazek@gmail.com>
*
* SPDX-License-Identifier: MIT
*
****************************************************************************/
#ifndef OGRGRASS_H_INCLUDED
#define OGRGRASS_H_INCLUDED
#include "gdal_version.h"
#include "ogrsf_frmts.h"
extern "C"
{
#include <grass/version.h>
#include <grass/gprojects.h>
#include <grass/gis.h>
#include <grass/dbmi.h>
#include <grass/vector.h>
}
/************************************************************************/
/* OGRGRASSLayer */
/************************************************************************/
class OGRGRASSLayer final : public OGRLayer
{
public:
OGRGRASSLayer(int layer, struct Map_info *map);
virtual ~OGRGRASSLayer();
// Layer info
auto GetName() -> const char * override
{
return osName.c_str();
}
auto GetLayerDefn() -> OGRFeatureDefn * override
{
return poFeatureDefn;
}
auto GetFeatureCount(int) -> GIntBig override;
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3, 11, 0)
auto IGetExtent(int iGeomField, OGREnvelope *psExtent, bool bForce)
-> OGRErr override;
#else
auto GetExtent(OGREnvelope *psExtent, int bForce) -> OGRErr override;
virtual auto GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce)
-> OGRErr override
{
return OGRLayer::GetExtent(iGeomField, psExtent, bForce);
}
#endif
virtual auto GetSpatialRef() -> OGRSpatialReference * override;
auto TestCapability(const char *) -> int override;
// Reading
void ResetReading() override;
virtual auto SetNextByIndex(GIntBig nIndex) -> OGRErr override;
auto GetNextFeature() -> OGRFeature * override;
auto GetFeature(GIntBig nFeatureId) -> OGRFeature * override;
// Filters
virtual auto SetAttributeFilter(const char *query) -> OGRErr override;
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3, 11, 0)
virtual OGRErr ISetSpatialFilter(int iGeomField,
const OGRGeometry *poGeom) override;
#else
virtual void SetSpatialFilter(OGRGeometry *poGeomIn) override;
virtual void SetSpatialFilter(int iGeomField, OGRGeometry *poGeom) override
{
OGRLayer::SetSpatialFilter(iGeomField, poGeom);
}
#endif
private:
std::string osName;
OGRSpatialReference *poSRS;
OGRFeatureDefn *poFeatureDefn;
char *pszQuery; // Attribute filter string
GIntBig iNextId;
int nTotalCount;
int iLayer; // Layer number
int iLayerIndex; // Layer index (in GRASS category index)
int iCatField; // Field where category (key) is stored
int nFields;
int *paFeatureIndex; // Array of indexes to category index array
// Vector map
struct Map_info *poMap;
struct field_info *poLink;
// Database connection
bool bHaveAttributes;
dbString *poDbString;
dbDriver *poDriver;
dbCursor *poCursor;
bool bCursorOpened; // Sequential database cursor opened
int iCurrentCat; // Current category in select cursor
struct line_pnts *poPoints;
struct line_cats *poCats;
auto StartDbDriver() -> bool;
auto StopDbDriver() -> bool;
auto GetFeatureGeometry(long nFeatureId, int *cat) -> OGRGeometry *;
auto SetAttributes(OGRFeature *feature, dbTable *table) -> bool;
// Features matching spatial filter for ALL features/elements in GRASS
char *paSpatialMatch;
auto SetSpatialMatch() -> bool;
// Features matching attribute filter for ALL features/elements in GRASS
char *paQueryMatch;
auto OpenSequentialCursor() -> bool;
auto ResetSequentialCursor() -> bool;
auto SetQueryMatch() -> bool;
};
/************************************************************************/
/* OGRGRASSDataSource */
/************************************************************************/
class OGRGRASSDataSource final : public OGRDataSource
{
public:
OGRGRASSDataSource() = default;
virtual ~OGRGRASSDataSource();
auto Open(const char *, bool bUpdate, bool bTestOpen,
bool bSingleNewFile = false) -> bool;
auto GetName() -> const char * override
{
return osName.c_str();
}
auto GetLayerCount() -> int override
{
return nLayers;
}
auto GetLayer(int) -> OGRLayer * override;
auto TestCapability(const char *) -> int override;
private:
OGRGRASSLayer **papoLayers{nullptr};
std::string osName; // Date source name
std::string osGisdbase; // GISBASE
std::string osLocation; // location name
std::string osMapset; // mapset name
std::string osMap; // name of vector map
struct Map_info map
{
};
int nLayers{0};
bool bOpened{false};
auto SetPath(const char *) -> bool;
};
#endif /* ndef OGRGRASS_H_INCLUDED */