25 #include <sys/types.h>
27 #include "base/Optionpk.h"
28 #include "base/Vector2d.h"
29 #include "algorithms/Filter2d.h"
30 #include "imageclasses/ImgReaderGdal.h"
31 #include "imageclasses/ImgWriterGdal.h"
84 int main(
int argc,
char **argv) {
88 Optionpk<double> saa_opt(
"saa",
"saa",
"Sun azimuth angle (N=0 E=90 S=180 W=270).");
89 Optionpk<int> flag_opt(
"f",
"flag",
"Flag to put in image if pixel shadow", 0);
90 Optionpk<std::string> otype_opt(
"ot",
"otype",
"Data type for output image ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}). Empty string: inherit type from input image",
"");
91 Optionpk<string> oformat_opt(
"of",
"oformat",
"Output image format (see also gdal_translate). Empty string: inherit from input image");
92 Optionpk<string> colorTable_opt(
"ct",
"ct",
"color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)");
93 Optionpk<string> option_opt(
"co",
"co",
"Creation option for output file. Multiple options can be specified.");
94 Optionpk<double> scale_opt(
"s",
"scale",
"scale used for input dsm: height=scale*input+offset");
95 Optionpk<double> offset_opt(
"off",
"offset",
"offset used for input dsm: height=scale*input+offset");
96 Optionpk<short> verbose_opt(
"v",
"verbose",
"verbose mode if > 0", 0,2);
99 offset_opt.setHide(1);
103 doProcess=input_opt.retrieveOption(argc,argv);
104 output_opt.retrieveOption(argc,argv);
105 sza_opt.retrieveOption(argc,argv);
106 saa_opt.retrieveOption(argc,argv);
107 flag_opt.retrieveOption(argc,argv);
108 scale_opt.retrieveOption(argc,argv);
109 offset_opt.retrieveOption(argc,argv);
110 option_opt.retrieveOption(argc,argv);
111 otype_opt.retrieveOption(argc,argv);
112 oformat_opt.retrieveOption(argc,argv);
113 colorTable_opt.retrieveOption(argc,argv);
114 verbose_opt.retrieveOption(argc,argv);
116 catch(
string predefinedString){
117 std::cout << predefinedString << std::endl;
122 cout <<
"Usage: pkdsm2shadow -i input.txt -o output [-sza angle] [-saa angle]" << endl;
124 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
130 assert(input_opt.size());
131 assert(output_opt.size());
132 input.open(input_opt[0]);
134 input.setScale(scale_opt[0]);
135 if(offset_opt.size())
136 input.setOffset(offset_opt[0]);
139 GDALDataType theType=GDT_Unknown;
141 cout <<
"possible output data types: ";
142 for(
int iType = 0; iType < GDT_TypeCount; ++iType){
144 cout <<
" " << GDALGetDataTypeName((GDALDataType)iType);
145 if( GDALGetDataTypeName((GDALDataType)iType) != NULL
146 && EQUAL(GDALGetDataTypeName((GDALDataType)iType),
147 otype_opt[0].c_str()))
148 theType=(GDALDataType) iType;
150 if(theType==GDT_Unknown)
151 theType=input.getDataType();
154 std::cout << std::endl <<
"Output pixel type: " << GDALGetDataTypeName(theType) << endl;
156 string imageType=input.getImageType();
157 if(oformat_opt.size())
158 imageType=oformat_opt[0];
160 if(option_opt.findSubstring(
"INTERLEAVE=")==option_opt.end()){
161 string theInterleave=
"INTERLEAVE=";
162 theInterleave+=input.getInterleave();
163 option_opt.push_back(theInterleave);
166 output.open(output_opt[0],input.nrOfCol(),input.nrOfRow(),input.nrOfBand(),theType,imageType,option_opt);
168 catch(
string errorstring){
169 cout << errorstring << endl;
172 output.setProjection(input.getProjection());
174 input.getGeoTransform(gt);
175 output.setGeoTransform(gt);
177 if(input.getColorTable()!=NULL)
178 output.setColorTable(input.getColorTable());
182 std::cout<<
"class values: ";
183 if(colorTable_opt.size())
184 output.setColorTable(colorTable_opt[0]);
185 filter2d.shadowDsm(input,output,sza_opt[0],saa_opt[0],input.getDeltaX(),flag_opt[0]);