-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput_layer.hpp
92 lines (68 loc) · 2 KB
/
output_layer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* output_layer.hpp
*
* Created on: 11.10.2016
* Author: michael
*
* This file contains code from osmium library v1 (include/osmium/export/shapefile.hpp).
*/
#ifndef OUTPUT_LAYER_HPP_
#define OUTPUT_LAYER_HPP_
#include <iostream>
#include <fstream>
#include <gdal/ogr_geometry.h>
#include <gdal/ogrsf_frmts.h>
#include <gdal/ogr_api.h>
#include "tile.hpp"
class OutputLayer {
private:
//current shapefile suffix (for overflow cases)
int m_current_index;
std::string m_directory;
std::string m_layer_name;
OGRSpatialReference m_output_srs;
OGRSpatialReference m_web_mercator_srs; // only necessary if output SRS is not EPSG:3857
bool m_tile_ids;
std::string& m_output_format;
GDALDriver* m_driver;
GDALDataset* m_dataset;
// counters and constants for calculation of current SHP and DBF file size
size_t m_current_dbf_size = 0;
size_t m_current_shp_size = 0;
size_t m_dbf_entry_size = 0;
// pointer to current OGRLayer
OGRLayer* m_layer;
static const int m_max_shape_size = 2040109465;
void setup_data_source();
void set_directory(std::string& path);
void set_filename(std::string& path);
/**
* add a field to a layer
*/
void add_field(const std::string& field_name, OGRFieldType type, int width);
/**
* close the layer
*/
void close_layer();
/**
* open a new layer
*/
void open_layer();
/**
* Write CPG file because GDAL's Shapefile driver does not do it.
*/
void write_cpg_file();
/**
* Check if layer is smaller than 2 GB. If not, close it and reopen a new one.
*/
void ensure_layer_writeable();
public:
OutputLayer(std::string&& out_directory, std::string&& layer_name, int output_epsg, bool tile_ids,
std::string& output_format);
~OutputLayer();
/**
* write a tile to the output layer
*/
void write_tile(int x, int y, int zoom, std::string& sequence, bool tile_ids);
};
#endif /* OUTPUT_LAYER_HPP_ */