osgEarth 2.1.1
|
#include <osg/Notify>
#include <osgEarthDrivers/feature_ogr/OGRFeatureOptions>
#include <osgEarthFeatures/GeometryUtils>
Go to the source code of this file.
Functions | |
std::string | attributeTypeToString (AttributeType type) |
void | printStats (FeatureSource *features) |
void | printFeature (Feature *feature) |
void | printAllFeatures (FeatureSource *features) |
int | usage (const std::string &msg) |
int | main (int argc, char **argv) |
Variables | |
std::string | indent = " " |
std::string attributeTypeToString | ( | AttributeType | type | ) |
Definition at line 30 of file osgearth_featureinfo.cpp.
{ switch (type) { case ATTRTYPE_BOOL: return "Boolean"; case ATTRTYPE_DOUBLE: return "Double"; case ATTRTYPE_INT: return "Integer"; case ATTRTYPE_STRING: return "String"; default: return "Unspecified"; } }
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 113 of file osgearth_featureinfo.cpp.
{ osg::ArgumentParser arguments(&argc,argv); if (argc < 2) { return usage(""); } std::vector< FeatureID > toDelete; int fid; while (arguments.read("--delete", fid)) { toDelete.push_back( fid ); } std::vector< FeatureID > fids; while (arguments.read("--fid", fid)) { fids.push_back( fid ); } bool printFeatures = false; if (arguments.read("--printfeatures" )) printFeatures = true; std::string filename; //Get the first argument that is not an option for(int pos=1;pos<arguments.argc();++pos) { if (!arguments.isOption(pos)) { filename = arguments[ pos ]; } } if (filename.empty()) { return usage( "Please provide a filename" ); } bool write = toDelete.size() > 0; //Open the feature source OGRFeatureOptions featureOpt; featureOpt.url() = filename; featureOpt.openWrite() = write; osg::ref_ptr< FeatureSource > features = FeatureSourceFactory::create( featureOpt ); features->initialize(""); features->getFeatureProfile(); //Delete any features if requested if (toDelete.size() > 0) { for (unsigned int i = 0; i < toDelete.size(); ++i) { FeatureID fid = toDelete[i]; std::cout << "Deleting Feature " << fid << std::endl; features->deleteFeature( fid ); } } else if (fids.size() > 0) { //Print out any specific FIDs for (unsigned int i = 0; i < fids.size(); ++i) { FeatureID fid = fids[i]; osg::ref_ptr< Feature > feature = features->getFeature( fid ); if (feature.valid()) { printFeature( feature.get() ); } else { std::cout << "Couldn't get feature " << fid << std::endl; } } } else { //Print out feature info printStats( features.get() ); if (printFeatures) { printAllFeatures( features.get() ); } } return 0; }
void printAllFeatures | ( | FeatureSource * | features | ) |
Definition at line 83 of file osgearth_featureinfo.cpp.
{ osg::ref_ptr< FeatureCursor > cursor = features->createFeatureCursor(); while (cursor->hasMore()) { osg::ref_ptr< Feature > feature = cursor->nextFeature(); printFeature( feature.get() ); } }
void printFeature | ( | Feature * | feature | ) |
Definition at line 59 of file osgearth_featureinfo.cpp.
{ std::cout << "FID: " << feature->getFID() << std::endl; for (AttributeTable::const_iterator itr = feature->getAttrs().begin(); itr != feature->getAttrs().end(); ++itr) { std::cout << indent << itr->first << "=" << itr->second.getString() << " (" << (itr->second.first == ATTRTYPE_INT? "integer" : itr->second.first == ATTRTYPE_DOUBLE? "double" : itr->second.first == ATTRTYPE_BOOL? "bool" : "string") << ")" << std::endl; } //Print out the geometry Geometry* geom = feature->getGeometry(); if (geom) { std::cout << indent << geometryToWkt( geom ) << std::endl; } std::cout << std::endl; }
void printStats | ( | FeatureSource * | features | ) |
Definition at line 44 of file osgearth_featureinfo.cpp.
{ std::cout << "Feature Count: " << features->getFeatureCount() << std::endl; std::cout << "Geometry Type: " << osgEarth::Symbology::Geometry::toString( features->getGeometryType() ) << std::endl; //Print the schema const FeatureSchema schema = features->getSchema(); std::cout << "Schema:" << std::endl; for (FeatureSchema::const_iterator itr = schema.begin(); itr != schema.end(); ++itr) { std::cout << indent << itr->first << ": " << attributeTypeToString(itr->second) << std::endl; } std::cout << std::endl; }
int usage | ( | const std::string & | msg | ) |
Definition at line 94 of file osgearth_featureinfo.cpp.
{ if ( !msg.empty() ) { std::cout << msg << std::endl; } std::cout << std::endl << "USAGE: osgearth_featureinfo [options] filename" << std::endl << std::endl << " --printfeatures ; Prints all features in the source" << std::endl << " --delete fid ; Deletes the given FID from the source." << std::endl << " --fid fid ; Displays the given FID." << std::endl << std::endl; return -1; }
std::string indent = " " |
Definition at line 42 of file osgearth_featureinfo.cpp.