| 1 |
/* |
|---|
| 2 |
Clustr. Copyright (c) 2007-2009 Yahoo! Inc. |
|---|
| 3 |
|
|---|
| 4 |
All rights reserved. This code is free software; you can redistribute it |
|---|
| 5 |
and/or modify it under the terms of the GNU General Public License (GPL), |
|---|
| 6 |
version 2 only. This code is distributed WITHOUT ANY WARRANTY, whether |
|---|
| 7 |
express or implied. See the GNU GPL for more details |
|---|
| 8 |
(http://www.gnu.org/licenses/gpl.html) |
|---|
| 9 |
|
|---|
| 10 |
AS A SPECIAL EXCEPTION, YOU HAVE PERMISSION TO LINK THIS PROGRAM WITH THE |
|---|
| 11 |
CGAL LIBRARY AND DISTRIBUTE EXECUTABLES, AS LONG AS YOU FOLLOW THE REQUIREMENTS |
|---|
| 12 |
OF THE GNU GPL VERSION 2 IN REGARD TO ALL OF THE SOFTWARE IN THE EXECUTABLE |
|---|
| 13 |
ASIDE FROM CGAL. |
|---|
| 14 |
*/ |
|---|
| 15 |
|
|---|
| 16 |
#include "clustr.h" |
|---|
| 17 |
#include <ogr_api.h> |
|---|
| 18 |
#include <string> |
|---|
| 19 |
|
|---|
| 20 |
namespace Clustr { |
|---|
| 21 |
class Shapefile; |
|---|
| 22 |
const std::string driver_name = "ESRI Shapefile"; |
|---|
| 23 |
typedef OGRwkbGeometryType GeometryType; |
|---|
| 24 |
|
|---|
| 25 |
class Geometry { |
|---|
| 26 |
protected: |
|---|
| 27 |
OGRGeometryH inner; |
|---|
| 28 |
OGRGeometryH outer; |
|---|
| 29 |
GeometryType geom_type; |
|---|
| 30 |
public: |
|---|
| 31 |
Geometry (GeometryType geom_type); |
|---|
| 32 |
~Geometry () { OGR_G_DestroyGeometry(outer); }; |
|---|
| 33 |
OGRGeometryH handle () const { return outer; }; |
|---|
| 34 |
GeometryType geometry_type (void) const { return geom_type; }; |
|---|
| 35 |
void add_ring (void); |
|---|
| 36 |
void push_back (double x, double y); |
|---|
| 37 |
void push_back (const Point& pt); |
|---|
| 38 |
template <typename Iterator> |
|---|
| 39 |
void insert (Iterator begin, Iterator end); |
|---|
| 40 |
void insert_rings (Polygon::iterator begin, Polygon::iterator end); |
|---|
| 41 |
}; |
|---|
| 42 |
|
|---|
| 43 |
class MultiGeometry : public Geometry { |
|---|
| 44 |
public: |
|---|
| 45 |
MultiGeometry (GeometryType geom_type) : Geometry(geom_type) {}; |
|---|
| 46 |
OGRGeometryH handle (void) const { return outer; }; |
|---|
| 47 |
void push_back (const Geometry& geom); |
|---|
| 48 |
void insert (Polygon::iterator begin, Polygon::iterator end); |
|---|
| 49 |
}; |
|---|
| 50 |
|
|---|
| 51 |
class Feature { |
|---|
| 52 |
OGRFeatureH feat; |
|---|
| 53 |
OGRFeatureDefnH defn; |
|---|
| 54 |
GeometryType geom_type; |
|---|
| 55 |
int index (const char *name); |
|---|
| 56 |
public: |
|---|
| 57 |
Feature (const Shapefile &shape); |
|---|
| 58 |
~Feature () { OGR_F_Destroy(feat); }; |
|---|
| 59 |
OGRFeatureH handle () const { return feat; }; |
|---|
| 60 |
void set (const char *name, const char *val); |
|---|
| 61 |
void set (const char *name, long int val); |
|---|
| 62 |
void set (const char *name, double val); |
|---|
| 63 |
void set (const Geometry &geom); |
|---|
| 64 |
}; |
|---|
| 65 |
|
|---|
| 66 |
class Shapefile { |
|---|
| 67 |
OGRSFDriverH driver; |
|---|
| 68 |
OGRDataSourceH ds; |
|---|
| 69 |
OGRLayerH layer; |
|---|
| 70 |
GeometryType geom_type; |
|---|
| 71 |
std::string name; |
|---|
| 72 |
public: |
|---|
| 73 |
Shapefile (std::string const filename, GeometryType layer_type, bool append=false); |
|---|
| 74 |
~Shapefile () { OGR_DS_Destroy( ds ); }; |
|---|
| 75 |
OGRFeatureDefnH definition (void) const { return OGR_L_GetLayerDefn(layer); }; |
|---|
| 76 |
GeometryType geometry_type (void) const { return geom_type; }; |
|---|
| 77 |
void add_field (const char *name, OGRFieldType type, int width, int precision=0); |
|---|
| 78 |
void add_feature (const Feature &feature); |
|---|
| 79 |
}; |
|---|
| 80 |
}; |
|---|