libosmscout  1.1.1
OptimizeAreasLowZoom.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_OPTIMIZEAREASLOWZOOM_H
2 #define OSMSCOUT_OPTIMIZEAREASLOWZOOM_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2011 Tim Teulings
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 
23 #include <map>
24 #include <memory>
25 #include <mutex>
26 #include <set>
27 #include <string>
28 
29 #include <osmscout/TypeInfoSet.h>
30 
31 #include <osmscout/Area.h>
32 #include <osmscout/Way.h>
33 
36 
37 namespace osmscout {
38 
43  {
44  public:
45  static const char* const FILE_AREASOPT_DAT;
46 
47  private:
48  struct TypeData
49  {
50  uint32_t optLevel;
51  uint32_t indexLevel;
52 
53  uint32_t cellXStart;
54  uint32_t cellXEnd;
55  uint32_t cellYStart;
56  uint32_t cellYEnd;
57 
58  FileOffset bitmapOffset;
59  uint8_t dataOffsetBytes;
60 
61  uint32_t cellXCount;
62  uint32_t cellYCount;
63 
64  double cellWidth;
65  double cellHeight;
66 
67  double minLon;
68  double maxLon;
69  double minLat;
70  double maxLat;
71  };
72 
73  private:
74  TypeConfigRef typeConfig;
75  std::string datafilename;
76  mutable FileScanner scanner;
77 
78  double magnification;
79  std::map<TypeInfoRef,std::list<TypeData> > areaTypesData;
80 
81  mutable std::mutex lookupMutex;
82 
83  private:
84  void ReadTypeData(FileScanner& scanner,
85  TypeData& data);
86 
87  void GetOffsets(const TypeData& typeData,
88  const GeoBox& boundingBox,
89  std::set<FileOffset>& offsets) const;
90 
91  void LoadData(std::set<FileOffset>& offsets,
92  std::vector<AreaRef>& areas) const;
93 
94  public:
96  virtual ~OptimizeAreasLowZoom();
97 
98  bool Open(const TypeConfigRef& typeConfig,
99  const std::string& path,
100  bool memoryMappedData);
101  bool Close();
102 
103  bool HasOptimizations(double magnification) const;
104 
105  void GetTypes(const Magnification& magnification,
106  const TypeInfoSet& areaTypes,
107  TypeInfoSet& availableAreaTypes) const;
108  bool GetAreas(const GeoBox& boundingBox,
109  const Magnification& magnification,
110  const TypeInfoSet& areaTypes,
111  std::vector<AreaRef>& areas,
112  TypeInfoSet& loadedAreaTypes) const;
113  };
114 
115  using OptimizeAreasLowZoomRef = std::shared_ptr<OptimizeAreasLowZoom>;
116 }
117 
118 #endif
std::shared_ptr< OptimizeAreasLowZoom > OptimizeAreasLowZoomRef
Definition: OptimizeAreasLowZoom.h:115
Definition: Area.h:38
Definition: OptimizeAreasLowZoom.h:42
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
static const char *const FILE_AREASOPT_DAT
Definition: OptimizeAreasLowZoom.h:45
uint64_t FileOffset
Definition: OSMScoutTypes.h:47
std::shared_ptr< TypeConfig > TypeConfigRef
Definition: TypeConfig.h:1227