-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathshapefile.h
65 lines (60 loc) · 2.25 KB
/
shapefile.h
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
#include "clustr.h"
#include <ogr_api.h>
#include <string>
namespace Clustr {
class Shapefile;
const std::string driver_name = "ESRI Shapefile";
typedef OGRwkbGeometryType GeometryType;
class Geometry {
protected:
OGRGeometryH inner;
OGRGeometryH outer;
GeometryType geom_type;
public:
Geometry (GeometryType geom_type);
~Geometry () { OGR_G_DestroyGeometry(outer); };
OGRGeometryH handle () const { return outer; };
GeometryType geometry_type (void) const { return geom_type; };
void add_ring (void);
void push_back (double x, double y);
void push_back (const Point& pt);
template <typename Iterator>
void insert (Iterator begin, Iterator end);
void insert_rings (Polygon::iterator begin, Polygon::iterator end);
};
class MultiGeometry : public Geometry {
public:
MultiGeometry (GeometryType geom_type) : Geometry(geom_type) {};
OGRGeometryH handle (void) const { return outer; };
void push_back (const Geometry& geom);
void insert (Polygon::iterator begin, Polygon::iterator end);
};
class Feature {
OGRFeatureH feat;
OGRFeatureDefnH defn;
GeometryType geom_type;
int index (const char *name);
public:
Feature (const Shapefile &shape);
~Feature () { OGR_F_Destroy(feat); };
OGRFeatureH handle () const { return feat; };
void set (const char *name, const char *val);
void set (const char *name, long int val);
void set (const char *name, double val);
void set (const Geometry &geom);
};
class Shapefile {
OGRSFDriverH driver;
OGRDataSourceH ds;
OGRLayerH layer;
GeometryType geom_type;
std::string name;
public:
Shapefile (std::string const filename, GeometryType layer_type, bool append=false);
~Shapefile () { OGR_DS_Destroy( ds ); };
OGRFeatureDefnH definition (void) const { return OGR_L_GetLayerDefn(layer); };
GeometryType geometry_type (void) const { return geom_type; };
void add_field (const char *name, OGRFieldType type, int width, int precision=0);
void add_feature (const Feature &feature);
};
};