Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: KML Driver 4 : * Purpose: Class for reading, parsing and handling a kmlfile. 5 : * Author: Jens Oberender, j.obi@troja.net 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2007, Jens Oberender 9 : * Copyright (c) 2008-2012, Even Rouault <even dot rouault at spatialys.com> 10 : * 11 : * SPDX-License-Identifier: MIT 12 : ****************************************************************************/ 13 : #ifndef OGR_KML_KML_H_INCLUDED 14 : #define OGR_KML_KML_H_INCLUDED 15 : 16 : #ifdef HAVE_EXPAT 17 : 18 : #include "ogr_expat.h" 19 : #include "cpl_vsi.h" 20 : 21 : // std 22 : #include <iostream> 23 : #include <string> 24 : #include <vector> 25 : 26 : #include "cpl_port.h" 27 : #include "kmlutility.h" 28 : 29 : class KMLNode; 30 : 31 : typedef enum 32 : { 33 : KML_VALIDITY_UNKNOWN, 34 : KML_VALIDITY_INVALID, 35 : KML_VALIDITY_VALID 36 : } OGRKMLValidity; 37 : 38 25 : class KML 39 : { 40 : public: 41 : KML(); 42 : virtual ~KML(); 43 : bool open(const char *pszFilename); 44 : bool isValid(); 45 : bool isHandled(std::string const &elem) const; 46 : virtual bool isLeaf(std::string const &elem) const; 47 : virtual bool isFeature(std::string const &elem) const; 48 : virtual bool isFeatureContainer(std::string const &elem) const; 49 : virtual bool isContainer(std::string const &elem) const; 50 : virtual bool isRest(std::string const &elem) const; 51 : virtual void findLayers(KMLNode *poNode, int bKeepEmptyContainers); 52 : 53 : bool hasOnlyEmpty() const; 54 : 55 : bool parse(); 56 : void print(unsigned short what = 3); 57 : std::string getError() const; 58 : int classifyNodes(); 59 : void eliminateEmpty(); 60 : int getNumLayers() const; 61 : bool selectLayer(int); 62 : std::string getCurrentName() const; 63 : Nodetype getCurrentType() const; 64 : int is25D() const; 65 : int getNumFeatures(); 66 : Feature *getFeature(std::size_t nNum, int &nLastAsked, int &nLastCount); 67 : 68 : void unregisterLayerIfMatchingThisNode(KMLNode *poNode); 69 : 70 : protected: 71 : void checkValidity(); 72 : 73 : static void XMLCALL startElement(void *, const char *, const char **); 74 : static void XMLCALL startElementValidate(void *, const char *, 75 : const char **); 76 : static void XMLCALL dataHandler(void *, const char *, int); 77 : static void XMLCALL dataHandlerValidate(void *, const char *, int); 78 : static void XMLCALL endElement(void *, const char *); 79 : 80 : // Trunk of KMLnodes. 81 : KMLNode *poTrunk_ = nullptr; 82 : // Number of layers. 83 : int nNumLayers_ = -1; 84 : KMLNode **papoLayers_ = nullptr; 85 : 86 : private: 87 : // Depth of the DOM. 88 : unsigned int nDepth_ = 0; 89 : // KML version number. 90 : std::string sVersion_{}; 91 : // Set to KML_VALIDITY_VALID if the beginning of the file is detected as KML 92 : OGRKMLValidity validity = KML_VALIDITY_UNKNOWN; 93 : // File descriptor. 94 : VSILFILE *pKMLFile_ = nullptr; 95 : // Error text ("" when everything is OK"). 96 : std::string sError_{}; 97 : // Current KMLNode. 98 : KMLNode *poCurrent_ = nullptr; 99 : 100 : XML_Parser oCurrentParser{}; 101 : int nDataHandlerCounter = 0; 102 : int nWithoutEventCounter = 0; 103 : 104 : CPL_DISALLOW_COPY_ASSIGN(KML) 105 : }; 106 : 107 : #endif // HAVE_EXPAT 108 : 109 : #endif /* OGR_KML_KML_H_INCLUDED */