Line data Source code
1 : /******************************************************************************
2 : * $Id$
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: Private definitions within the OGR GMT driver.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2007, Frank Warmerdam <warmerdam@pobox.com>
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #ifndef OGRGMT_H_INCLUDED
31 : #define OGRGMT_H_INCLUDED
32 :
33 : #include "ogrsf_frmts.h"
34 : #include "ogr_api.h"
35 : #include "cpl_string.h"
36 :
37 : /************************************************************************/
38 : /* OGRGmtLayer */
39 : /************************************************************************/
40 :
41 : class OGRGmtLayer final : public OGRLayer,
42 : public OGRGetNextFeatureThroughRaw<OGRGmtLayer>
43 : {
44 : GDALDataset *m_poDS = nullptr;
45 : OGRSpatialReference *m_poSRS = nullptr;
46 : OGRFeatureDefn *poFeatureDefn;
47 :
48 : int iNextFID;
49 :
50 : bool bUpdate;
51 : bool bHeaderComplete;
52 :
53 : bool bRegionComplete;
54 : OGREnvelope sRegion;
55 : vsi_l_offset nRegionOffset;
56 :
57 : VSILFILE *m_fp = nullptr;
58 :
59 : bool ReadLine();
60 : CPLString osLine;
61 : char **papszKeyedValues;
62 :
63 : bool ScanAheadForHole();
64 : bool NextIsFeature();
65 :
66 : OGRFeature *GetNextRawFeature();
67 :
68 : OGRErr WriteGeometry(OGRGeometryH hGeom, bool bHaveAngle);
69 : OGRErr CompleteHeader(OGRGeometry *);
70 :
71 : public:
72 : bool bValidFile;
73 :
74 : OGRGmtLayer(GDALDataset *poDS, const char *pszFilename, VSILFILE *fp,
75 : const OGRSpatialReference *poSRS, int bUpdate);
76 : virtual ~OGRGmtLayer();
77 :
78 : void ResetReading() override;
79 50 : DEFINE_GET_NEXT_FEATURE_THROUGH_RAW(OGRGmtLayer)
80 :
81 352 : OGRFeatureDefn *GetLayerDefn() override
82 : {
83 352 : return poFeatureDefn;
84 : }
85 :
86 : OGRErr GetExtent(OGREnvelope *psExtent, int bForce) override;
87 :
88 0 : virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent,
89 : int bForce) override
90 : {
91 0 : return OGRLayer::GetExtent(iGeomField, psExtent, bForce);
92 : }
93 :
94 : OGRErr ICreateFeature(OGRFeature *poFeature) override;
95 :
96 : virtual OGRErr CreateField(const OGRFieldDefn *poField,
97 : int bApproxOK = TRUE) override;
98 :
99 : int TestCapability(const char *) override;
100 :
101 17 : GDALDataset *GetDataset() override
102 : {
103 17 : return m_poDS;
104 : }
105 : };
106 :
107 : /************************************************************************/
108 : /* OGRGmtDataSource */
109 : /************************************************************************/
110 :
111 : class OGRGmtDataSource final : public OGRDataSource
112 : {
113 : OGRGmtLayer **papoLayers;
114 : int nLayers;
115 :
116 : char *pszName;
117 :
118 : bool bUpdate;
119 :
120 : public:
121 : OGRGmtDataSource();
122 : virtual ~OGRGmtDataSource();
123 :
124 : int Open(const char *pszFilename, VSILFILE *fp,
125 : const OGRSpatialReference *poSRS, int bUpdate);
126 : int Create(const char *pszFilename, char **papszOptions);
127 :
128 0 : const char *GetName() override
129 : {
130 0 : return pszName;
131 : }
132 :
133 3 : int GetLayerCount() override
134 : {
135 3 : return nLayers;
136 : }
137 :
138 : OGRLayer *GetLayer(int) override;
139 :
140 : OGRLayer *ICreateLayer(const char *pszName,
141 : const OGRGeomFieldDefn *poGeomFieldDefn,
142 : CSLConstList papszOptions) override;
143 : int TestCapability(const char *) override;
144 : };
145 :
146 : #endif /* ndef OGRGMT_H_INCLUDED */
|