23 #include "base/Optionpk.h" 24 #include "imageclasses/ImgWriterOgr.h" 72 int main(
int argc,
char *argv[])
76 Optionpk<string> ogrformat_opt(
"f",
"f",
"Output sample file format",
"ESRI Shapefile");
79 Optionpk<bool> polygon_opt(
"l",
"line",
"create OGRPolygon as geometry instead of points. Fields are taken from first point and polygon is automatically closed (no need to repeat first point at last line). (false: use OGRPoint)",
false);
80 Optionpk<string> fname_opt(
"n",
"name",
"Field names for the columns in the input ascii file");
81 Optionpk<string> ftype_opt(
"ot",
"ot",
"Field type (Real, Integer, String) for each of the fields as defined by name",
"Real");
82 Optionpk<string> projection_opt(
"a_srs",
"a_srs",
"Override the projection for the output file, use epsg:<code> or Wkt string",
"epsg:4326");
84 Optionpk<int> verbose_opt(
"v",
"verbose",
"verbose (0)", 0,2);
88 doProcess=input_opt.retrieveOption(argc,argv);
89 output_opt.retrieveOption(argc,argv);
90 ogrformat_opt.retrieveOption(argc,argv);
91 colX_opt.retrieveOption(argc,argv);
92 colY_opt.retrieveOption(argc,argv);
93 polygon_opt.retrieveOption(argc,argv);
94 fname_opt.retrieveOption(argc,argv);
95 ftype_opt.retrieveOption(argc,argv);
96 projection_opt.retrieveOption(argc,argv);
97 fs_opt.retrieveOption(argc,argv);
98 verbose_opt.retrieveOption(argc,argv);
100 catch(
string predefinedString){
101 std::cout << predefinedString << std::endl;
106 cout <<
"Usage: pkascii2ogr -i input.txt -o output" << endl;
108 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
111 if(input_opt.empty()){
112 std::cerr <<
"No input file provided (use option -i). Use --help for help information";
115 if(output_opt.empty()){
116 std::cerr <<
"No output file provided (use option -o). Use --help for help information";
120 string theProjection;
121 theProjection=projection_opt[0];
122 int ogr_typecount=11;
123 while(ftype_opt.size()<fname_opt.size())
124 ftype_opt.push_back(ftype_opt[0]);
126 vector<OGRFieldType> ftype(ftype_opt.size());
128 cout <<
"field types can be: ";
129 for(
int ifield=0;ifield<fname_opt.size();++ifield){
131 for(
int iType = 0; iType < ogr_typecount; ++iType){
132 if(!ifield&&verbose_opt[0])
133 cout <<
" " << OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType);
134 if( OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType) != NULL
135 && EQUAL(OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType),
136 ftype_opt[ifield].c_str()))
137 ftype[ifield]=(OGRFieldType) iType;
142 cout << endl <<
"field types are: ";
143 for(
int ifield=0;ifield<ftype.size();++ifield)
144 cout << OGRFieldDefn::GetFieldTypeName(ftype[ifield]) <<
" ";
149 imgWriter.open(output_opt[0],ogrformat_opt[0]);
152 imgWriter.ascii2ogr(input_opt[0],
"New Layer", fname_opt, ftype, colX_opt[0], colY_opt[0], theProjection, wkbPolygon, fs_opt[0]);
154 imgWriter.ascii2ogr(input_opt[0],
"New Layer", fname_opt, ftype, colX_opt[0], colY_opt[0], theProjection, wkbPoint, fs_opt[0]);
156 catch(
string errorString){
157 cout << errorString << endl;