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"
38 int main(
int argc,
char **argv) {
42 Optionpk<double> saa_opt(
"saa",
"saa",
"Sun azimuth angle (N=0 E=90 S=180 W=270).");
43 Optionpk<int> flag_opt(
"f",
"flag",
"Flag to put in image if pixel shadow", 0);
44 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",
"");
45 Optionpk<string> oformat_opt(
"of",
"oformat",
"Output image format (see also gdal_translate). Empty string: inherit from input image");
46 Optionpk<string> colorTable_opt(
"ct",
"ct",
"color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)");
47 Optionpk<string> option_opt(
"co",
"co",
"Creation option for output file. Multiple options can be specified.");
48 Optionpk<double> scale_opt(
"s",
"scale",
"scale used for input dsm: height=scale*input+offset");
49 Optionpk<double> offset_opt(
"off",
"offset",
"offset used for input dsm: height=scale*input+offset");
50 Optionpk<short> verbose_opt(
"v",
"verbose",
"verbose mode if > 0", 0,2);
53 offset_opt.setHide(1);
57 doProcess=input_opt.retrieveOption(argc,argv);
58 output_opt.retrieveOption(argc,argv);
59 sza_opt.retrieveOption(argc,argv);
60 saa_opt.retrieveOption(argc,argv);
61 flag_opt.retrieveOption(argc,argv);
62 scale_opt.retrieveOption(argc,argv);
63 offset_opt.retrieveOption(argc,argv);
64 option_opt.retrieveOption(argc,argv);
65 otype_opt.retrieveOption(argc,argv);
66 oformat_opt.retrieveOption(argc,argv);
67 colorTable_opt.retrieveOption(argc,argv);
68 verbose_opt.retrieveOption(argc,argv);
70 catch(
string predefinedString){
71 std::cout << predefinedString << std::endl;
76 cout <<
"Usage: pkdsm2shadow -i input.txt -o output [-sza angle] [-saa angle]" << endl;
78 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
84 assert(input_opt.size());
85 assert(output_opt.size());
86 input.open(input_opt[0]);
88 input.setScale(scale_opt[0]);
90 input.setOffset(offset_opt[0]);
93 GDALDataType theType=GDT_Unknown;
95 cout <<
"possible output data types: ";
96 for(
int iType = 0; iType < GDT_TypeCount; ++iType){
98 cout <<
" " << GDALGetDataTypeName((GDALDataType)iType);
99 if( GDALGetDataTypeName((GDALDataType)iType) != NULL
100 && EQUAL(GDALGetDataTypeName((GDALDataType)iType),
101 otype_opt[0].c_str()))
102 theType=(GDALDataType) iType;
104 if(theType==GDT_Unknown)
105 theType=input.getDataType();
108 std::cout << std::endl <<
"Output pixel type: " << GDALGetDataTypeName(theType) << endl;
110 string imageType=input.getImageType();
111 if(oformat_opt.size())
112 imageType=oformat_opt[0];
114 if(option_opt.findSubstring(
"INTERLEAVE=")==option_opt.end()){
115 string theInterleave=
"INTERLEAVE=";
116 theInterleave+=input.getInterleave();
117 option_opt.push_back(theInterleave);
120 output.open(output_opt[0],input.nrOfCol(),input.nrOfRow(),input.nrOfBand(),theType,imageType,option_opt);
122 catch(
string errorstring){
123 cout << errorstring << endl;
126 output.setProjection(input.getProjection());
128 input.getGeoTransform(gt);
129 output.setGeoTransform(gt);
131 if(input.getColorTable()!=NULL)
132 output.setColorTable(input.getColorTable());
136 std::cout<<
"class values: ";
137 if(colorTable_opt.size())
138 output.setColorTable(colorTable_opt[0]);
139 filter2d.shadowDsm(input,output,sza_opt[0],saa_opt[0],input.getDeltaX(),flag_opt[0]);