6 #include "getopts/getopts.h"
21 int main(
int argc,
char **argv ) {
27 opts.addOption(
"" ,
"log-level" ,
"Set the log level (debug, warn, info, error)",
true );
28 opts.addOption(
"v",
"version" ,
"Display version info" ,
false );
29 opts.addOption(
"l",
"list" ,
"List available formats" ,
false );
30 opts.addOption(
"s",
"source" ,
"Source where points are located" ,
true );
31 opts.addOption(
"n",
"name" ,
"Name (label) to filter points" ,
true );
32 opts.addOption(
"w",
"wkt" ,
"Spatial reference in WKT" ,
true );
33 opts.addOption(
"o",
"type" ,
"Output type" ,
true );
34 opts.addOption(
"" ,
"split" ,
"Split points using the specified proportion (0,1)" ,
true );
35 opts.addOption(
"" ,
"file1" ,
"File name to store 1st subset (used w/ param split)",
true );
36 opts.addOption(
"" ,
"file2" ,
"File name to store 2nd subset (used w/ param split)",
true );
37 opts.addOption(
"c",
"config-file",
"Configuration file for openModeller" ,
true );
39 std::string log_level(
"info");
40 bool list_formats =
false;
41 std::string source(
"");
42 std::string label(
"");
43 std::string wkt(
"GEOGCS[\"WGS84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"degree\",0.017453292519943295],AXIS[\"Longitude\",EAST],AXIS[\"Latitude\",NORTH]]");
44 std::string format(
"TXT");
45 std::string split_prop_string;
48 std::string config_file;
50 if ( ! opts.parse( argc, argv ) ) {
52 opts.showHelp( argv[0] );
61 while ( ( option = opts.cycle() ) >= 0 ) {
66 log_level = opts.getArgs( option );
69 printf(
"om_points %s\n", om.
getVersion().c_str() );
70 printf(
"This is free software; see the source for copying conditions. There is NO\n");
71 printf(
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
78 source = opts.getArgs( option );
81 label = opts.getArgs( option );
84 wkt = opts.getArgs( option );
87 format = opts.getArgs( option );
90 split_prop_string = opts.getArgs( option );
93 file1 = opts.getArgs( option );
96 file2 = opts.getArgs( option );
99 config_file = opts.getArgs( option );
113 if ( ! config_file.empty() ) {
122 if ( list_formats ) {
128 printf(
"Available formats (id: description (input/output))\n" );
130 for (
size_t i = 0; i < driver_ids.size(); ++i ) {
132 std::string description(
"?");
135 if ( driver_ids[i] ==
"GBIF" ) {
137 description =
"GBIF Web Service for occurrence points";
139 else if ( driver_ids[i] ==
"TAPIR" ) {
141 description =
"TAPIR Web Service using DarwinCore 1.4 and the geospatial extension";
143 else if ( driver_ids[i] ==
"TerraLib" ) {
145 description =
"Points stored in a TerraLib database";
147 else if ( driver_ids[i] ==
"TXT" ) {
149 description =
"Delimited text file (id, label, long, lat, abundance)";
153 else if ( driver_ids[i] ==
"XML" ) {
155 description =
"openModeller serialized XML for occurrences";
160 printf(
" %s: %s (%s)\n", driver_ids[i].c_str(), description.c_str(), io.c_str() );
168 if ( source.empty() ) {
170 printf(
"Please specify a source to load points from.\n");
173 if ( label.empty() ) {
175 printf(
"Please specify a name to filter points.\n");
180 double split_prop = 0.0;
182 if ( ! split_prop_string.empty() ) {
184 if ( file1.empty() || file2.empty() ) {
186 printf(
"When splitting points, you need to specify file1 and file2.\n");
190 split_prop = atof( split_prop_string.c_str() );
192 if ( split_prop <= 0.0 || split_prop >= 1.0 ) {
194 printf(
"Splitting proportion must be a value between 0 and 1.\n");
215 pres1 =
new OccurrencesImpl( presences->label(), presences->coordSystem() );
216 pres2 =
new OccurrencesImpl( presences->label(), presences->coordSystem() );
223 abs1 =
new OccurrencesImpl( absences->label(), absences->coordSystem() );
224 abs2 =
new OccurrencesImpl( absences->label(), absences->coordSystem() );
231 ofstream outfile1( file1.c_str() );
233 writeOutput( outfile1, format, pres1, abs1, label );
237 ofstream outfile2( file2.c_str() );
239 writeOutput( outfile2, format, pres2, abs2, label );
250 writeOutput( cout, format, presences, absences, label );
252 catch ( runtime_error e ) {
254 printf(
"om_points: %s\n", e.what() );
265 if ( format ==
"XML" ) {
270 cfg->setName(
"Presence" );
275 if ( absences && absences->numOccurrences() ) {
278 cfg->setName(
"Absence" );
286 stream <<
"#id\t" <<
"label\t" <<
"long\t" <<
"lat\t" <<
"abundance" << endl << flush;
293 while ( it != last ) {
295 stream << (*it)->id() <<
"\t" << label.c_str() <<
"\t" << (*it)->x() <<
"\t" << (*it)->y() <<
"\t" << (*it)->abundance() << endl << flush;
305 while ( it != last ) {
307 stream << (*it)->id() <<
"\t" << label.c_str() <<
"\t" << (*it)->x() <<
"\t" << (*it)->y() <<
"\t" << (*it)->abundance() << endl << flush;
static void loadConfig(const std::string configFile)
std::vector< OccurrencePtr >::iterator iterator
vector< string > getRegisteredDrivers()
static Log * instance()
Returns the instance pointer, creating the object on the first call.
static OccurrencesFactory & instance()
void writeOutput(ostream &stream, std::string format, OccurrencesPtr presences, OccurrencesPtr absences, std::string label)
Log::Level getLogLevel(std::string level)
virtual OccurrencesPtr getAbsences(const char *groupId)
void setLevel(Level level)
int main(int argc, char **argv)
void setupExternalResources()
virtual OccurrencesPtr getPresences(const char *groupId)
void splitOccurrences(const OccurrencesPtr &occurrences, OccurrencesPtr &trainOccurrences, OccurrencesPtr &testOccurrences, double propTrain)
static void writeXml(const ConstConfigurationPtr &config, char const *fileaname)
OccurrencesReader * create(const char *source, const char *coordSystem)