24 #include "base/Optionpk.h" 25 #include "imageclasses/ImgReaderOgr.h" 26 #include "pkdumpogr.h" 72 int main(
int argc,
char *argv[])
75 Optionpk<string> layer_opt(
"ln",
"lname",
"Layer name(s) in sample (leave empty to select all)");
77 Optionpk<string> attribute_opt(
"n",
"name",
"names of the attributes to select. Each attribute is stored in a separate band. Default is ALL: write all attributes",
"ALL");
78 Optionpk<bool> pos_opt(
"pos",
"pos",
"include position (x and y)",
false);
79 Optionpk<bool> transpose_opt(
"t",
"transpose",
"transpose output (does not work for -n ALL ",
false);
81 Optionpk<short> verbose_opt(
"v",
"verbose",
"verbose (Default: 0)", 0,2);
84 verbose_opt.setHide(2);
88 doProcess=input_opt.retrieveOption(argc,argv);
89 layer_opt.retrieveOption(argc,argv);
90 output_opt.retrieveOption(argc,argv);
91 attribute_opt.retrieveOption(argc,argv);
92 pos_opt.retrieveOption(argc,argv);
93 transpose_opt.retrieveOption(argc,argv);
94 fs_opt.retrieveOption(argc,argv);
95 verbose_opt.retrieveOption(argc,argv);
97 catch(
string predefinedString){
98 std::cout << predefinedString << std::endl;
103 cout <<
"Usage: pkdumpogr -i input [-o output]" << endl;
105 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
109 if(input_opt.empty()){
110 std::cerr <<
"No input file provided (use option -i). Use --help for help information" << std::endl;
116 inputReader.open(input_opt[0]);
118 catch(
string errorstring){
119 cerr << errorstring << endl;
122 if(output_opt.size())
123 outputFile.open(output_opt[0].c_str(),ios::out);
125 inputReader.setFieldSeparator(fs_opt[0]);
128 int nlayerRead=inputReader.getDataSource()->GetLayerCount();
130 cout <<
"number of layers: " << nlayerRead << endl;
132 for(
int ilayer=0;ilayer<nlayerRead;++ilayer){
133 OGRLayer *readLayer=inputReader.getLayer(ilayer);
134 string currentLayername=readLayer->GetName();
136 if(find(layer_opt.begin(),layer_opt.end(),currentLayername)==layer_opt.end())
139 cout <<
"processing layer " << currentLayername << endl;
143 if(attribute_opt[0]==
"ALL"){
144 attribute_opt.clear();
145 OGRFeatureDefn *poFDefn = readLayer->GetLayerDefn();
146 for(
int iField=0;iField<poFDefn->GetFieldCount();++iField){
147 OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
148 std::string fieldname=poFieldDefn->GetNameRef();
149 attribute_opt.push_back(fieldname);
153 vector<double> xvector;
154 vector<double> yvector;
155 if(inputReader.getGeometryType()==wkbPoint)
156 inputReader.readXY(xvector,yvector);
158 for(
int ifield=0;ifield<attribute_opt.size();++ifield){
160 cout <<
"field: " << ifield << endl;
161 theData[ifield].clear();
162 inputReader.readData(theData[ifield],OFTReal,attribute_opt[ifield],ilayer,verbose_opt[0]);
165 std::cout <<
"number of fields: " << theData.size() << std::endl;
166 std::cout <<
"number of samples: " << theData[0].size() << std::endl;
168 if(transpose_opt[0]){
169 if(pos_opt[0]&&(inputReader.getGeometryType()==wkbPoint)){
170 if(output_opt.size()){
171 outputFile <<
"X" << fs_opt[0];
172 for(
int isample=0;isample<xvector.size();++isample){
173 outputFile << xvector[isample];
174 if(isample<xvector.size()-1)
175 outputFile << fs_opt[0];
177 outputFile << std::endl;
179 outputFile <<
"Y" << fs_opt[0];
180 for(
int isample=0;isample<yvector.size();++isample){
181 outputFile << yvector[isample];
182 if(isample<yvector.size()-1)
183 outputFile << fs_opt[0];
185 outputFile << std::endl;
189 std::cout <<
"X" << fs_opt[0];
190 for(
int isample=0;isample<xvector.size();++isample){
191 std::cout << xvector[isample];
192 if(isample<xvector.size()-1)
193 std::cout << fs_opt[0];
195 std::cout << std::endl;
197 std::cout <<
"Y" << fs_opt[0];
198 for(
int isample=0;isample<yvector.size();++isample){
199 std::cout << yvector[isample];
200 if(isample<yvector.size()-1)
201 std::cout << fs_opt[0];
203 std::cout << std::endl;
207 for(
int ifield=0;ifield<theData.size();++ifield){
208 if(output_opt.size()){
209 outputFile << ifield << fs_opt[0];
210 for(
int isample=0;isample<theData[0].size();++isample){
211 outputFile << theData[ifield][isample];
212 if(isample<theData[0].size()-1)
213 outputFile << fs_opt[0];
215 outputFile << std::endl;
219 std::cout << ifield << fs_opt[0];
220 for(
int isample=0;isample<theData[0].size();++isample){
221 std::cout << theData[ifield][isample];
222 if(isample<theData[0].size()-1)
223 std::cout << fs_opt[0];
225 std::cout << std::endl;
231 for(
int isample=0;isample<theData[0].size();++isample){
232 if(output_opt.size()){
233 outputFile << isample << fs_opt[0];
235 outputFile << xvector[isample] << fs_opt[0] << yvector[isample] << fs_opt[0];
236 for(
int ifield=0;ifield<theData.size();++ifield){
237 outputFile << theData[ifield][isample];
238 if(ifield<theData.size()-1)
239 outputFile << fs_opt[0];
241 outputFile << std::endl;
245 std::cout << isample << fs_opt[0];
247 std::cout << xvector[isample] << fs_opt[0] << yvector[isample] << fs_opt[0];
248 for(
int ifield=0;ifield<theData.size();++ifield){
249 std::cout << theData[ifield][isample];
250 if(ifield<theData.size()-1)
251 std::cout << fs_opt[0];
253 std::cout << std::endl;
258 if(output_opt.size())