28 #include "imageclasses/ImgReaderGdal.h"
29 #include "imageclasses/ImgWriterOgr.h"
30 #include "base/Optionpk.h"
31 #include "algorithms/StatFactory.h"
34 #define PI 3.1415926535897932384626433832795
38 enum RULE_TYPE {point=0, mean=1, proportion=2, custom=3, min=4, max=5, mode=6, centroid=7, sum=8, median=9, stdev=10};
43 int main(
int argc,
char *argv[])
45 Optionpk<string> image_opt(
"i",
"input",
"Raster input dataset containing band information");
46 Optionpk<string> sample_opt(
"s",
"sample",
"OGR vector dataset with features to be extracted from input data. Output will contain features with input band information included. Sample image can also be GDAL raster dataset.");
47 Optionpk<string> layer_opt(
"ln",
"ln",
"Layer name(s) in sample (leave empty to select all)");
48 Optionpk<unsigned int> random_opt(
"rand",
"random",
"Create simple random sample of points. Provide number of points to generate");
49 Optionpk<double> grid_opt(
"grid",
"grid",
"Create systematic grid of points. Provide cell grid size (in projected units, e.g,. m)");
51 Optionpk<int> class_opt(
"c",
"class",
"Class(es) to extract from input sample image. Leave empty to extract all valid data pixels from sample dataset. Make sure to set classes if rule is set to mode or proportion");
52 Optionpk<float> threshold_opt(
"t",
"threshold",
"Probability threshold for selecting samples (randomly). Provide probability in percentage (>0) or absolute (<0). Use a single threshold for vector sample datasets. If using raster land cover maps as a sample dataset, you can provide a threshold value for each class (e.g. -t 80 -t 60). Use value 100 to select all pixels for selected class(es)", 100);
53 Optionpk<string> ogrformat_opt(
"f",
"f",
"Output sample dataset format",
"SQLite");
54 Optionpk<string> ftype_opt(
"ft",
"ftype",
"Field type (only Real or Integer)",
"Real");
55 Optionpk<string> ltype_opt(
"lt",
"ltype",
"Label type: In16 or String",
"Integer");
56 Optionpk<bool> polygon_opt(
"polygon",
"polygon",
"Create OGRPolygon as geometry instead of OGRPoint.",
false);
57 Optionpk<int> band_opt(
"b",
"band",
"Band index(es) to extract. Leave empty to use all bands");
58 Optionpk<string> rule_opt(
"r",
"rule",
"Rule how to report image information per feature (only for vector sample). point (value at each point or at centroid if polygon), centroid, mean, stdev, median, proportion, min, max, mode, sum.",
"centroid");
59 Optionpk<double> srcnodata_opt(
"srcnodata",
"srcnodata",
"Invalid value(s) for input image");
60 Optionpk<int> bndnodata_opt(
"bndnodata",
"bndnodata",
"Band(s) in input image to check if pixel is valid (used for srcnodata)", 0);
61 Optionpk<float> polythreshold_opt(
"tp",
"thresholdPolygon",
"(absolute) threshold for selecting samples in each polygon");
62 Optionpk<string> test_opt(
"test",
"test",
"Test sample dataset (use this option in combination with threshold<100 to create a training (output) and test set");
63 Optionpk<string> fieldname_opt(
"bn",
"bname",
"For single band input data, this extra attribute name will correspond to the raster values. For multi-band input data, multiple attributes with this prefix will be added (e.g. b0, b1, b2, etc.)",
"b");
64 Optionpk<string> label_opt(
"cn",
"cname",
"Name of the class label in the output vector dataset",
"label");
65 Optionpk<short> geo_opt(
"geo",
"geo",
"Use geo coordinates (set to 0 to use image coordinates)", 1);
66 Optionpk<short> down_opt(
"down",
"down",
"Down sampling factor (for raster sample datasets only). Can be used to create grid points", 1);
67 Optionpk<short> buffer_opt(
"buf",
"buffer",
"Buffer for calculating statistics for point features ");
68 Optionpk<bool> disc_opt(
"circ",
"circular",
"Use a circular disc kernel buffer (for vector point sample datasets only, use in combination with buffer option)",
false);
73 doProcess=image_opt.retrieveOption(argc,argv);
74 sample_opt.retrieveOption(argc,argv);
75 layer_opt.retrieveOption(argc,argv);
76 random_opt.retrieveOption(argc,argv);
77 grid_opt.retrieveOption(argc,argv);
78 output_opt.retrieveOption(argc,argv);
79 class_opt.retrieveOption(argc,argv);
80 threshold_opt.retrieveOption(argc,argv);
81 ogrformat_opt.retrieveOption(argc,argv);
82 ftype_opt.retrieveOption(argc,argv);
83 ltype_opt.retrieveOption(argc,argv);
84 polygon_opt.retrieveOption(argc,argv);
85 band_opt.retrieveOption(argc,argv);
86 rule_opt.retrieveOption(argc,argv);
87 bndnodata_opt.retrieveOption(argc,argv);
88 srcnodata_opt.retrieveOption(argc,argv);
89 polythreshold_opt.retrieveOption(argc,argv);
90 test_opt.retrieveOption(argc,argv);
91 fieldname_opt.retrieveOption(argc,argv);
92 label_opt.retrieveOption(argc,argv);
93 geo_opt.retrieveOption(argc,argv);
94 down_opt.retrieveOption(argc,argv);
95 buffer_opt.retrieveOption(argc,argv);
96 disc_opt.retrieveOption(argc,argv);
99 verbose_opt.retrieveOption(argc,argv);
101 catch(
string predefinedString){
102 std::cout << predefinedString << std::endl;
106 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
110 std::map<std::string, rule::RULE_TYPE> ruleMap;
112 ruleMap[
"point"]=rule::point;
113 ruleMap[
"centroid"]=rule::centroid;
114 ruleMap[
"mean"]=rule::mean;
115 ruleMap[
"stdev"]=rule::stdev;
116 ruleMap[
"median"]=rule::median;
117 ruleMap[
"proportion"]=rule::proportion;
118 ruleMap[
"min"]=rule::min;
119 ruleMap[
"max"]=rule::max;
120 ruleMap[
"custom"]=rule::custom;
121 ruleMap[
"mode"]=rule::mode;
122 ruleMap[
"sum"]=rule::sum;
124 if(srcnodata_opt.size()){
125 while(srcnodata_opt.size()<bndnodata_opt.size())
126 srcnodata_opt.push_back(srcnodata_opt[0]);
127 while(bndnodata_opt.size()<srcnodata_opt.size())
128 bndnodata_opt.push_back(bndnodata_opt[0]);
132 std::cout << class_opt << std::endl;
135 unsigned long int nsample=0;
136 unsigned long int ntotalvalid=0;
137 unsigned long int ntotalinvalid=0;
138 vector<unsigned long int> nvalid(class_opt.size());
139 vector<unsigned long int> ninvalid(class_opt.size());
140 for(
int it=0;it<nvalid.size();++it){
146 if(image_opt.empty()){
147 std::cerr <<
"No image dataset provided (use option -i). Use --help for help information";
150 if(output_opt.empty()){
151 std::cerr <<
"No output dataset provided (use option -o). Use --help for help information";
155 imgReader.open(image_opt[0]);
157 catch(std::string errorstring){
158 std::cout << errorstring << std::endl;
162 int nband=(band_opt.size()) ? band_opt.size() : imgReader.nrOfBand();
164 if(fieldname_opt.size()<nband){
165 std::string bandString=fieldname_opt[0];
166 fieldname_opt.clear();
167 fieldname_opt.resize(nband);
168 for(
int iband=0;iband<nband;++iband){
169 int theBand=(band_opt.size()) ? band_opt[iband] : iband;
171 fs << bandString << theBand;
172 fieldname_opt[iband]=fs.str();
177 std::cout << fieldname_opt << std::endl;
180 std::cout <<
"Number of bands in input image: " << imgReader.nrOfBand() << std::endl;
182 OGRFieldType fieldType;
183 OGRFieldType labelType;
184 int ogr_typecount=11;
186 std::cout <<
"field and label types can be: ";
187 for(
int iType = 0; iType < ogr_typecount; ++iType){
189 std::cout <<
" " << OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType);
190 if( OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType) != NULL
191 && EQUAL(OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType),
192 ftype_opt[0].c_str()))
193 fieldType=(OGRFieldType) iType;
194 if( OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType) != NULL
195 && EQUAL(OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType),
196 ltype_opt[0].c_str()))
197 labelType=(OGRFieldType) iType;
205 std::cout << std::endl <<
"field type is: " << OGRFieldDefn::GetFieldTypeName(fieldType) << std::endl;
208 cerr <<
"field type " << OGRFieldDefn::GetFieldTypeName(fieldType) <<
" not supported" << std::endl;
218 std::cout << std::endl <<
"label type is: " << OGRFieldDefn::GetFieldTypeName(labelType) << std::endl;
221 cerr <<
"label type " << OGRFieldDefn::GetFieldTypeName(labelType) <<
" not supported" << std::endl;
226 const char* pszMessage;
227 void* pProgressArg=NULL;
228 GDALProgressFunc pfnProgress=GDALTermProgress;
232 bool sampleIsRaster=
false;
233 bool sampleIsVirtual=
false;
238 if(sample_opt.size()){
240 sampleReaderOgr.open(sample_opt[0]);
242 catch(
string errorString){
247 sampleWriterOgr.open(
"/vsimem/sample",ogrformat_opt[0]);
248 char **papszOptions=NULL;
249 sampleWriterOgr.createLayer(
"points", imgReader.getProjection(), wkbPoint, papszOptions);
250 sampleIsVirtual=
true;
255 if(random_opt.size()){
258 double ulx,uly,lrx,lry;
259 imgReader.getBoundingBox(ulx,uly,lrx,lry);
260 for(
unsigned int ipoint=1;ipoint<=random_opt[0];++ipoint){
261 OGRFeature *pointFeature;
262 pointFeature=sampleWriterOgr.createFeature();
264 double theX=ulx+
static_cast<double>(rand())/(RAND_MAX)*(lrx-ulx);
265 double theY=uly-
static_cast<double>(rand())/(RAND_MAX)*(uly-lry);
268 pointFeature->SetGeometry( &pt );
269 if(sampleWriterOgr.createFeature(pointFeature) != OGRERR_NONE ){
270 cerr <<
"Failed to create feature in shapefile" << endl;
273 OGRFeature::DestroyFeature(pointFeature);
276 else if(grid_opt.size()){
279 double ulx,uly,lrx,lry;
280 imgReader.getBoundingBox(ulx,uly,lrx,lry);
281 unsigned int ipoint=0;
282 for(
double theY=uly-grid_opt[0]/2;theY>lry;theY-=grid_opt[0]){
283 for(
double theX=ulx+grid_opt[0]/2;theX<lrx;theX+=grid_opt[0]){
285 cout <<
"position: " << theX <<
" " << theY << endl;
286 OGRFeature *pointFeature;
287 pointFeature=sampleWriterOgr.createFeature();
291 pointFeature->SetGeometry( &pt );
292 if(sampleWriterOgr.createFeature(pointFeature) != OGRERR_NONE ){
293 cerr <<
"Failed to create feature in shapefile" << endl;
296 OGRFeature::DestroyFeature(pointFeature);
301 std::cerr <<
"No sample dataset provided (use option -s). Use --help for help information";
304 sampleReaderOgr.open(
"/vsimem/sample");
308 if(class_opt.empty()){
312 assert(sample_opt.size());
313 classReader.open(sample_opt[0]);
315 vector<double> classBuffer(classReader.nrOfCol());
317 vector<double> sample(2+nband);
320 vector<double> writeBufferClass;
321 vector<int> selectedClass;
327 std::cout <<
"extracting sample from image..." << std::endl;
329 pfnProgress(progress,pszMessage,pProgressArg);
330 for(irow=0;irow<classReader.nrOfRow();++irow){
334 classReader.readData(classBuffer,GDT_Float64,irow);
337 for(icol=0;icol<classReader.nrOfCol();++icol){
341 double theClass=classBuffer[icol];
362 classReader.image2geo(icol,irow,x,y);
365 if(verbose_opt[0]>1){
366 std::cout.precision(12);
367 std::cout << theClass <<
" " << x <<
" " << y << std::endl;
370 imgReader.geo2image(x,y,iimg,jimg);
372 jimg=
static_cast<int>(jimg);
373 iimg=
static_cast<int>(iimg);
374 if(static_cast<int>(iimg)<0||
static_cast<int>(iimg)>=imgReader.nrOfCol())
383 if(static_cast<int>(jimg)<0||
static_cast<int>(jimg)>=imgReader.nrOfRow())
388 if(static_cast<int>(jimg)!=
static_cast<int>(oldimgrow)){
389 assert(imgBuffer.size()==nband);
390 for(
int iband=0;iband<nband;++iband){
391 int theBand=(band_opt.size()) ? band_opt[iband] : iband;
392 imgReader.readData(imgBuffer[iband],GDT_Float64,static_cast<int>(jimg),theBand);
393 assert(imgBuffer[iband].size()==imgReader.nrOfCol());
394 if(srcnodata_opt.size()){
395 vector<int>::const_iterator bndit=find(bndnodata_opt.begin(),bndnodata_opt.end(),theBand);
396 if(bndit!=bndnodata_opt.end()){
397 vector<int>::const_iterator bndit=find(bndnodata_opt.begin(),bndnodata_opt.end(),theBand);
398 if(bndit!=bndnodata_opt.end()){
399 if(imgBuffer[iband][static_cast<int>(iimg)]==srcnodata_opt[theBand])
409 for(
int iband=0;iband<imgBuffer.size();++iband){
410 if(imgBuffer[iband].size()!=imgReader.nrOfCol()){
411 std::cout <<
"Error in band " << iband <<
": " << imgBuffer[iband].size() <<
"!=" << imgReader.nrOfCol() << std::endl;
412 assert(imgBuffer[iband].size()==imgReader.nrOfCol());
414 sample[iband+2]=imgBuffer[iband][
static_cast<int>(iimg)];
416 float theThreshold=(threshold_opt.size()>1)?threshold_opt[processClass]:threshold_opt[0];
418 double p=
static_cast<double>(rand())/(RAND_MAX);
423 else if(nvalid.size()>processClass){
424 if(nvalid[processClass]>-theThreshold)
427 writeBuffer.push_back(sample);
428 writeBufferClass.push_back(theClass);
430 if(nvalid.size()>processClass)
431 ++(nvalid[processClass]);
435 if(ninvalid.size()>processClass)
436 ++(ninvalid[processClass]);
440 progress=
static_cast<float>(irow+1.0)/classReader.nrOfRow();
441 pfnProgress(progress,pszMessage,pProgressArg);
444 pfnProgress(progress,pszMessage,pProgressArg);
445 if(writeBuffer.size()>0){
446 assert(ntotalvalid==writeBuffer.size());
448 std::cout <<
"creating image sample writer " << output_opt[0] <<
" with " << writeBuffer.size() <<
" samples (" << ntotalinvalid <<
" invalid)" << std::endl;
449 ogrWriter.open(output_opt[0],ogrformat_opt[0]);
450 char **papszOptions=NULL;
451 ostringstream slayer;
452 slayer <<
"training data";
453 std::string layername=slayer.str();
454 ogrWriter.createLayer(layername, imgReader.getProjection(), wkbPoint, papszOptions);
455 std::string fieldname=
"fid";
456 ogrWriter.createField(fieldname,OFTInteger);
457 map<std::string,double> pointAttributes;
458 ogrWriter.createField(label_opt[0],labelType);
459 for(
int iband=0;iband<nband;++iband){
460 int theBand=(band_opt.size()) ? band_opt[iband] : iband;
461 ogrWriter.createField(fieldname_opt[iband],fieldType);
463 std::cout <<
"writing sample to " << output_opt[0] <<
"..." << std::endl;
465 pfnProgress(progress,pszMessage,pProgressArg);
466 for(
int isample=0;isample<writeBuffer.size();++isample){
468 std::cout <<
"writing sample " << isample << std::endl;
469 pointAttributes[label_opt[0]]=writeBufferClass[isample];
470 for(
int iband=0;iband<writeBuffer[0].size()-2;++iband){
471 int theBand=(band_opt.size()) ? band_opt[iband] : iband;
478 pointAttributes[fieldname_opt[iband]]=writeBuffer[isample][iband+2];
481 std::cout <<
"all bands written" << std::endl;
482 ogrWriter.addPoint(writeBuffer[isample][0],writeBuffer[isample][1],pointAttributes,fieldname,isample);
483 progress=
static_cast<float>(isample+1.0)/writeBuffer.size();
484 pfnProgress(progress,pszMessage,pProgressArg);
489 std::cout <<
"No data found for any class " << std::endl;
492 nsample=writeBuffer.size();
494 std::cout <<
"total number of samples written: " << nsample << std::endl;
497 assert(class_opt[0]);
499 assert(threshold_opt.size()==1||threshold_opt.size()==class_opt.size());
502 if(verbose_opt[0]>1){
503 std::cout <<
"reading position from sample dataset " << std::endl;
504 std::cout <<
"class thresholds: " << std::endl;
505 for(
int iclass=0;iclass<class_opt.size();++iclass){
506 if(threshold_opt.size()>1)
507 std::cout << class_opt[iclass] <<
": " << threshold_opt[iclass] << std::endl;
509 std::cout << class_opt[iclass] <<
": " << threshold_opt[0] << std::endl;
512 classReader.open(sample_opt[0]);
513 vector<int> classBuffer(classReader.nrOfCol());
516 vector<double> sample(2+nband);
518 vector<int> writeBufferClass;
520 vector<int> selectedClass;
526 std::cout <<
"extracting sample from image..." << std::endl;
528 pfnProgress(progress,pszMessage,pProgressArg);
529 for(irow=0;irow<classReader.nrOfRow();++irow){
532 classReader.readData(classBuffer,GDT_Int32,irow);
536 for(icol=0;icol<classReader.nrOfCol();++icol){
542 if(class_opt.empty()){
543 if(classBuffer[icol]){
545 theClass=classBuffer[icol];
549 for(
int iclass=0;iclass<class_opt.size();++iclass){
550 if(classBuffer[icol]==class_opt[iclass]){
552 theClass=class_opt[iclass];
559 classReader.image2geo(icol,irow,x,y);
562 if(verbose_opt[0]>1){
563 std::cout.precision(12);
564 std::cout << theClass <<
" " << x <<
" " << y << std::endl;
567 imgReader.geo2image(x,y,iimg,jimg);
569 jimg=
static_cast<int>(jimg);
570 iimg=
static_cast<int>(iimg);
571 if(static_cast<int>(iimg)<0||
static_cast<int>(iimg)>=imgReader.nrOfCol())
580 if(static_cast<int>(jimg)<0||
static_cast<int>(jimg)>=imgReader.nrOfRow())
585 if(static_cast<int>(jimg)!=
static_cast<int>(oldimgrow)){
586 assert(imgBuffer.size()==nband);
587 for(
int iband=0;iband<nband;++iband){
588 int theBand=(band_opt.size()) ? band_opt[iband] : iband;
589 imgReader.readData(imgBuffer[iband],GDT_Float64,static_cast<int>(jimg),theBand);
590 assert(imgBuffer[iband].size()==imgReader.nrOfCol());
591 if(srcnodata_opt.size()){
592 vector<int>::const_iterator bndit=find(bndnodata_opt.begin(),bndnodata_opt.end(),theBand);
593 if(bndit!=bndnodata_opt.end()){
594 if(imgBuffer[iband][static_cast<int>(iimg)]==srcnodata_opt[theBand])
602 for(
int iband=0;iband<imgBuffer.size();++iband){
603 if(imgBuffer[iband].size()!=imgReader.nrOfCol()){
604 std::cout <<
"Error in band " << iband <<
": " << imgBuffer[iband].size() <<
"!=" << imgReader.nrOfCol() << std::endl;
605 assert(imgBuffer[iband].size()==imgReader.nrOfCol());
607 sample[iband+2]=imgBuffer[iband][
static_cast<int>(iimg)];
609 float theThreshold=(threshold_opt.size()>1)?threshold_opt[processClass]:threshold_opt[0];
611 double p=
static_cast<double>(rand())/(RAND_MAX);
616 else if(nvalid.size()>processClass){
617 if(nvalid[processClass]>-theThreshold)
620 writeBuffer.push_back(sample);
622 writeBufferClass.push_back(theClass);
624 if(nvalid.size()>processClass)
625 ++(nvalid[processClass]);
629 if(ninvalid.size()>processClass)
630 ++(ninvalid[processClass]);
634 progress=
static_cast<float>(irow+1.0)/classReader.nrOfRow();
635 pfnProgress(progress,pszMessage,pProgressArg);
637 if(writeBuffer.size()>0){
638 assert(ntotalvalid==writeBuffer.size());
640 std::cout <<
"creating image sample writer " << output_opt[0] <<
" with " << writeBuffer.size() <<
" samples (" << ntotalinvalid <<
" invalid)" << std::endl;
641 ogrWriter.open(output_opt[0],ogrformat_opt[0]);
642 char **papszOptions=NULL;
643 ostringstream slayer;
644 slayer <<
"training data";
645 std::string layername=slayer.str();
646 ogrWriter.createLayer(layername, imgReader.getProjection(), wkbPoint, papszOptions);
647 std::string fieldname=
"fid";
648 ogrWriter.createField(fieldname,OFTInteger);
649 map<std::string,double> pointAttributes;
651 ogrWriter.createField(label_opt[0],labelType);
652 for(
int iband=0;iband<nband;++iband){
653 int theBand=(band_opt.size()) ? band_opt[iband] : iband;
660 ogrWriter.createField(fieldname_opt[iband],fieldType);
662 pfnProgress(progress,pszMessage,pProgressArg);
663 std::cout <<
"writing sample to " << output_opt[0] <<
"..." << std::endl;
665 pfnProgress(progress,pszMessage,pProgressArg);
666 for(
int isample=0;isample<writeBuffer.size();++isample){
667 pointAttributes[label_opt[0]]=writeBufferClass[isample];
668 for(
int iband=0;iband<writeBuffer[0].size()-2;++iband){
669 int theBand=(band_opt.size()) ? band_opt[iband] : iband;
676 pointAttributes[fieldname_opt[iband]]=writeBuffer[isample][iband+2];
678 ogrWriter.addPoint(writeBuffer[isample][0],writeBuffer[isample][1],pointAttributes,fieldname,isample);
679 progress=
static_cast<float>(isample+1.0)/writeBuffer.size();
680 pfnProgress(progress,pszMessage,pProgressArg);
685 std::cout <<
"No data found for any class " << std::endl;
688 nsample=writeBuffer.size();
690 std::cout <<
"total number of samples written: " << nsample << std::endl;
691 if(nvalid.size()==class_opt.size()){
692 for(
int iclass=0;iclass<class_opt.size();++iclass)
693 std::cout <<
"class " << class_opt[iclass] <<
" has " << nvalid[iclass] <<
" samples" << std::endl;
700 std::cout <<
"creating image sample writer " << output_opt[0] << std::endl;
703 ogrWriter.open(output_opt[0],ogrformat_opt[0]);
706 std::cout <<
"creating image test writer " << test_opt[0] << std::endl;
707 ogrTestWriter.open(test_opt[0],ogrformat_opt[0]);
711 int nlayerRead=sampleReaderOgr.getDataSource()->GetLayerCount();
714 std::cout <<
"number of layers: " << nlayerRead << endl;
716 for(
int ilayer=0;ilayer<nlayerRead;++ilayer){
717 OGRLayer *readLayer=sampleReaderOgr.getLayer(ilayer);
718 string currentLayername=readLayer->GetName();
720 if(find(layer_opt.begin(),layer_opt.end(),currentLayername)==layer_opt.end())
722 cout <<
"processing layer " << currentLayername << endl;
724 readLayer->ResetReading();
725 OGRLayer *writeLayer;
726 OGRLayer *writeTestLayer;
730 std::cout <<
"create polygons" << std::endl;
731 char **papszOptions=NULL;
732 writeLayer=ogrWriter.createLayer(readLayer->GetName(), imgReader.getProjection(), wkbPolygon, papszOptions);
734 writeTestLayer=ogrTestWriter.createLayer(readLayer->GetName(), imgReader.getProjection(), wkbPolygon, papszOptions);
738 std::cout <<
"create points in layer " << readLayer->GetName() << std::endl;
739 char **papszOptions=NULL;
741 writeLayer=ogrWriter.createLayer(readLayer->GetName(), imgReader.getProjection(), wkbPoint, papszOptions);
743 char **papszOptions=NULL;
744 writeTestLayer=ogrTestWriter.createLayer(readLayer->GetName(), imgReader.getProjection(), wkbPoint, papszOptions);
748 std::cout <<
"copy fields from layer " << ilayer << std::flush << std::endl;
749 ogrWriter.copyFields(sampleReaderOgr,ilayer,ilayerWrite);
753 std::cout <<
"copy fields test writer" << std::flush << std::endl;
754 ogrTestWriter.copyFields(sampleReaderOgr,ilayer,ilayerWrite);
763 if(class_opt.size()){
764 switch(ruleMap[rule_opt[0]]){
765 case(rule::proportion):{
766 for(
int iclass=0;iclass<class_opt.size();++iclass){
768 cs << class_opt[iclass];
769 ogrWriter.createField(cs.str(),fieldType,ilayerWrite);
775 ogrWriter.createField(label_opt[0],fieldType,ilayerWrite);
777 ogrTestWriter.createField(label_opt[0],fieldType,ilayerWrite);
782 for(
int iband=0;iband<nband;++iband){
783 int theBand=(band_opt.size()) ? band_opt[iband] : iband;
785 fs << fieldname_opt[iband];
787 std::cout <<
"creating field " << fs.str() << std::endl;
789 ogrWriter.createField(fs.str(),fieldType,ilayerWrite);
791 ogrTestWriter.createField(fs.str(),fieldType,ilayerWrite);
794 OGRFeature *readFeature;
795 unsigned long int ifeature=0;
796 unsigned long int nfeature=sampleReaderOgr.getFeatureCount();
798 pfnProgress(progress,pszMessage,pProgressArg);
799 while( (readFeature = readLayer->GetNextFeature()) != NULL ){
800 bool validFeature=
false;
801 bool writeTest=
false;
803 std::cout <<
"reading feature " << readFeature->GetFID() << std::endl;
804 if(threshold_opt[0]>0){
805 double p=
static_cast<double>(rand())/(RAND_MAX);
807 if(p>threshold_opt[0]){
815 if(ntotalvalid>-threshold_opt[0]){
823 std::cout <<
"processing feature " << readFeature->GetFID() << std::endl;
826 OGRGeometry *poGeometry;
827 poGeometry = readFeature->GetGeometryRef();
828 assert(poGeometry!=NULL);
830 if(wkbFlatten(poGeometry->getGeometryType()) == wkbPoint ){
832 if(!buffer_opt.size()){
833 switch(ruleMap[rule_opt[0]]){
835 case(rule::centroid):
836 buffer_opt.push_back(1);
839 buffer_opt.push_back(3);
844 std::cout <<
"boundary: " << buffer_opt[0] << std::endl;
846 OGRPolygon writePolygon;
847 OGRLinearRing writeRing;
848 OGRPoint writeCentroidPoint;
849 OGRFeature *writePolygonFeature;
850 OGRFeature *writeCentroidFeature;
852 OGRPoint *poPoint = (OGRPoint *) poGeometry;
853 writeCentroidPoint=*poPoint;
858 double i_centre,j_centre;
860 imgReader.geo2image(x,y,i_centre,j_centre);
866 j_centre=
static_cast<int>(j_centre);
867 i_centre=
static_cast<int>(i_centre);
869 double uli=i_centre-buffer_opt[0]/2;
870 double ulj=j_centre-buffer_opt[0]/2;
871 double lri=i_centre+buffer_opt[0]/2;
872 double lrj=j_centre+buffer_opt[0]/2;
879 ulj=
static_cast<int>(ulj);
880 uli=
static_cast<int>(uli);
881 lrj=
static_cast<int>(lrj);
882 lri=
static_cast<int>(lri);
884 if((polygon_opt[0]&&ruleMap[rule_opt[0]]==rule::point)||(ruleMap[rule_opt[0]]==rule::centroid)){
892 if(static_cast<int>(ulj)<0||
static_cast<int>(ulj)>=imgReader.nrOfRow())
895 if(static_cast<int>(uli)<0||
static_cast<int>(lri)>=imgReader.nrOfCol())
898 OGRPoint ulPoint,urPoint,llPoint,lrPoint;
905 double radius=buffer_opt[0]/2.0*sqrt(imgReader.getDeltaX()*imgReader.getDeltaY());
906 unsigned short nstep = 25;
907 for(
int i=0;i<nstep;++i){
909 aPoint.setX(x+radius*cos(2*PI*i/nstep));
910 aPoint.setY(y+radius*sin(2*PI*i/nstep));
911 writeRing.addPoint(&aPoint);
913 writePolygon.addRing(&writeRing);
914 writePolygon.closeRings();
919 imgReader.image2geo(uli,ulj,ulx,uly);
920 imgReader.image2geo(lri,lrj,lrx,lry);
921 ulPoint.setX(ulx-imgReader.getDeltaX()/2.0);
922 ulPoint.setY(uly+imgReader.getDeltaY()/2.0);
923 lrPoint.setX(lrx+imgReader.getDeltaX()/2.0);
924 lrPoint.setY(lry-imgReader.getDeltaY()/2.0);
925 urPoint.setX(lrx+imgReader.getDeltaX()/2.0);
926 urPoint.setY(uly+imgReader.getDeltaY()/2.0);
927 llPoint.setX(ulx-imgReader.getDeltaX()/2.0);
928 llPoint.setY(lry-imgReader.getDeltaY()/2.0);
930 writeRing.addPoint(&ulPoint);
931 writeRing.addPoint(&urPoint);
932 writeRing.addPoint(&lrPoint);
933 writeRing.addPoint(&llPoint);
934 writePolygon.addRing(&writeRing);
935 writePolygon.closeRings();
942 writePolygonFeature = OGRFeature::CreateFeature(writeTestLayer->GetLayerDefn());
944 writePolygonFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
946 else if(ruleMap[rule_opt[0]]!=rule::point){
948 writeCentroidFeature = OGRFeature::CreateFeature(writeTestLayer->GetLayerDefn());
950 writeCentroidFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
953 vector<double> windowClassValues;
955 if(class_opt.size()){
956 windowClassValues.resize(class_opt.size());
958 for(
int iclass=0;iclass<class_opt.size();++iclass)
959 windowClassValues[iclass]=0;
962 windowValues.resize(nband);
963 vector< Vector2d<double> > readValues(nband);
964 for(
int iband=0;iband<nband;++iband){
965 int theBand=(band_opt.size()) ? band_opt[iband] : iband;
968 assert(uli<imgReader.nrOfCol());
970 assert(lri<imgReader.nrOfCol());
972 assert(ulj<imgReader.nrOfRow());
974 assert(lrj<imgReader.nrOfRow());
975 imgReader.readDataBlock(readValues[iband],GDT_Float64,uli,lri,ulj,lrj,theBand);
979 for(
int j=ulj;j<=lrj;++j){
980 for(
int i=uli;i<=lri;++i){
982 if(i<0||i>=imgReader.nrOfCol())
984 if(j<0||j>=imgReader.nrOfRow())
989 imgReader.image2geo(i,j,theX,theY);
993 if(disc_opt[0]&&buffer_opt[0]>1){
994 double radius=buffer_opt[0]/2.0*sqrt(imgReader.getDeltaX()*imgReader.getDeltaY());
995 if((theX-x)*(theX-x)+(theY-y)*(theY-y)>radius*radius)
1000 if(srcnodata_opt.size()){
1001 for(
int vband=0;vband<bndnodata_opt.size();++vband){
1002 double value=((readValues[bndnodata_opt[vband]])[j-ulj])[i-uli];
1003 if(value==srcnodata_opt[vband]){
1018 OGRFeature *writePointFeature;
1019 if(!polygon_opt[0]){
1021 if(ruleMap[rule_opt[0]]==rule::point){
1023 writePointFeature = OGRFeature::CreateFeature(writeTestLayer->GetLayerDefn());
1025 writePointFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
1026 if(verbose_opt[0]>1)
1027 std::cout <<
"copying fields from polygons " << std::endl;
1028 if(writePointFeature->SetFrom(readFeature)!= OGRERR_NONE)
1029 cerr <<
"writing feature failed" << std::endl;
1030 writePointFeature->SetGeometry(&thePoint);
1031 OGRGeometry *updateGeometry;
1032 updateGeometry = writePointFeature->GetGeometryRef();
1033 OGRPoint *poPoint = (OGRPoint *) updateGeometry;
1034 if(verbose_opt[0]>1)
1035 std::cout <<
"write feature has " << writePointFeature->GetFieldCount() <<
" fields" << std::endl;
1038 if(class_opt.size()){
1039 short value=((readValues[0])[j-ulj])[i-uli];
1040 for(
int iclass=0;iclass<class_opt.size();++iclass){
1041 if(value==class_opt[iclass])
1042 windowClassValues[iclass]+=1;
1046 for(
int iband=0;iband<nband;++iband){
1047 int theBand=(band_opt.size()) ? band_opt[iband] : iband;
1049 assert(j-ulj<readValues[iband].size());
1051 assert(i-uli<((readValues[iband])[j-ulj]).size());
1052 double value=((readValues[iband])[j-ulj])[i-uli];
1054 if(verbose_opt[0]>1)
1055 std::cout <<
": " << value << std::endl;
1056 if(polygon_opt[0]||ruleMap[rule_opt[0]]!=rule::point){
1057 windowValues[iband].push_back(value);
1060 if(verbose_opt[0]>1)
1061 std::cout <<
"set field " << fieldname_opt[iband] <<
" to " << value << std::endl;
1062 switch( fieldType ){
1065 writePointFeature->SetField(fieldname_opt[iband].c_str(),value);
1068 writePointFeature->SetField(fieldname_opt[iband].c_str(),type2string<double>(value).c_str());
1077 if(!polygon_opt[0]){
1078 if(ruleMap[rule_opt[0]]==rule::point){
1080 if(verbose_opt[0]>1)
1081 std::cout <<
"creating point feature" << std::endl;
1083 if(writeTestLayer->CreateFeature( writePointFeature ) != OGRERR_NONE ){
1084 std::string errorString=
"Failed to create feature in test ogr vector dataset";
1089 if(writeLayer->CreateFeature( writePointFeature ) != OGRERR_NONE ){
1090 std::string errorString=
"Failed to create feature in ogr vector dataset";
1095 OGRFeature::DestroyFeature( writePointFeature );
1098 std::cout <<
"ntotalvalid(2): " << ntotalvalid << std::endl;
1103 if(polygon_opt[0]||ruleMap[rule_opt[0]]!=rule::point){
1107 cout <<
"no points found in window, continuing" << endl;
1115 if(writePolygonFeature->SetFrom(readFeature)!= OGRERR_NONE)
1116 cerr <<
"writing feature failed" << std::endl;
1117 writePolygonFeature->SetGeometry(&writePolygon);
1118 if(verbose_opt[0]>1)
1119 std::cout <<
"copying new fields write polygon " << std::endl;
1120 if(verbose_opt[0]>1)
1121 std::cout <<
"write feature has " << writePolygonFeature->GetFieldCount() <<
" fields" << std::endl;
1126 if(verbose_opt[0]>1)
1127 std::cout <<
"copying fields from polygons " << std::endl;
1128 if(writeCentroidFeature->SetFrom(readFeature)!= OGRERR_NONE)
1129 cerr <<
"writing feature failed" << std::endl;
1130 writeCentroidFeature->SetGeometry(&writeCentroidPoint);
1131 OGRGeometry *updateGeometry;
1132 updateGeometry = writeCentroidFeature->GetGeometryRef();
1133 assert(wkbFlatten(updateGeometry->getGeometryType()) == wkbPoint );
1134 if(verbose_opt[0]>1)
1135 std::cout <<
"write feature has " << writeCentroidFeature->GetFieldCount() <<
" fields" << std::endl;
1137 if(class_opt.empty()){
1138 if(ruleMap[rule_opt[0]]==rule::point){
1140 std::cout <<
"number of points in window: " << nPointWindow << std::endl;
1141 for(
int index=0;index<windowValues.size();++index){
1143 if(windowValues[index].size()!=1){
1144 cerr <<
"Error: windowValues[index].size()=" << windowValues[index].size() << endl;
1145 assert(windowValues[index].size()==1);
1147 double theValue=windowValues[index].back();
1150 std::cout <<
"number of points in window: " << nPointWindow << std::endl;
1151 int theBand=(band_opt.size()) ? band_opt[index] : index;
1153 if(verbose_opt[0]>1)
1154 std::cout <<
"set field " << fieldname_opt[index] <<
" to " << theValue << std::endl;
1155 switch( fieldType ){
1159 writePolygonFeature->SetField(fieldname_opt[index].c_str(),theValue);
1161 writeCentroidFeature->SetField(fieldname_opt[index].c_str(),theValue);
1165 writePolygonFeature->SetField(fieldname_opt[index].c_str(),type2string<double>(theValue).c_str());
1167 writeCentroidFeature->SetField(fieldname_opt[index].c_str(),type2string<double>(theValue).c_str());
1170 std::cout <<
"field type not supported yet..." << std::endl;
1177 for(
int index=0;index<windowValues.size();++index){
1178 if(windowValues[index].size()!=buffer_opt[0]*buffer_opt[0]){
1179 cerr <<
"Error: windowValues[index].size()=" << windowValues[index].size() << endl;
1181 if(ruleMap[rule_opt[0]]==rule::mean)
1182 theValue=stat.mean(windowValues[index]);
1183 else if(ruleMap[rule_opt[0]]==rule::stdev)
1184 theValue=sqrt(stat.var(windowValues[index]));
1185 else if(ruleMap[rule_opt[0]]==rule::median)
1186 theValue=stat.median(windowValues[index]);
1187 else if(ruleMap[rule_opt[0]]==rule::sum)
1188 theValue=stat.sum(windowValues[index]);
1189 else if(ruleMap[rule_opt[0]]==rule::max)
1190 theValue=stat.mymax(windowValues[index]);
1191 else if(ruleMap[rule_opt[0]]==rule::min)
1192 theValue=stat.mymin(windowValues[index]);
1195 std::cout <<
"number of points in polygon: " << nPointWindow << std::endl;
1196 assert(nPointWindow<=1);
1197 assert(nPointWindow==windowValues[index].size());
1198 theValue=windowValues[index].back();
1200 if(verbose_opt[0]>1)
1201 std::cout <<
"set field " << fieldname_opt[index] <<
" to " << theValue << std::endl;
1202 switch( fieldType ){
1206 writePolygonFeature->SetField(fieldname_opt[index].c_str(),theValue);
1208 writeCentroidFeature->SetField(fieldname_opt[index].c_str(),theValue);
1212 writePolygonFeature->SetField(fieldname_opt[index].c_str(),type2string<double>(theValue).c_str());
1214 writeCentroidFeature->SetField(fieldname_opt[index].c_str(),type2string<double>(theValue).c_str());
1217 std::cout <<
"field type not supported yet..." << std::endl;
1224 if(ruleMap[rule_opt[0]]==rule::proportion){
1226 std::cout <<
"number of points in polygon: " << nPointWindow << std::endl;
1227 stat.normalize_pct(windowClassValues);
1228 for(
int index=0;index<windowClassValues.size();++index){
1229 double theValue=windowClassValues[index];
1231 fs << class_opt[index];
1233 writePolygonFeature->SetField(fs.str().c_str(),
static_cast<int>(theValue));
1235 writeCentroidFeature->SetField(fs.str().c_str(),
static_cast<int>(theValue));
1238 else if(ruleMap[rule_opt[0]]==rule::custom){
1239 assert(polygon_opt[0]);
1241 std::cout <<
"number of points in polygon: " << nPointWindow << std::endl;
1242 stat.normalize_pct(windowClassValues);
1243 assert(windowClassValues.size()==2);
1244 if(windowClassValues[0]>=75)
1245 writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(11));
1246 else if(windowClassValues[1]>=75)
1247 writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(12));
1248 else if(windowClassValues[0]>25&&windowClassValues[1]>25)
1249 writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(13));
1252 std::cout <<
"No valid value in windowClassValues..." << std::endl;
1253 for(
int index=0;index<windowClassValues.size();++index){
1254 double theValue=windowClassValues[index];
1255 std::cout << theValue <<
" ";
1257 std::cout << std::endl;
1259 writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(20));
1262 else if(ruleMap[rule_opt[0]]==rule::mode){
1265 std::cout <<
"number of points in window: " << nPointWindow << std::endl;
1267 int maxClass=stat.mymin(class_opt);
1268 vector<double>::iterator maxit;
1269 maxit=stat.mymax(windowClassValues,windowClassValues.begin(),windowClassValues.end());
1270 int maxIndex=distance(windowClassValues.begin(),maxit);
1271 maxClass=class_opt[maxIndex];
1272 if(verbose_opt[0]>0)
1273 std::cout <<
"maxClass: " << maxClass << std::endl;
1275 writePolygonFeature->SetField(label_opt[0].c_str(),maxClass);
1277 writeCentroidFeature->SetField(label_opt[0].c_str(),maxClass);
1281 if(verbose_opt[0]>1)
1282 std::cout <<
"creating polygon feature" << std::endl;
1284 if(writeTestLayer->CreateFeature( writePolygonFeature ) != OGRERR_NONE ){
1285 std::string errorString=
"Failed to create polygon feature in ogr vector dataset";
1290 if(writeLayer->CreateFeature( writePolygonFeature ) != OGRERR_NONE ){
1291 std::string errorString=
"Failed to create polygon feature in ogr vector dataset";
1295 OGRFeature::DestroyFeature( writePolygonFeature );
1298 std::cout <<
"ntotalvalid(1): " << ntotalvalid << std::endl;
1301 if(verbose_opt[0]>1)
1302 std::cout <<
"creating point feature in centroid" << std::endl;
1304 if(writeTestLayer->CreateFeature( writeCentroidFeature ) != OGRERR_NONE ){
1305 std::string errorString=
"Failed to create point feature in ogr vector dataset";
1311 assert(validFeature);
1312 if(writeLayer->CreateFeature( writeCentroidFeature ) != OGRERR_NONE ){
1313 std::string errorString=
"Failed to create point feature in ogr vector dataset";
1317 OGRFeature::DestroyFeature( writeCentroidFeature );
1320 std::cout <<
"ntotalvalid: " << ntotalvalid << std::endl;
1324 else if(wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon){
1326 OGRPolygon readPolygon = *((OGRPolygon *) poGeometry);
1327 OGRPolygon writePolygon;
1328 OGRLinearRing writeRing;
1329 OGRPoint writeCentroidPoint;
1330 OGRFeature *writePolygonFeature;
1331 OGRFeature *writeCentroidFeature;
1333 readPolygon.closeRings();
1335 if(verbose_opt[0]>1)
1336 std::cout <<
"get point on polygon" << std::endl;
1337 if(ruleMap[rule_opt[0]]==rule::centroid)
1338 readPolygon.Centroid(&writeCentroidPoint);
1340 readPolygon.PointOnSurface(&writeCentroidPoint);
1342 double ulx,uly,lrx,lry;
1343 double uli,ulj,lri,lrj;
1344 if((polygon_opt[0]&&ruleMap[rule_opt[0]]==rule::point)||(ruleMap[rule_opt[0]]==rule::centroid)){
1345 ulx=writeCentroidPoint.getX();
1346 uly=writeCentroidPoint.getY();
1353 std::cout <<
"reading envelope for polygon " << ifeature << std::endl;
1354 OGREnvelope* psEnvelope=
new OGREnvelope();
1355 readPolygon.getEnvelope(psEnvelope);
1356 ulx=psEnvelope->MinX;
1357 uly=psEnvelope->MaxY;
1358 lrx=psEnvelope->MaxX;
1359 lry=psEnvelope->MinY;
1363 imgReader.geo2image(ulx,uly,uli,ulj);
1364 imgReader.geo2image(lrx,lry,lri,lrj);
1373 ulj=
static_cast<int>(ulj);
1374 uli=
static_cast<int>(uli);
1375 lrj=
static_cast<int>(lrj);
1376 lri=
static_cast<int>(lri);
1378 if(verbose_opt[0]>1)
1379 std::cout <<
"bounding box for polygon feature " << ifeature <<
": " << uli <<
" " << ulj <<
" " << lri <<
" " << lrj << std::endl;
1385 if(uli>=imgReader.nrOfCol())
1386 uli=imgReader.nrOfCol()-1;
1387 if(lri>=imgReader.nrOfCol())
1388 lri=imgReader.nrOfCol()-1;
1393 if(ulj>=imgReader.nrOfRow())
1394 ulj=imgReader.nrOfRow()-1;
1395 if(lrj>=imgReader.nrOfRow())
1396 lrj=imgReader.nrOfRow()-1;
1400 int nPointPolygon=0;
1404 writePolygonFeature = OGRFeature::CreateFeature(writeTestLayer->GetLayerDefn());
1406 writePolygonFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
1408 else if(ruleMap[rule_opt[0]]!=rule::point){
1410 writeCentroidFeature = OGRFeature::CreateFeature(writeTestLayer->GetLayerDefn());
1412 writeCentroidFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
1416 vector<double> polyClassValues;
1418 if(class_opt.size()){
1420 polyClassValues.resize(class_opt.size());
1422 for(
int iclass=0;iclass<class_opt.size();++iclass)
1423 polyClassValues[iclass]=0;
1426 polyValues.resize(nband);
1427 vector< Vector2d<double> > readValues(nband);
1428 for(
int iband=0;iband<nband;++iband){
1429 int theBand=(band_opt.size()) ? band_opt[iband] : iband;
1432 assert(uli<imgReader.nrOfCol());
1434 assert(lri<imgReader.nrOfCol());
1436 assert(ulj<imgReader.nrOfRow());
1438 assert(lrj<imgReader.nrOfRow());
1439 imgReader.readDataBlock(readValues[iband],GDT_Float64,uli,lri,ulj,lrj,theBand);
1443 for(
int j=ulj;j<=lrj;++j){
1444 for(
int i=uli;i<=lri;++i){
1446 if(i<0||i>=imgReader.nrOfCol())
1448 if(j<0||j>=imgReader.nrOfRow())
1453 imgReader.image2geo(i,j,theX,theY);
1454 thePoint.setX(theX);
1455 thePoint.setY(theY);
1457 if(ruleMap[rule_opt[0]]!=rule::centroid&&!readPolygon.Contains(&thePoint))
1462 if(srcnodata_opt.size()){
1463 for(
int vband=0;vband<bndnodata_opt.size();++vband){
1464 double value=((readValues[bndnodata_opt[vband]])[j-ulj])[i-uli];
1465 if(value==srcnodata_opt[vband]){
1477 writeRing.addPoint(&thePoint);
1478 if(verbose_opt[0]>1)
1479 std::cout <<
"point is on surface:" << thePoint.getX() <<
"," << thePoint.getY() << std::endl;
1482 if(polythreshold_opt.size())
1483 if(nPointPolygon>polythreshold_opt[0])
1486 OGRFeature *writePointFeature;
1487 if(!polygon_opt[0]){
1489 if(ruleMap[rule_opt[0]]==rule::point){
1491 writePointFeature = OGRFeature::CreateFeature(writeTestLayer->GetLayerDefn());
1493 writePointFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
1494 if(verbose_opt[0]>1)
1495 std::cout <<
"copying fields from polygons " << std::endl;
1496 if(writePointFeature->SetFrom(readFeature)!= OGRERR_NONE)
1497 cerr <<
"writing feature failed" << std::endl;
1498 writePointFeature->SetGeometry(&thePoint);
1499 OGRGeometry *updateGeometry;
1500 updateGeometry = writePointFeature->GetGeometryRef();
1501 OGRPoint *poPoint = (OGRPoint *) updateGeometry;
1502 if(verbose_opt[0]>1)
1503 std::cout <<
"write feature has " << writePointFeature->GetFieldCount() <<
" fields" << std::endl;
1506 if(class_opt.size()){
1507 short value=((readValues[0])[j-ulj])[i-uli];
1508 for(
int iclass=0;iclass<class_opt.size();++iclass){
1509 if(value==class_opt[iclass])
1510 polyClassValues[iclass]+=1;
1514 for(
int iband=0;iband<nband;++iband){
1515 int theBand=(band_opt.size()) ? band_opt[iband] : iband;
1517 assert(j-ulj<readValues[iband].size());
1519 assert(i-uli<((readValues[iband])[j-ulj]).size());
1520 double value=((readValues[iband])[j-ulj])[i-uli];
1522 if(verbose_opt[0]>1)
1523 std::cout <<
": " << value << std::endl;
1524 if(polygon_opt[0]||ruleMap[rule_opt[0]]!=rule::point)
1525 polyValues[iband].push_back(value);
1527 if(verbose_opt[0]>1)
1528 std::cout <<
"set field " << fieldname_opt[iband] <<
" to " << value << std::endl;
1529 switch( fieldType ){
1532 writePointFeature->SetField(fieldname_opt[iband].c_str(),value);
1535 writePointFeature->SetField(fieldname_opt[iband].c_str(),type2string<double>(value).c_str());
1544 if(!polygon_opt[0]){
1545 if(ruleMap[rule_opt[0]]==rule::point){
1547 if(verbose_opt[0]>1)
1548 std::cout <<
"creating point feature" << std::endl;
1550 if(writeTestLayer->CreateFeature( writePointFeature ) != OGRERR_NONE ){
1551 std::string errorString=
"Failed to create feature in test ogr vector dataset";
1556 if(writeLayer->CreateFeature( writePointFeature ) != OGRERR_NONE ){
1557 std::string errorString=
"Failed to create feature in ogr vector dataset";
1562 OGRFeature::DestroyFeature( writePointFeature );
1565 std::cout <<
"ntotalvalid(2): " << ntotalvalid << std::endl;
1570 if(polygon_opt[0]||ruleMap[rule_opt[0]]!=rule::point){
1574 cout <<
"no points found in polygon, continuing" << endl;
1579 writePolygon.addRing(&writeRing);
1580 writePolygon.closeRings();
1582 if(writePolygonFeature->SetFrom(readFeature)!= OGRERR_NONE)
1583 cerr <<
"writing feature failed" << std::endl;
1584 writePolygonFeature->SetGeometry(&writePolygon);
1585 if(verbose_opt[0]>1)
1586 std::cout <<
"copying new fields write polygon " << std::endl;
1587 if(verbose_opt[0]>1)
1588 std::cout <<
"write feature has " << writePolygonFeature->GetFieldCount() <<
" fields" << std::endl;
1593 if(verbose_opt[0]>1)
1594 std::cout <<
"copying fields from polygons " << std::endl;
1595 if(writeCentroidFeature->SetFrom(readFeature)!= OGRERR_NONE)
1596 cerr <<
"writing feature failed" << std::endl;
1597 writeCentroidFeature->SetGeometry(&writeCentroidPoint);
1598 OGRGeometry *updateGeometry;
1599 updateGeometry = writeCentroidFeature->GetGeometryRef();
1600 assert(wkbFlatten(updateGeometry->getGeometryType()) == wkbPoint );
1601 if(verbose_opt[0]>1)
1602 std::cout <<
"write feature has " << writeCentroidFeature->GetFieldCount() <<
" fields" << std::endl;
1604 if(class_opt.empty()){
1605 if(ruleMap[rule_opt[0]]==rule::point){
1607 std::cout <<
"number of points in polygon: " << nPointPolygon << std::endl;
1608 for(
int index=0;index<polyValues.size();++index){
1610 assert(polyValues[index].size()==1);
1611 double theValue=polyValues[index].back();
1614 std::cout <<
"number of points in polygon: " << nPointPolygon << std::endl;
1615 int theBand=(band_opt.size()) ? band_opt[index] : index;
1617 if(verbose_opt[0]>1)
1618 std::cout <<
"set field " << fieldname_opt[index] <<
" to " << theValue << std::endl;
1619 switch( fieldType ){
1623 writePolygonFeature->SetField(fieldname_opt[index].c_str(),theValue);
1625 writeCentroidFeature->SetField(fieldname_opt[index].c_str(),theValue);
1629 writePolygonFeature->SetField(fieldname_opt[index].c_str(),type2string<double>(theValue).c_str());
1631 writeCentroidFeature->SetField(fieldname_opt[index].c_str(),type2string<double>(theValue).c_str());
1634 std::cout <<
"field type not supported yet..." << std::endl;
1641 for(
int index=0;index<polyValues.size();++index){
1642 if(ruleMap[rule_opt[0]]==rule::mean)
1643 theValue=stat.mean(polyValues[index]);
1644 else if(ruleMap[rule_opt[0]]==rule::stdev)
1645 theValue=sqrt(stat.var(polyValues[index]));
1646 else if(ruleMap[rule_opt[0]]==rule::median)
1647 theValue=stat.median(polyValues[index]);
1648 else if(ruleMap[rule_opt[0]]==rule::sum)
1649 theValue=stat.sum(polyValues[index]);
1650 else if(ruleMap[rule_opt[0]]==rule::max)
1651 theValue=stat.mymax(polyValues[index]);
1652 else if(ruleMap[rule_opt[0]]==rule::min)
1653 theValue=stat.mymin(polyValues[index]);
1656 std::cout <<
"number of points in polygon: " << nPointPolygon << std::endl;
1657 assert(nPointPolygon<=1);
1658 assert(nPointPolygon==polyValues[index].size());
1659 theValue=polyValues[index].back();
1661 if(verbose_opt[0]>1)
1662 std::cout <<
"set field " << fieldname_opt[index] <<
" to " << theValue << std::endl;
1663 switch( fieldType ){
1667 writePolygonFeature->SetField(fieldname_opt[index].c_str(),theValue);
1669 writeCentroidFeature->SetField(fieldname_opt[index].c_str(),theValue);
1673 writePolygonFeature->SetField(fieldname_opt[index].c_str(),type2string<double>(theValue).c_str());
1675 writeCentroidFeature->SetField(fieldname_opt[index].c_str(),type2string<double>(theValue).c_str());
1678 std::cout <<
"field type not supported yet..." << std::endl;
1685 if(ruleMap[rule_opt[0]]==rule::proportion){
1687 std::cout <<
"number of points in polygon: " << nPointPolygon << std::endl;
1688 stat.normalize_pct(polyClassValues);
1689 for(
int index=0;index<polyClassValues.size();++index){
1690 double theValue=polyClassValues[index];
1692 fs << class_opt[index];
1694 writePolygonFeature->SetField(fs.str().c_str(),
static_cast<int>(theValue));
1696 writeCentroidFeature->SetField(fs.str().c_str(),
static_cast<int>(theValue));
1699 else if(ruleMap[rule_opt[0]]==rule::custom){
1700 assert(polygon_opt[0]);
1702 std::cout <<
"number of points in polygon: " << nPointPolygon << std::endl;
1703 stat.normalize_pct(polyClassValues);
1704 assert(polyClassValues.size()==2);
1705 if(polyClassValues[0]>=75)
1706 writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(11));
1707 else if(polyClassValues[1]>=75)
1708 writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(12));
1709 else if(polyClassValues[0]>25&&polyClassValues[1]>25)
1710 writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(13));
1713 std::cout <<
"No valid value in polyClassValues..." << std::endl;
1714 for(
int index=0;index<polyClassValues.size();++index){
1715 double theValue=polyClassValues[index];
1716 std::cout << theValue <<
" ";
1718 std::cout << std::endl;
1720 writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(20));
1723 else if(ruleMap[rule_opt[0]]==rule::mode){
1726 std::cout <<
"number of points in polygon: " << nPointPolygon << std::endl;
1728 int maxClass=stat.mymin(class_opt);
1729 vector<double>::iterator maxit;
1730 maxit=stat.mymax(polyClassValues,polyClassValues.begin(),polyClassValues.end());
1731 int maxIndex=distance(polyClassValues.begin(),maxit);
1732 maxClass=class_opt[maxIndex];
1733 if(verbose_opt[0]>0)
1734 std::cout <<
"maxClass: " << maxClass << std::endl;
1736 writePolygonFeature->SetField(label_opt[0].c_str(),maxClass);
1738 writeCentroidFeature->SetField(label_opt[0].c_str(),maxClass);
1742 if(verbose_opt[0]>1)
1743 std::cout <<
"creating polygon feature" << std::endl;
1745 if(writeTestLayer->CreateFeature( writePolygonFeature ) != OGRERR_NONE ){
1746 std::string errorString=
"Failed to create polygon feature in ogr vector dataset";
1751 if(writeLayer->CreateFeature( writePolygonFeature ) != OGRERR_NONE ){
1752 std::string errorString=
"Failed to create polygon feature in ogr vector dataset";
1756 OGRFeature::DestroyFeature( writePolygonFeature );
1759 std::cout <<
"ntotalvalid(1): " << ntotalvalid << std::endl;
1762 if(verbose_opt[0]>1)
1763 std::cout <<
"creating point feature in centroid" << std::endl;
1765 if(writeTestLayer->CreateFeature( writeCentroidFeature ) != OGRERR_NONE ){
1766 std::string errorString=
"Failed to create point feature in ogr vector dataset";
1772 assert(validFeature);
1773 if(writeLayer->CreateFeature( writeCentroidFeature ) != OGRERR_NONE ){
1774 std::string errorString=
"Failed to create point feature in ogr vector dataset";
1778 OGRFeature::DestroyFeature( writeCentroidFeature );
1781 std::cout <<
"ntotalvalid: " << ntotalvalid << std::endl;
1785 else if(wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon){
1786 OGRMultiPolygon readPolygon = *((OGRMultiPolygon *) poGeometry);
1787 OGRPolygon writePolygon;
1788 OGRLinearRing writeRing;
1789 OGRPoint writeCentroidPoint;
1790 OGRFeature *writePolygonFeature;
1791 OGRFeature *writeCentroidFeature;
1793 readPolygon.closeRings();
1795 if(verbose_opt[0]>1)
1796 std::cout <<
"get centroid point from polygon" << std::endl;
1798 readPolygon.Centroid(&writeCentroidPoint);
1800 double ulx,uly,lrx,lry;
1801 double uli,ulj,lri,lrj;
1802 if((polygon_opt[0]&&ruleMap[rule_opt[0]]==rule::point)||(ruleMap[rule_opt[0]]==rule::centroid)){
1803 ulx=writeCentroidPoint.getX();
1804 uly=writeCentroidPoint.getY();
1811 std::cout <<
"reading envelope for polygon " << ifeature << std::endl;
1812 OGREnvelope* psEnvelope=
new OGREnvelope();
1813 readPolygon.getEnvelope(psEnvelope);
1814 ulx=psEnvelope->MinX;
1815 uly=psEnvelope->MaxY;
1816 lrx=psEnvelope->MaxX;
1817 lry=psEnvelope->MinY;
1821 imgReader.geo2image(ulx,uly,uli,ulj);
1822 imgReader.geo2image(lrx,lry,lri,lrj);
1831 ulj=
static_cast<int>(ulj);
1832 uli=
static_cast<int>(uli);
1833 lrj=
static_cast<int>(lrj);
1834 lri=
static_cast<int>(lri);
1836 if(verbose_opt[0]>1)
1837 std::cout <<
"bounding box for multipologon feature " << ifeature <<
": " << uli <<
" " << ulj <<
" " << lri <<
" " << lrj << std::endl;
1843 if(uli>=imgReader.nrOfCol())
1844 uli=imgReader.nrOfCol()-1;
1845 if(lri>=imgReader.nrOfCol())
1846 lri=imgReader.nrOfCol()-1;
1851 if(ulj>=imgReader.nrOfRow())
1852 ulj=imgReader.nrOfRow()-1;
1853 if(lrj>=imgReader.nrOfRow())
1854 lrj=imgReader.nrOfRow()-1;
1858 int nPointPolygon=0;
1861 writePolygonFeature = OGRFeature::CreateFeature(writeTestLayer->GetLayerDefn());
1863 writePolygonFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
1865 else if(ruleMap[rule_opt[0]]!=rule::point){
1867 writeCentroidFeature = OGRFeature::CreateFeature(writeTestLayer->GetLayerDefn());
1869 writeCentroidFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
1873 vector<double> polyClassValues;
1875 if(class_opt.size()){
1876 polyClassValues.resize(class_opt.size());
1878 for(
int iclass=0;iclass<class_opt.size();++iclass)
1879 polyClassValues[iclass]=0;
1882 polyValues.resize(nband);
1883 vector< Vector2d<double> > readValues(nband);
1884 for(
int iband=0;iband<nband;++iband){
1885 int theBand=(band_opt.size()) ? band_opt[iband] : iband;
1888 assert(uli<imgReader.nrOfCol());
1890 assert(lri<imgReader.nrOfCol());
1892 assert(ulj<imgReader.nrOfRow());
1894 assert(lrj<imgReader.nrOfRow());
1895 imgReader.readDataBlock(readValues[iband],GDT_Float64,uli,lri,ulj,lrj,theBand);
1899 for(
int j=ulj;j<=lrj;++j){
1900 for(
int i=uli;i<=lri;++i){
1902 if(i<0||i>=imgReader.nrOfCol())
1904 if(j<0||j>=imgReader.nrOfRow())
1909 imgReader.image2geo(i,j,theX,theY);
1910 thePoint.setX(theX);
1911 thePoint.setY(theY);
1913 if(ruleMap[rule_opt[0]]!=rule::centroid&&!readPolygon.Contains(&thePoint))
1918 if(srcnodata_opt.size()){
1919 for(
int vband=0;vband<bndnodata_opt.size();++vband){
1920 double value=((readValues[bndnodata_opt[vband]])[j-ulj])[i-uli];
1921 if(value==srcnodata_opt[vband]){
1933 writeRing.addPoint(&thePoint);
1934 if(verbose_opt[0]>1)
1935 std::cout <<
"point is on surface:" << thePoint.getX() <<
"," << thePoint.getY() << std::endl;
1938 if(polythreshold_opt.size())
1939 if(nPointPolygon>polythreshold_opt[0])
1942 OGRFeature *writePointFeature;
1943 if(!polygon_opt[0]){
1945 if(ruleMap[rule_opt[0]]==rule::point){
1947 writePointFeature = OGRFeature::CreateFeature(writeTestLayer->GetLayerDefn());
1949 writePointFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
1950 if(verbose_opt[0]>1)
1951 std::cout <<
"copying fields from polygons " << std::endl;
1952 if(writePointFeature->SetFrom(readFeature)!= OGRERR_NONE)
1953 cerr <<
"writing feature failed" << std::endl;
1954 writePointFeature->SetGeometry(&thePoint);
1955 OGRGeometry *updateGeometry;
1956 updateGeometry = writePointFeature->GetGeometryRef();
1957 OGRPoint *poPoint = (OGRPoint *) updateGeometry;
1958 if(verbose_opt[0]>1)
1959 std::cout <<
"write feature has " << writePointFeature->GetFieldCount() <<
" fields" << std::endl;
1962 if(class_opt.size()){
1963 short value=((readValues[0])[j-ulj])[i-uli];
1964 for(
int iclass=0;iclass<class_opt.size();++iclass){
1965 if(value==class_opt[iclass])
1966 polyClassValues[iclass]+=1;
1970 for(
int iband=0;iband<nband;++iband){
1973 assert(j-ulj<readValues[iband].size());
1975 assert(i-uli<((readValues[iband])[j-ulj]).size());
1976 double value=((readValues[iband])[j-ulj])[i-uli];
1978 if(verbose_opt[0]>1)
1979 std::cout <<
": " << value << std::endl;
1980 if(polygon_opt[0]||ruleMap[rule_opt[0]]!=rule::point)
1981 polyValues[iband].push_back(value);
1983 if(verbose_opt[0]>1)
1984 std::cout <<
"set field " << fieldname_opt[iband] <<
" to " << value << std::endl;
1985 switch( fieldType ){
1988 writePointFeature->SetField(fieldname_opt[iband].c_str(),value);
1991 writePointFeature->SetField(fieldname_opt[iband].c_str(),type2string<double>(value).c_str());
2011 if(!polygon_opt[0]){
2012 if(ruleMap[rule_opt[0]]==rule::point){
2014 if(verbose_opt[0]>1)
2015 std::cout <<
"creating point feature" << std::endl;
2017 if(writeTestLayer->CreateFeature( writePointFeature ) != OGRERR_NONE ){
2018 std::string errorString=
"Failed to create feature in ogr vector dataset";
2023 if(writeLayer->CreateFeature( writePointFeature ) != OGRERR_NONE ){
2024 std::string errorString=
"Failed to create feature in ogr vector dataset";
2029 OGRFeature::DestroyFeature( writePointFeature );
2035 std::cout <<
"ntotalvalid: " << ntotalvalid << std::endl;
2042 if(polygon_opt[0]||ruleMap[rule_opt[0]]!=rule::point){
2048 writePolygon.addRing(&writeRing);
2049 writePolygon.closeRings();
2051 if(writePolygonFeature->SetFrom(readFeature)!= OGRERR_NONE)
2052 cerr <<
"writing feature failed" << std::endl;
2053 writePolygonFeature->SetGeometry(&writePolygon);
2054 if(verbose_opt[0]>1)
2055 std::cout <<
"copying new fields write polygon " << std::endl;
2056 if(verbose_opt[0]>1)
2057 std::cout <<
"write feature has " << writePolygonFeature->GetFieldCount() <<
" fields" << std::endl;
2062 if(verbose_opt[0]>1)
2063 std::cout <<
"copying fields from polygons " << std::endl;
2064 if(writeCentroidFeature->SetFrom(readFeature)!= OGRERR_NONE)
2065 cerr <<
"writing feature failed" << std::endl;
2066 writeCentroidFeature->SetGeometry(&writeCentroidPoint);
2067 OGRGeometry *updateGeometry;
2068 updateGeometry = writeCentroidFeature->GetGeometryRef();
2069 assert(wkbFlatten(updateGeometry->getGeometryType()) == wkbPoint );
2070 if(verbose_opt[0]>1)
2071 std::cout <<
"write feature has " << writeCentroidFeature->GetFieldCount() <<
" fields" << std::endl;
2073 if(class_opt.empty()){
2074 if(ruleMap[rule_opt[0]]==rule::point){
2076 std::cout <<
"number of points in polygon: " << nPointPolygon << std::endl;
2077 for(
int index=0;index<polyValues.size();++index){
2079 assert(polyValues[index].size()==1);
2080 double theValue=polyValues[index].back();
2082 std::cout <<
"number of points in polygon: " << nPointPolygon << std::endl;
2083 int theBand=(band_opt.size()) ? band_opt[index] : index;
2085 if(verbose_opt[0]>1)
2086 std::cout <<
"set field " << fieldname_opt[index] <<
" to " << theValue << std::endl;
2087 switch( fieldType ){
2091 writePolygonFeature->SetField(fieldname_opt[index].c_str(),theValue);
2093 writeCentroidFeature->SetField(fieldname_opt[index].c_str(),theValue);
2097 writePolygonFeature->SetField(fieldname_opt[index].c_str(),type2string<double>(theValue).c_str());
2099 writeCentroidFeature->SetField(fieldname_opt[index].c_str(),type2string<double>(theValue).c_str());
2127 std::cout <<
"field type not supported yet..." << std::endl;
2134 for(
int index=0;index<polyValues.size();++index){
2135 if(ruleMap[rule_opt[0]]==rule::mean)
2136 theValue=stat.mean(polyValues[index]);
2137 else if(ruleMap[rule_opt[0]]==rule::stdev)
2138 theValue=sqrt(stat.var(polyValues[index]));
2139 else if(ruleMap[rule_opt[0]]==rule::median)
2140 theValue=stat.median(polyValues[index]);
2141 else if(ruleMap[rule_opt[0]]==rule::sum)
2142 theValue=stat.sum(polyValues[index]);
2143 else if(ruleMap[rule_opt[0]]==rule::max)
2144 theValue=stat.mymax(polyValues[index]);
2145 else if(ruleMap[rule_opt[0]]==rule::min)
2146 theValue=stat.mymin(polyValues[index]);
2149 std::cout <<
"number of points in polygon: " << nPointPolygon << std::endl;
2150 assert(nPointPolygon<=1);
2151 assert(nPointPolygon==polyValues[index].size());
2152 theValue=polyValues[index].back();
2154 if(verbose_opt[0]>1)
2155 std::cout <<
"set field " << fieldname_opt[index] <<
" to " << theValue << std::endl;
2156 switch( fieldType ){
2160 writePolygonFeature->SetField(fieldname_opt[index].c_str(),theValue);
2162 writeCentroidFeature->SetField(fieldname_opt[index].c_str(),theValue);
2166 writePolygonFeature->SetField(fieldname_opt[index].c_str(),type2string<double>(theValue).c_str());
2168 writeCentroidFeature->SetField(fieldname_opt[index].c_str(),type2string<double>(theValue).c_str());
2196 std::cout <<
"field type not supported yet..." << std::endl;
2203 if(ruleMap[rule_opt[0]]==rule::proportion){
2205 std::cout <<
"number of points in polygon: " << nPointPolygon << std::endl;
2206 stat.normalize_pct(polyClassValues);
2207 for(
int index=0;index<polyClassValues.size();++index){
2208 double theValue=polyClassValues[index];
2210 fs << class_opt[index];
2212 writePolygonFeature->SetField(fs.str().c_str(),
static_cast<int>(theValue));
2214 writeCentroidFeature->SetField(fs.str().c_str(),
static_cast<int>(theValue));
2217 else if(ruleMap[rule_opt[0]]==rule::custom){
2218 assert(polygon_opt[0]);
2220 std::cout <<
"number of points in polygon: " << nPointPolygon << std::endl;
2221 stat.normalize_pct(polyClassValues);
2222 assert(polyClassValues.size()==2);
2223 if(polyClassValues[0]>=75)
2224 writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(11));
2225 else if(polyClassValues[1]>=75)
2226 writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(12));
2227 else if(polyClassValues[0]>25&&polyClassValues[1]>25)
2228 writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(13));
2231 std::cout <<
"No valid value in polyClassValues..." << std::endl;
2232 for(
int index=0;index<polyClassValues.size();++index){
2233 double theValue=polyClassValues[index];
2234 std::cout << theValue <<
" ";
2236 std::cout << std::endl;
2238 writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(20));
2241 else if(ruleMap[rule_opt[0]]==rule::mode){
2244 std::cout <<
"number of points in polygon: " << nPointPolygon << std::endl;
2246 int maxClass=stat.mymin(class_opt);
2247 vector<double>::iterator maxit;
2248 maxit=stat.mymax(polyClassValues,polyClassValues.begin(),polyClassValues.end());
2249 int maxIndex=distance(polyClassValues.begin(),maxit);
2250 maxClass=class_opt[maxIndex];
2251 if(verbose_opt[0]>0)
2252 std::cout <<
"maxClass: " << maxClass << std::endl;
2254 writePolygonFeature->SetField(label_opt[0].c_str(),maxClass);
2256 writeCentroidFeature->SetField(label_opt[0].c_str(),maxClass);
2261 if(verbose_opt[0]>1)
2262 std::cout <<
"creating polygon feature" << std::endl;
2264 if(writeTestLayer->CreateFeature( writePolygonFeature ) != OGRERR_NONE ){
2265 std::string errorString=
"Failed to create polygon feature in ogr vector dataset";
2270 if(writeLayer->CreateFeature( writePolygonFeature ) != OGRERR_NONE ){
2271 std::string errorString=
"Failed to create polygon feature in ogr vector dataset";
2275 OGRFeature::DestroyFeature( writePolygonFeature );
2278 std::cout <<
"ntotalvalid: " << ntotalvalid << std::endl;
2281 if(verbose_opt[0]>1)
2282 std::cout <<
"creating point feature in centroid" << std::endl;
2284 if(writeTestLayer->CreateFeature( writeCentroidFeature ) != OGRERR_NONE ){
2285 std::string errorString=
"Failed to create point feature in ogr vector dataset";
2291 assert(validFeature);
2292 if(writeLayer->CreateFeature( writeCentroidFeature ) != OGRERR_NONE ){
2293 std::string errorString=
"Failed to create point feature in ogr vector dataset";
2297 OGRFeature::DestroyFeature( writeCentroidFeature );
2300 std::cout <<
"ntotalvalid: " << ntotalvalid << std::endl;
2306 test=poGeometry->getGeometryName();
2308 oss <<
"geometry " << test <<
" not supported";
2312 progress=
static_cast<float>(ifeature+1)/nfeature;
2313 pfnProgress(progress,pszMessage,pProgressArg);
2315 catch(std::string e){
2316 std::cout << e << std::endl;
2321 std::cout <<
"number of points read in polygon: " << npoint << std::endl;
2328 pfnProgress(progress,pszMessage,pProgressArg);
2333 sampleWriterOgr.close();
2335 ogrTestWriter.close();
2338 pfnProgress(progress,pszMessage,pProgressArg);