21 #include "base/Vector2d.h" 22 #include "imageclasses/ImgReaderOgr.h" 29 template<
typename T>
unsigned int readDataImageShape(
const string &filename,
31 vector<string>& fields,
35 const string& query=
"",
39 template<
typename T>
unsigned int readDataImageShape(
const string &filename,
41 vector<string>& fields,
53 cout <<
"reading shape file " << filename << endl;
56 imgReaderShape.open(filename);
57 bool queryFound=
false;
59 imgReaderShape.getFields(fields);
60 vector<string>::iterator fit=fields.begin();
62 cout <<
"reading fields: ";
63 while(fit!=fields.end()){
66 size_t pos=(*fit).find_first_not_of(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ ");
67 if(pos==string::npos){
69 if((*fit).find(query)!=string::npos)
75 string fieldname=(*fit).substr(pos);
76 int iband=atoi(fieldname.c_str());
77 if((start||end)&&(iband<start||iband>end))
87 for(vector<string>::iterator fit=fields.begin();fit!=fields.end();++fit)
94 qs <<
"select * from " << imgReaderShape.getLayerName() <<
" where " << query <<
"=1";
96 cout <<
"reading with sql: " << qs.str() << endl;
97 nband=imgReaderShape.readSql(mapPixels,OFTReal,fields,label,qs.str(),NULL,0,
true,
false);
101 cout <<
"reading data" << endl;
102 nband=imgReaderShape.readData(mapPixels,OFTReal,fields,label,0,
true,verbose==2);
108 qs <<
"select * from " << imgReaderShape.getLayerName() <<
" where " << query <<
"=1";
110 cout <<
"reading with sql: " << qs.str() << endl;
111 assert(nband==imgReaderShape.readSql(mapPixels,OFTReal,fields,label,qs.str(),NULL,0,
true,
false));
114 assert(nband==imgReaderShape.readData(mapPixels,OFTReal,fields,label,0,
true,
false));
119 estr << e <<
" " << filename;
122 nsample=imgReaderShape.getFeatureCount();
123 totalSamples+=nsample;
125 cout <<
": " << nsample <<
" samples read with " << nband <<
" bands" << endl;
126 imgReaderShape.close();
128 cout <<
"total number of samples read " << totalSamples << endl;
131 #endif //_PKDUMPOGR_H_