1 #ifndef bkml_parser_h_ 2 #define bkml_parser_h_ 3 //: 4 // \file 5 // \verbatim 6 // Modifications 7 // Yi Dong SEP-2012 added parser for polygon (inner/outer) defined in kml 8 // Yi Dong NOV-2012 added parser for deviations of heading, tilt, roll, right_fov, top_fov of camera 9 // Yi Dong OCT-2014 added extra checking for polygon parsing to avoid duplicated points 10 // \endverbatim 11 12 // Tags for KML 13 #define PHOTO_OVL_TAG "PhotoOverlay" 14 #define KML_CAMERA_TAG "Camera" 15 #define KML_LON_TAG "longitude" 16 #define KML_LAT_TAG "latitude" 17 #define KML_ALT_TAG "altitude" 18 #define KML_HEAD_TAG "heading" 19 #define KML_TILT_TAG "tilt" 20 #define KML_ROLL_TAG "roll" 21 #define KML_RFOV_TAG "rightFov" 22 #define KML_TFOV_TAG "topFov" 23 #define KML_NEAR_TAG "near" 24 #define KML_POLY_TAG "Polygon" 25 #define KML_POINT_TAG "Point" 26 #define KML_POLYOB_TAG "outerBoundaryIs" 27 #define KML_POLYIB_TAG "innerBoundaryIs" 28 #define KML_CORD_TAG "coordinates" 29 #define KML_POLYCORE_END_TAG "/coordinates" 30 #define KML_LINE_TAG "LineString" 31 #define KML_PLACEMARK_NAME_TAG "name" 32 33 34 #define KML_HEAD_DEV_TAG "heading_deviation" 35 #define KML_TILT_DEV_TAG "tilt_deviation" 36 #define KML_ROLL_DEV_TAG "roll_deviation" 37 #define KML_RFOV_DEV_TAG "rightFov_deviation" 38 #define KML_TFOV_DEV_TAG "topFov_deviation" 39 #ifdef WIN32 40 #define _LIB 41 #endif 42 #include <iostream> 43 #include <string> 44 #include <vector> 45 #include <utility> 46 #include <expatpp.h> 47 #ifdef _MSC_VER 48 # include <vcl_msvc_warnings.h> 49 #endif 50 #include <vgl/vgl_point_3d.h> 51 #include <vgl/vgl_polygon.h> 52 53 54 class bkml_parser : public expatpp 55 { 56 public: 57 bkml_parser(void); 58 // parser should not delete the site, it is used afterwards 59 ~bkml_parser(void) override = default; 60 61 62 //: parser to load the points defined in kml file 63 static std::vector<vgl_point_3d<double> > parse_points(const std::string& kml_file); 64 65 //: parser to load the outer boundary of all defined polygons in the kml file (only parse the lat(y) and lon(x), elev ignored) 66 static vgl_polygon<double> parse_polygon(const std::string& poly_kml_file); 67 68 //: parser to load the outer and inner boundary, the first n_out sheets are the outer boundary 69 // and the following n_in sheets are the inner boundary 70 static vgl_polygon<double> parse_polygon_with_inner(const std::string& poly_kml_file, vgl_polygon<double>& outer, vgl_polygon<double>& inter, 71 unsigned& n_out, unsigned& n_in); 72 73 static bool parse_location_from_kml(const std::string& kml_file, double& lat, double& lon); 74 75 static void trim_string(std::string& s); 76 77 // results of parse 78 double longitude_; 79 double latitude_; 80 double altitude_; 81 double heading_; 82 double tilt_; 83 double roll_; 84 double right_fov_; 85 double top_fov_; 86 double near_; 87 double heading_dev_; 88 double tilt_dev_; 89 double roll_dev_; 90 double right_fov_dev_; 91 double top_fov_dev_; 92 std::vector<std::vector<vgl_point_3d<double> > > polyouter_; 93 std::vector<std::vector<vgl_point_3d<double> > > polyinner_; 94 std::vector<std::vector<vgl_point_3d<double> > > linecord_; 95 std::vector<vgl_point_3d<double> > points_; 96 97 std::string current_name_; 98 private: 99 100 void startElement(const XML_Char* name, const XML_Char** atts) override; 101 void endElement(const XML_Char* name) override; 102 void charData(const XML_Char* s, int len) override; 103 void handleAtts(const XML_Char** atts); 104 void cdataHandler(const std::string& name, const std::string& data); 105 void init_params(); 106 107 //element parser 108 std::string last_tag; 109 std::string cord_tag_; 110 111 }; 112 113 114 #endif 115