1
2 ///////////////////////////////////////////////////////////
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Tool Library //
9 // io_gdal //
10 // //
11 //-------------------------------------------------------//
12 // //
13 // gdal_formats.cpp //
14 // //
15 // Copyright (C) 2016 by //
16 // Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. SAGA is free software; you //
22 // can redistribute it and/or modify it under the terms //
23 // of the GNU General Public License as published by the //
24 // Free Software Foundation, either version 2 of the //
25 // License, or (at your option) any later version. //
26 // //
27 // SAGA is distributed in the hope that it will be //
28 // useful, but WITHOUT ANY WARRANTY; without even the //
29 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
30 // PARTICULAR PURPOSE. See the GNU General Public //
31 // License for more details. //
32 // //
33 // You should have received a copy of the GNU General //
34 // Public License along with this program; if not, see //
35 // <http://www.gnu.org/licenses/>. //
36 // //
37 //-------------------------------------------------------//
38 // //
39 // e-mail: oconrad@saga-gis.de //
40 // //
41 // contact: Olaf Conrad //
42 // Bundesstr. 55 //
43 // D-20146 Hamburg //
44 // Germany //
45 // //
46 ///////////////////////////////////////////////////////////
47
48 //---------------------------------------------------------
49 #include "gdal_formats.h"
50
51 #include "gdal_driver.h"
52 #include "ogr_driver.h"
53
54
55 ///////////////////////////////////////////////////////////
56 // //
57 ///////////////////////////////////////////////////////////
58
59 //---------------------------------------------------------
60 enum
61 {
62 GDAL_LIST_FMT_ID = 0,
63 GDAL_LIST_FMT_NAME,
64 GDAL_LIST_FMT_FILTER,
65 GDAL_LIST_FMT_TYPE,
66 GDAL_LIST_FMT_ACCESS
67 };
68
69
70 ///////////////////////////////////////////////////////////
71 // //
72 // //
73 // //
74 ///////////////////////////////////////////////////////////
75
76 //---------------------------------------------------------
CGDAL_Formats(void)77 CGDAL_Formats::CGDAL_Formats(void)
78 {
79 //-----------------------------------------------------
80 Set_Name (_TL("GDAL Formats"));
81
82 Set_Author ("O.Conrad (c) 2016");
83
84 CSG_String Description;
85
86 Description = _TW(
87 "This tool lists all (file) formats supported by the currently loaded GDAL library. "
88 );
89
90 Description += CSG_String::Format("\nGDAL %s:%s\n\n", _TL("Version"), SG_Get_GDAL_Drivers().Get_Version().c_str());
91
92 Set_Description(Description);
93
94 Add_Reference("GDAL/OGR contributors", "2019",
95 "GDAL/OGR Geospatial Data Abstraction software Library",
96 "A translator library for raster and vector geospatial data formats. Open Source Geospatial Foundation.",
97 SG_T("https://gdal.org"), SG_T("Link")
98 );
99
100 //-----------------------------------------------------
101 Parameters.Add_Table("",
102 "FORMATS" , _TL("GDAL Formats"),
103 _TL(""),
104 PARAMETER_OUTPUT
105 );
106
107 Parameters.Add_Choice("",
108 "TYPE" , _TL("Type"),
109 _TL(""),
110 CSG_String::Format("%s|%s|%s|",
111 _TL("raster"),
112 _TL("vector"),
113 _TL("all")
114 ), 2
115 );
116
117 Parameters.Add_Choice("",
118 "ACCESS" , _TL("Access"),
119 _TL(""),
120 CSG_String::Format("%s|%s|%s|",
121 _TL("read"),
122 _TL("write"),
123 _TL("read or write")
124 ), 2
125 );
126
127 Parameters.Add_Bool("",
128 "RECOGNIZED", _TL("All Recognized Files"),
129 _TL("Add an entry for all recognized files."),
130 true
131 );
132 }
133
134
135 ///////////////////////////////////////////////////////////
136 // //
137 ///////////////////////////////////////////////////////////
138
139 //---------------------------------------------------------
On_Execute(void)140 bool CGDAL_Formats::On_Execute(void)
141 {
142 CSG_Table *pFormats = Parameters("FORMATS")->asTable();
143
144 pFormats->Destroy();
145 pFormats->Set_Name(_TL("GDAL Formats"));
146
147 pFormats->Add_Field("ID" , SG_DATATYPE_String);
148 pFormats->Add_Field("NAME" , SG_DATATYPE_String);
149 pFormats->Add_Field("FILTER", SG_DATATYPE_String);
150 pFormats->Add_Field("TYPE" , SG_DATATYPE_String);
151 pFormats->Add_Field("ACCESS", SG_DATATYPE_String);
152
153 //-----------------------------------------------------
154 int Type = Parameters("TYPE" )->asInt();
155 int Access = Parameters("ACCESS")->asInt();
156
157 //-----------------------------------------------------
158 if( Type != 1 ) // not vectors only
159 {
160 for(int i=0; i<SG_Get_GDAL_Drivers().Get_Count(); i++)
161 {
162 if( SG_Get_GDAL_Drivers().is_Raster(i) )
163 {
164 CSG_String R(SG_Get_GDAL_Drivers().Can_Read (i) ? "R" : "");
165 CSG_String W(SG_Get_GDAL_Drivers().Can_Write(i) ? "W" : "");
166
167 if( (Access != 0 || !R.is_Empty()) && (Access != 1 || !W.is_Empty()) )
168 {
169 CSG_Table_Record *pFormat = pFormats->Add_Record();
170
171 pFormat->Set_Value(GDAL_LIST_FMT_ID , SG_Get_GDAL_Drivers().Get_Description(i));
172 pFormat->Set_Value(GDAL_LIST_FMT_NAME , SG_Get_GDAL_Drivers().Get_Name (i));
173 pFormat->Set_Value(GDAL_LIST_FMT_FILTER, SG_Get_GDAL_Drivers().Get_Extension (i));
174 pFormat->Set_Value(GDAL_LIST_FMT_TYPE , "RASTER");
175 pFormat->Set_Value(GDAL_LIST_FMT_ACCESS, R + W);
176 }
177 }
178 }
179 }
180
181 //-----------------------------------------------------
182 if( Type != 0 ) // not rasters only
183 {
184 for(int i=0; i<SG_Get_OGR_Drivers().Get_Count(); i++)
185 {
186 if( SG_Get_OGR_Drivers().is_Vector(i) )
187 {
188 CSG_String R(SG_Get_OGR_Drivers().Can_Read (i) ? "R" : "");
189 CSG_String W(SG_Get_OGR_Drivers().Can_Write(i) ? "W" : "");
190
191 if( (Access != 0 || !R.is_Empty()) && (Access != 1 || !W.is_Empty()) )
192 {
193 CSG_Table_Record *pFormat = pFormats->Add_Record();
194
195 pFormat->Set_Value(GDAL_LIST_FMT_ID , SG_Get_OGR_Drivers().Get_Description(i));
196 pFormat->Set_Value(GDAL_LIST_FMT_NAME , SG_Get_OGR_Drivers().Get_Name (i));
197 pFormat->Set_Value(GDAL_LIST_FMT_FILTER, SG_Get_OGR_Drivers().Get_Extension (i));
198 pFormat->Set_Value(GDAL_LIST_FMT_TYPE , "VECTOR");
199 pFormat->Set_Value(GDAL_LIST_FMT_ACCESS, R + W);
200 }
201 }
202 }
203 }
204
205 //-----------------------------------------------------
206 if( Parameters("RECOGNIZED")->asBool() )
207 {
208 CSG_String Filter_All, Filter_Last;
209
210 pFormats->Set_Index(GDAL_LIST_FMT_FILTER, TABLE_INDEX_Ascending);
211
212 for(int i=0; i<pFormats->Get_Count(); i++)
213 {
214 CSG_String Filter = pFormats->Get_Record_byIndex(i)->asString(GDAL_LIST_FMT_FILTER);
215
216 if( !Filter.is_Empty() && Filter.Cmp(Filter_Last) )
217 {
218 Filter.Replace("/", ";");
219
220 Filter_All += (Filter_All.is_Empty() ? "*." : ";*.") + Filter;
221
222 Filter_Last = Filter;
223 }
224 }
225
226 pFormats->Del_Index();
227
228 if( !Filter_All.is_Empty() )
229 {
230 CSG_Table_Record *pFormat = pFormats->Add_Record();
231
232 pFormat->Set_Value(GDAL_LIST_FMT_NAME , _TL("All Recognized Files"));
233 pFormat->Set_Value(GDAL_LIST_FMT_FILTER, Filter_All);
234 pFormat->Set_Value(GDAL_LIST_FMT_TYPE , Type == 0 ? "RASTER" : Type == 1 ? "VECTOR" : "RASTER/VECTOR");
235 pFormat->Set_Value(GDAL_LIST_FMT_ACCESS, Access == 0 ? "R" : Access == 1 ? "W" : "RW" );
236 }
237 }
238
239 //-----------------------------------------------------
240 return( pFormats->Get_Count() > 0 );
241 }
242
243
244 ///////////////////////////////////////////////////////////
245 // //
246 // //
247 // //
248 ///////////////////////////////////////////////////////////
249
250 //---------------------------------------------------------
251