-
Notifications
You must be signed in to change notification settings - Fork 8
/
ogrgrass.h
170 lines (143 loc) · 5.48 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
/******************************************************************************
* $Id$
*
* Project: OpenGIS Simple Features Reference Implementation
* Purpose: Private definitions for OGR/GRASS driver.
* Author: Radim Blazek, [email protected]
*
******************************************************************************
* Copyright (c) 2005, Radim Blazek <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
#ifndef OGRGRASS_H_INCLUDED
#define OGRGRASS_H_INCLUDED
#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
OGRFeatureDefn *GetLayerDefn() override
{
return poFeatureDefn;
}
GIntBig GetFeatureCount(int) override;
OGRErr GetExtent(OGREnvelope *psExtent, int bForce) override;
virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent,
int bForce) override
{
return OGRLayer::GetExtent(iGeomField, psExtent, bForce);
}
virtual OGRSpatialReference *GetSpatialRef() override;
int TestCapability(const char *) override;
// Reading
void ResetReading() override;
virtual OGRErr SetNextByIndex(GIntBig nIndex) override;
OGRFeature *GetNextFeature() override;
OGRFeature *GetFeature(GIntBig nFeatureId) override;
// Filters
virtual OGRErr SetAttributeFilter(const char *query) override;
virtual void SetSpatialFilter(OGRGeometry *poGeomIn) override;
virtual void SetSpatialFilter(int iGeomField, OGRGeometry *poGeom) override
{
OGRLayer::SetSpatialFilter(iGeomField, poGeom);
}
private:
char *pszName;
OGRSpatialReference *poSRS;
OGRFeatureDefn *poFeatureDefn;
char *pszQuery; // Attribute filter string
int 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;
bool StartDbDriver();
bool StopDbDriver();
OGRGeometry *GetFeatureGeometry(long nFeatureId, int *cat);
bool SetAttributes(OGRFeature *feature, dbTable *table);
// Features matching spatial filter for ALL features/elements in GRASS
char *paSpatialMatch;
bool SetSpatialMatch();
// Features matching attribute filter for ALL features/elements in GRASS
char *paQueryMatch;
bool OpenSequentialCursor();
bool ResetSequentialCursor();
bool SetQueryMatch();
};
/************************************************************************/
/* OGRGRASSDataSource */
/************************************************************************/
class OGRGRASSDataSource final : public OGRDataSource
{
public:
OGRGRASSDataSource();
virtual ~OGRGRASSDataSource();
bool Open(const char *, bool bUpdate, bool bTestOpen,
bool bSingleNewFile = false);
const char *GetName() override
{
return pszName;
}
int GetLayerCount() override
{
return nLayers;
}
OGRLayer *GetLayer(int) override;
int TestCapability(const char *) override;
private:
OGRGRASSLayer **papoLayers;
char *pszName; // Date source name
char *pszGisdbase; // GISBASE
char *pszLocation; // location name
char *pszMapset; // mapset name
char *pszMap; // name of vector map
struct Map_info map;
int nLayers;
bool bOpened;
static bool SplitPath(char *, char **, char **, char **, char **);
};
#endif /* ndef OGRGRASS_H_INCLUDED */