schleyfox-rgeo 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.rdoc +199 -0
- data/README.rdoc +172 -0
- data/Spatial_Programming_With_RGeo.rdoc +440 -0
- data/Version +1 -0
- data/ext/geos_c_impl/extconf.rb +84 -0
- data/ext/geos_c_impl/factory.c +468 -0
- data/ext/geos_c_impl/factory.h +224 -0
- data/ext/geos_c_impl/geometry.c +705 -0
- data/ext/geos_c_impl/geometry.h +55 -0
- data/ext/geos_c_impl/geometry_collection.c +482 -0
- data/ext/geos_c_impl/geometry_collection.h +69 -0
- data/ext/geos_c_impl/line_string.c +509 -0
- data/ext/geos_c_impl/line_string.h +64 -0
- data/ext/geos_c_impl/main.c +70 -0
- data/ext/geos_c_impl/point.c +193 -0
- data/ext/geos_c_impl/point.h +62 -0
- data/ext/geos_c_impl/polygon.c +265 -0
- data/ext/geos_c_impl/polygon.h +66 -0
- data/ext/geos_c_impl/preface.h +50 -0
- data/ext/proj4_c_impl/extconf.rb +88 -0
- data/ext/proj4_c_impl/main.c +271 -0
- data/lib/rgeo.rb +124 -0
- data/lib/rgeo/cartesian.rb +60 -0
- data/lib/rgeo/cartesian/analysis.rb +118 -0
- data/lib/rgeo/cartesian/bounding_box.rb +337 -0
- data/lib/rgeo/cartesian/calculations.rb +161 -0
- data/lib/rgeo/cartesian/factory.rb +209 -0
- data/lib/rgeo/cartesian/feature_classes.rb +173 -0
- data/lib/rgeo/cartesian/feature_methods.rb +106 -0
- data/lib/rgeo/cartesian/interface.rb +150 -0
- data/lib/rgeo/coord_sys.rb +79 -0
- data/lib/rgeo/coord_sys/cs/entities.rb +1524 -0
- data/lib/rgeo/coord_sys/cs/factories.rb +208 -0
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +308 -0
- data/lib/rgeo/coord_sys/proj4.rb +312 -0
- data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +194 -0
- data/lib/rgeo/coord_sys/srs_database/interface.rb +165 -0
- data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +188 -0
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +108 -0
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +108 -0
- data/lib/rgeo/error.rb +63 -0
- data/lib/rgeo/feature.rb +88 -0
- data/lib/rgeo/feature/curve.rb +156 -0
- data/lib/rgeo/feature/factory.rb +332 -0
- data/lib/rgeo/feature/factory_generator.rb +138 -0
- data/lib/rgeo/feature/geometry.rb +614 -0
- data/lib/rgeo/feature/geometry_collection.rb +129 -0
- data/lib/rgeo/feature/line.rb +66 -0
- data/lib/rgeo/feature/line_string.rb +102 -0
- data/lib/rgeo/feature/linear_ring.rb +66 -0
- data/lib/rgeo/feature/multi_curve.rb +113 -0
- data/lib/rgeo/feature/multi_line_string.rb +66 -0
- data/lib/rgeo/feature/multi_point.rb +73 -0
- data/lib/rgeo/feature/multi_polygon.rb +97 -0
- data/lib/rgeo/feature/multi_surface.rb +116 -0
- data/lib/rgeo/feature/point.rb +120 -0
- data/lib/rgeo/feature/polygon.rb +141 -0
- data/lib/rgeo/feature/surface.rb +122 -0
- data/lib/rgeo/feature/types.rb +305 -0
- data/lib/rgeo/geographic.rb +75 -0
- data/lib/rgeo/geographic/factory.rb +287 -0
- data/lib/rgeo/geographic/interface.rb +410 -0
- data/lib/rgeo/geographic/proj4_projector.rb +98 -0
- data/lib/rgeo/geographic/projected_feature_classes.rb +213 -0
- data/lib/rgeo/geographic/projected_feature_methods.rb +228 -0
- data/lib/rgeo/geographic/projected_window.rb +467 -0
- data/lib/rgeo/geographic/simple_mercator_projector.rb +157 -0
- data/lib/rgeo/geographic/spherical_feature_classes.rb +212 -0
- data/lib/rgeo/geographic/spherical_feature_methods.rb +97 -0
- data/lib/rgeo/geographic/spherical_math.rb +206 -0
- data/lib/rgeo/geos.rb +72 -0
- data/lib/rgeo/geos/factory.rb +301 -0
- data/lib/rgeo/geos/impl_additions.rb +76 -0
- data/lib/rgeo/geos/interface.rb +139 -0
- data/lib/rgeo/geos/zm_factory.rb +275 -0
- data/lib/rgeo/geos/zm_impl.rb +432 -0
- data/lib/rgeo/impl_helper.rb +53 -0
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +235 -0
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +85 -0
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +197 -0
- data/lib/rgeo/impl_helper/basic_point_methods.rb +138 -0
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +121 -0
- data/lib/rgeo/impl_helper/math.rb +50 -0
- data/lib/rgeo/version.rb +52 -0
- data/lib/rgeo/wkrep.rb +72 -0
- data/lib/rgeo/wkrep/wkb_generator.rb +267 -0
- data/lib/rgeo/wkrep/wkb_parser.rb +315 -0
- data/lib/rgeo/wkrep/wkt_generator.rb +275 -0
- data/lib/rgeo/wkrep/wkt_parser.rb +496 -0
- data/test/common/geometry_collection_tests.rb +238 -0
- data/test/common/line_string_tests.rb +324 -0
- data/test/common/multi_line_string_tests.rb +209 -0
- data/test/common/multi_point_tests.rb +201 -0
- data/test/common/multi_polygon_tests.rb +208 -0
- data/test/common/point_tests.rb +331 -0
- data/test/common/polygon_tests.rb +232 -0
- data/test/coord_sys/tc_active_record_table.rb +102 -0
- data/test/coord_sys/tc_ogc_cs.rb +356 -0
- data/test/coord_sys/tc_proj4.rb +138 -0
- data/test/coord_sys/tc_proj4_srs_data.rb +76 -0
- data/test/coord_sys/tc_sr_org.rb +70 -0
- data/test/coord_sys/tc_url_reader.rb +82 -0
- data/test/geos/tc_factory.rb +91 -0
- data/test/geos/tc_geometry_collection.rb +62 -0
- data/test/geos/tc_line_string.rb +62 -0
- data/test/geos/tc_misc.rb +72 -0
- data/test/geos/tc_multi_line_string.rb +62 -0
- data/test/geos/tc_multi_point.rb +62 -0
- data/test/geos/tc_multi_polygon.rb +63 -0
- data/test/geos/tc_point.rb +86 -0
- data/test/geos/tc_polygon.rb +86 -0
- data/test/geos/tc_zmfactory.rb +85 -0
- data/test/projected_geographic/tc_geometry_collection.rb +62 -0
- data/test/projected_geographic/tc_line_string.rb +62 -0
- data/test/projected_geographic/tc_multi_line_string.rb +62 -0
- data/test/projected_geographic/tc_multi_point.rb +62 -0
- data/test/projected_geographic/tc_multi_polygon.rb +63 -0
- data/test/projected_geographic/tc_point.rb +93 -0
- data/test/projected_geographic/tc_polygon.rb +62 -0
- data/test/simple_cartesian/tc_calculations.rb +145 -0
- data/test/simple_cartesian/tc_geometry_collection.rb +69 -0
- data/test/simple_cartesian/tc_line_string.rb +70 -0
- data/test/simple_cartesian/tc_multi_line_string.rb +67 -0
- data/test/simple_cartesian/tc_multi_point.rb +67 -0
- data/test/simple_cartesian/tc_multi_polygon.rb +70 -0
- data/test/simple_cartesian/tc_point.rb +91 -0
- data/test/simple_cartesian/tc_polygon.rb +67 -0
- data/test/simple_mercator/tc_geometry_collection.rb +62 -0
- data/test/simple_mercator/tc_line_string.rb +62 -0
- data/test/simple_mercator/tc_multi_line_string.rb +62 -0
- data/test/simple_mercator/tc_multi_point.rb +62 -0
- data/test/simple_mercator/tc_multi_polygon.rb +63 -0
- data/test/simple_mercator/tc_point.rb +93 -0
- data/test/simple_mercator/tc_polygon.rb +62 -0
- data/test/simple_mercator/tc_window.rb +219 -0
- data/test/spherical_geographic/tc_calculations.rb +203 -0
- data/test/spherical_geographic/tc_geometry_collection.rb +70 -0
- data/test/spherical_geographic/tc_line_string.rb +70 -0
- data/test/spherical_geographic/tc_multi_line_string.rb +67 -0
- data/test/spherical_geographic/tc_multi_point.rb +67 -0
- data/test/spherical_geographic/tc_multi_polygon.rb +70 -0
- data/test/spherical_geographic/tc_point.rb +100 -0
- data/test/spherical_geographic/tc_polygon.rb +67 -0
- data/test/tc_cartesian_analysis.rb +107 -0
- data/test/tc_oneoff.rb +63 -0
- data/test/wkrep/tc_wkb_generator.rb +249 -0
- data/test/wkrep/tc_wkb_parser.rb +353 -0
- data/test/wkrep/tc_wkt_generator.rb +362 -0
- data/test/wkrep/tc_wkt_parser.rb +480 -0
- metadata +267 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
/*
|
2
|
+
-----------------------------------------------------------------------------
|
3
|
+
|
4
|
+
Line string methods for GEOS wrapper
|
5
|
+
|
6
|
+
-----------------------------------------------------------------------------
|
7
|
+
Copyright 2010 Daniel Azuma
|
8
|
+
|
9
|
+
All rights reserved.
|
10
|
+
|
11
|
+
Redistribution and use in source and binary forms, with or without
|
12
|
+
modification, are permitted provided that the following conditions are met:
|
13
|
+
|
14
|
+
* Redistributions of source code must retain the above copyright notice,
|
15
|
+
this list of conditions and the following disclaimer.
|
16
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
17
|
+
this list of conditions and the following disclaimer in the documentation
|
18
|
+
and/or other materials provided with the distribution.
|
19
|
+
* Neither the name of the copyright holder, nor the names of any other
|
20
|
+
contributors to this software, may be used to endorse or promote products
|
21
|
+
derived from this software without specific prior written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
24
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
25
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
27
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
28
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
29
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
31
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
32
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
-----------------------------------------------------------------------------
|
35
|
+
*/
|
36
|
+
|
37
|
+
|
38
|
+
#ifndef RGEO_GEOS_LINE_STRING_INCLUDED
|
39
|
+
#define RGEO_GEOS_LINE_STRING_INCLUDED
|
40
|
+
|
41
|
+
#include <ruby.h>
|
42
|
+
#include <geos_c.h>
|
43
|
+
|
44
|
+
#include "factory.h"
|
45
|
+
|
46
|
+
RGEO_BEGIN_C
|
47
|
+
|
48
|
+
|
49
|
+
/*
|
50
|
+
Initializes the line string module. This should be called after
|
51
|
+
the geometry module is initialized.
|
52
|
+
*/
|
53
|
+
void rgeo_init_geos_line_string(RGeo_Globals* globals);
|
54
|
+
|
55
|
+
/*
|
56
|
+
Determines whether the given GEOS line string is closed.
|
57
|
+
Returns Qtrue if true, Qfalse if false, or Qnil on an error.
|
58
|
+
*/
|
59
|
+
VALUE rgeo_is_geos_line_string_closed(GEOSContextHandle_t context, const GEOSGeometry* geom);
|
60
|
+
|
61
|
+
|
62
|
+
RGEO_END_C
|
63
|
+
|
64
|
+
#endif
|
@@ -0,0 +1,70 @@
|
|
1
|
+
/*
|
2
|
+
-----------------------------------------------------------------------------
|
3
|
+
|
4
|
+
Main initializer for GEOS wrapper
|
5
|
+
|
6
|
+
-----------------------------------------------------------------------------
|
7
|
+
Copyright 2010 Daniel Azuma
|
8
|
+
|
9
|
+
All rights reserved.
|
10
|
+
|
11
|
+
Redistribution and use in source and binary forms, with or without
|
12
|
+
modification, are permitted provided that the following conditions are met:
|
13
|
+
|
14
|
+
* Redistributions of source code must retain the above copyright notice,
|
15
|
+
this list of conditions and the following disclaimer.
|
16
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
17
|
+
this list of conditions and the following disclaimer in the documentation
|
18
|
+
and/or other materials provided with the distribution.
|
19
|
+
* Neither the name of the copyright holder, nor the names of any other
|
20
|
+
contributors to this software, may be used to endorse or promote products
|
21
|
+
derived from this software without specific prior written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
24
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
25
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
27
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
28
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
29
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
31
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
32
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
-----------------------------------------------------------------------------
|
35
|
+
*/
|
36
|
+
|
37
|
+
|
38
|
+
#include "preface.h"
|
39
|
+
|
40
|
+
#ifdef RGEO_GEOS_SUPPORTED
|
41
|
+
|
42
|
+
#include <ruby.h>
|
43
|
+
#include <geos_c.h>
|
44
|
+
|
45
|
+
#include "factory.h"
|
46
|
+
#include "geometry.h"
|
47
|
+
#include "point.h"
|
48
|
+
#include "line_string.h"
|
49
|
+
#include "polygon.h"
|
50
|
+
#include "geometry_collection.h"
|
51
|
+
|
52
|
+
#endif
|
53
|
+
|
54
|
+
RGEO_BEGIN_C
|
55
|
+
|
56
|
+
|
57
|
+
void Init_geos_c_impl()
|
58
|
+
{
|
59
|
+
#ifdef RGEO_GEOS_SUPPORTED
|
60
|
+
RGeo_Globals* globals = rgeo_init_geos_factory();
|
61
|
+
rgeo_init_geos_geometry(globals);
|
62
|
+
rgeo_init_geos_point(globals);
|
63
|
+
rgeo_init_geos_line_string(globals);
|
64
|
+
rgeo_init_geos_polygon(globals);
|
65
|
+
rgeo_init_geos_geometry_collection(globals);
|
66
|
+
#endif
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
RGEO_END_C
|
@@ -0,0 +1,193 @@
|
|
1
|
+
/*
|
2
|
+
-----------------------------------------------------------------------------
|
3
|
+
|
4
|
+
Point methods for GEOS wrapper
|
5
|
+
|
6
|
+
-----------------------------------------------------------------------------
|
7
|
+
Copyright 2010 Daniel Azuma
|
8
|
+
|
9
|
+
All rights reserved.
|
10
|
+
|
11
|
+
Redistribution and use in source and binary forms, with or without
|
12
|
+
modification, are permitted provided that the following conditions are met:
|
13
|
+
|
14
|
+
* Redistributions of source code must retain the above copyright notice,
|
15
|
+
this list of conditions and the following disclaimer.
|
16
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
17
|
+
this list of conditions and the following disclaimer in the documentation
|
18
|
+
and/or other materials provided with the distribution.
|
19
|
+
* Neither the name of the copyright holder, nor the names of any other
|
20
|
+
contributors to this software, may be used to endorse or promote products
|
21
|
+
derived from this software without specific prior written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
24
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
25
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
27
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
28
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
29
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
31
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
32
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
-----------------------------------------------------------------------------
|
35
|
+
*/
|
36
|
+
|
37
|
+
|
38
|
+
#include "preface.h"
|
39
|
+
|
40
|
+
#ifdef RGEO_GEOS_SUPPORTED
|
41
|
+
|
42
|
+
#include <ruby.h>
|
43
|
+
#include <geos_c.h>
|
44
|
+
|
45
|
+
#include "factory.h"
|
46
|
+
#include "geometry.h"
|
47
|
+
#include "point.h"
|
48
|
+
|
49
|
+
RGEO_BEGIN_C
|
50
|
+
|
51
|
+
|
52
|
+
static VALUE method_point_geometry_type(VALUE self)
|
53
|
+
{
|
54
|
+
VALUE result = Qnil;
|
55
|
+
RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
56
|
+
if (self_data->geom) {
|
57
|
+
result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_point;
|
58
|
+
}
|
59
|
+
return result;
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
static VALUE method_point_x(VALUE self)
|
64
|
+
{
|
65
|
+
VALUE result = Qnil;
|
66
|
+
RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
67
|
+
const GEOSGeometry* self_geom = self_data->geom;
|
68
|
+
if (self_geom) {
|
69
|
+
GEOSContextHandle_t self_context = self_data->geos_context;
|
70
|
+
const GEOSCoordSequence* coord_seq = GEOSGeom_getCoordSeq_r(self_context, self_geom);
|
71
|
+
if (coord_seq) {
|
72
|
+
double val;
|
73
|
+
if (GEOSCoordSeq_getX_r(self_context, coord_seq, 0, &val)) {
|
74
|
+
result = rb_float_new(val);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
return result;
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
static VALUE method_point_y(VALUE self)
|
83
|
+
{
|
84
|
+
VALUE result = Qnil;
|
85
|
+
RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
86
|
+
const GEOSGeometry* self_geom = self_data->geom;
|
87
|
+
if (self_geom) {
|
88
|
+
GEOSContextHandle_t self_context = self_data->geos_context;
|
89
|
+
const GEOSCoordSequence* coord_seq = GEOSGeom_getCoordSeq_r(self_context, self_geom);
|
90
|
+
if (coord_seq) {
|
91
|
+
double val;
|
92
|
+
if (GEOSCoordSeq_getY_r(self_context, coord_seq, 0, &val)) {
|
93
|
+
result = rb_float_new(val);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
return result;
|
98
|
+
}
|
99
|
+
|
100
|
+
|
101
|
+
static VALUE get_3d_point(VALUE self, int flag)
|
102
|
+
{
|
103
|
+
VALUE result = Qnil;
|
104
|
+
RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
105
|
+
const GEOSGeometry* self_geom = self_data->geom;
|
106
|
+
if (self_geom) {
|
107
|
+
if (RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & flag) {
|
108
|
+
GEOSContextHandle_t self_context = self_data->geos_context;
|
109
|
+
const GEOSCoordSequence* coord_seq = GEOSGeom_getCoordSeq_r(self_context, self_geom);
|
110
|
+
if (coord_seq) {
|
111
|
+
double val;
|
112
|
+
if (GEOSCoordSeq_getZ_r(self_context, coord_seq, 0, &val)) {
|
113
|
+
result = rb_float_new(val);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
}
|
118
|
+
return result;
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
static VALUE method_point_z(VALUE self)
|
123
|
+
{
|
124
|
+
return get_3d_point(self, RGEO_FACTORYFLAGS_SUPPORTS_Z);
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
static VALUE method_point_m(VALUE self)
|
129
|
+
{
|
130
|
+
return get_3d_point(self, RGEO_FACTORYFLAGS_SUPPORTS_M);
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
static VALUE method_point_eql(VALUE self, VALUE rhs)
|
135
|
+
{
|
136
|
+
VALUE result = rgeo_geos_klasses_and_factories_eql(self, rhs);
|
137
|
+
if (RTEST(result)) {
|
138
|
+
RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
139
|
+
result = rgeo_geos_coordseqs_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom, RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
|
140
|
+
}
|
141
|
+
return result;
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
static VALUE cmethod_create(VALUE module, VALUE factory, VALUE x, VALUE y, VALUE z)
|
146
|
+
{
|
147
|
+
return rgeo_create_geos_point(factory, rb_num2dbl(x), rb_num2dbl(y),
|
148
|
+
RGEO_FACTORY_DATA_PTR(factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M ? rb_num2dbl(z) : 0);
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
void rgeo_init_geos_point(RGeo_Globals* globals)
|
153
|
+
{
|
154
|
+
VALUE geos_point_class = rb_define_class_under(globals->geos_module, "PointImpl", globals->geos_geometry);
|
155
|
+
globals->geos_point = geos_point_class;
|
156
|
+
globals->feature_point = rb_const_get_at(globals->feature_module, rb_intern("Point"));
|
157
|
+
|
158
|
+
rb_define_module_function(geos_point_class, "create", cmethod_create, 4);
|
159
|
+
|
160
|
+
rb_define_method(geos_point_class, "eql?", method_point_eql, 1);
|
161
|
+
rb_define_method(geos_point_class, "geometry_type", method_point_geometry_type, 0);
|
162
|
+
rb_define_method(geos_point_class, "x", method_point_x, 0);
|
163
|
+
rb_define_method(geos_point_class, "y", method_point_y, 0);
|
164
|
+
rb_define_method(geos_point_class, "z", method_point_z, 0);
|
165
|
+
rb_define_method(geos_point_class, "m", method_point_m, 0);
|
166
|
+
}
|
167
|
+
|
168
|
+
|
169
|
+
VALUE rgeo_create_geos_point(VALUE factory, double x, double y, double z)
|
170
|
+
{
|
171
|
+
VALUE result = Qnil;
|
172
|
+
RGeo_FactoryData* factory_data = RGEO_FACTORY_DATA_PTR(factory);
|
173
|
+
GEOSContextHandle_t context = factory_data->geos_context;
|
174
|
+
GEOSCoordSequence* coord_seq = GEOSCoordSeq_create_r(context, 1, 3);
|
175
|
+
if (coord_seq) {
|
176
|
+
if (GEOSCoordSeq_setX_r(context, coord_seq, 0, x)) {
|
177
|
+
if (GEOSCoordSeq_setY_r(context, coord_seq, 0, y)) {
|
178
|
+
if (GEOSCoordSeq_setZ_r(context, coord_seq, 0, z)) {
|
179
|
+
GEOSGeometry* geom = GEOSGeom_createPoint_r(context, coord_seq);
|
180
|
+
if (geom) {
|
181
|
+
result = rgeo_wrap_geos_geometry(factory, geom, factory_data->globals->geos_point);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}
|
186
|
+
}
|
187
|
+
return result;
|
188
|
+
}
|
189
|
+
|
190
|
+
|
191
|
+
RGEO_END_C
|
192
|
+
|
193
|
+
#endif
|
@@ -0,0 +1,62 @@
|
|
1
|
+
/*
|
2
|
+
-----------------------------------------------------------------------------
|
3
|
+
|
4
|
+
Point methods for GEOS wrapper
|
5
|
+
|
6
|
+
-----------------------------------------------------------------------------
|
7
|
+
Copyright 2010 Daniel Azuma
|
8
|
+
|
9
|
+
All rights reserved.
|
10
|
+
|
11
|
+
Redistribution and use in source and binary forms, with or without
|
12
|
+
modification, are permitted provided that the following conditions are met:
|
13
|
+
|
14
|
+
* Redistributions of source code must retain the above copyright notice,
|
15
|
+
this list of conditions and the following disclaimer.
|
16
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
17
|
+
this list of conditions and the following disclaimer in the documentation
|
18
|
+
and/or other materials provided with the distribution.
|
19
|
+
* Neither the name of the copyright holder, nor the names of any other
|
20
|
+
contributors to this software, may be used to endorse or promote products
|
21
|
+
derived from this software without specific prior written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
24
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
25
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
27
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
28
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
29
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
31
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
32
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
-----------------------------------------------------------------------------
|
35
|
+
*/
|
36
|
+
|
37
|
+
|
38
|
+
#ifndef RGEO_GEOS_POINT_INCLUDED
|
39
|
+
#define RGEO_GEOS_POINT_INCLUDED
|
40
|
+
|
41
|
+
#include <ruby.h>
|
42
|
+
|
43
|
+
#include "factory.h"
|
44
|
+
|
45
|
+
RGEO_BEGIN_C
|
46
|
+
|
47
|
+
|
48
|
+
/*
|
49
|
+
Initializes the point module. This should be called after
|
50
|
+
the geometry module is initialized.
|
51
|
+
*/
|
52
|
+
void rgeo_init_geos_point(RGeo_Globals* globals);
|
53
|
+
|
54
|
+
/*
|
55
|
+
Creates a 3d point and returns the ruby object.
|
56
|
+
*/
|
57
|
+
VALUE rgeo_create_geos_point(VALUE factory, double x, double y, double z);
|
58
|
+
|
59
|
+
|
60
|
+
RGEO_END_C
|
61
|
+
|
62
|
+
#endif
|
@@ -0,0 +1,265 @@
|
|
1
|
+
/*
|
2
|
+
-----------------------------------------------------------------------------
|
3
|
+
|
4
|
+
Polygon methods for GEOS wrapper
|
5
|
+
|
6
|
+
-----------------------------------------------------------------------------
|
7
|
+
Copyright 2010 Daniel Azuma
|
8
|
+
|
9
|
+
All rights reserved.
|
10
|
+
|
11
|
+
Redistribution and use in source and binary forms, with or without
|
12
|
+
modification, are permitted provided that the following conditions are met:
|
13
|
+
|
14
|
+
* Redistributions of source code must retain the above copyright notice,
|
15
|
+
this list of conditions and the following disclaimer.
|
16
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
17
|
+
this list of conditions and the following disclaimer in the documentation
|
18
|
+
and/or other materials provided with the distribution.
|
19
|
+
* Neither the name of the copyright holder, nor the names of any other
|
20
|
+
contributors to this software, may be used to endorse or promote products
|
21
|
+
derived from this software without specific prior written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
24
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
25
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
27
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
28
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
29
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
31
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
32
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
-----------------------------------------------------------------------------
|
35
|
+
*/
|
36
|
+
|
37
|
+
|
38
|
+
#include "preface.h"
|
39
|
+
|
40
|
+
#ifdef RGEO_GEOS_SUPPORTED
|
41
|
+
|
42
|
+
#include <ruby.h>
|
43
|
+
#include <geos_c.h>
|
44
|
+
|
45
|
+
#include "factory.h"
|
46
|
+
#include "geometry.h"
|
47
|
+
#include "line_string.h"
|
48
|
+
#include "polygon.h"
|
49
|
+
|
50
|
+
RGEO_BEGIN_C
|
51
|
+
|
52
|
+
|
53
|
+
static VALUE method_polygon_eql(VALUE self, VALUE rhs)
|
54
|
+
{
|
55
|
+
VALUE result = rgeo_geos_klasses_and_factories_eql(self, rhs);
|
56
|
+
if (RTEST(result)) {
|
57
|
+
RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
58
|
+
result = rgeo_geos_polygons_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom, RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
|
59
|
+
}
|
60
|
+
return result;
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
static VALUE method_polygon_geometry_type(VALUE self)
|
65
|
+
{
|
66
|
+
VALUE result = Qnil;
|
67
|
+
RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
68
|
+
if (self_data->geom) {
|
69
|
+
result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_polygon;
|
70
|
+
}
|
71
|
+
return result;
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
static VALUE method_polygon_area(VALUE self)
|
76
|
+
{
|
77
|
+
VALUE result = Qnil;
|
78
|
+
RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
79
|
+
const GEOSGeometry* self_geom = self_data->geom;
|
80
|
+
if (self_geom) {
|
81
|
+
double area;
|
82
|
+
if (GEOSArea_r(self_data->geos_context, self_geom, &area)) {
|
83
|
+
result = rb_float_new(area);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
return result;
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
static VALUE method_polygon_centroid(VALUE self)
|
91
|
+
{
|
92
|
+
VALUE result = Qnil;
|
93
|
+
RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
94
|
+
const GEOSGeometry* self_geom = self_data->geom;
|
95
|
+
if (self_geom) {
|
96
|
+
result = rgeo_wrap_geos_geometry(self_data->factory, GEOSGetCentroid_r(self_data->geos_context, self_geom), RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_point);
|
97
|
+
}
|
98
|
+
return result;
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
static VALUE method_polygon_point_on_surface(VALUE self)
|
103
|
+
{
|
104
|
+
VALUE result = Qnil;
|
105
|
+
RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
106
|
+
const GEOSGeometry* self_geom = self_data->geom;
|
107
|
+
if (self_geom) {
|
108
|
+
result = rgeo_wrap_geos_geometry(self_data->factory, GEOSPointOnSurface_r(self_data->geos_context, self_geom), RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_point);
|
109
|
+
}
|
110
|
+
return result;
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
static VALUE method_polygon_exterior_ring(VALUE self)
|
115
|
+
{
|
116
|
+
VALUE result = Qnil;
|
117
|
+
RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
118
|
+
const GEOSGeometry* self_geom = self_data->geom;
|
119
|
+
if (self_geom) {
|
120
|
+
result = rgeo_wrap_geos_geometry_clone(self_data->factory, GEOSGetExteriorRing_r(self_data->geos_context, self_geom), RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_linear_ring);
|
121
|
+
}
|
122
|
+
return result;
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
static VALUE method_polygon_num_interior_rings(VALUE self)
|
127
|
+
{
|
128
|
+
VALUE result = Qnil;
|
129
|
+
RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
130
|
+
const GEOSGeometry* self_geom = self_data->geom;
|
131
|
+
if (self_geom) {
|
132
|
+
int num = GEOSGetNumInteriorRings_r(self_data->geos_context, self_geom);
|
133
|
+
if (num >= 0) {
|
134
|
+
result = INT2NUM(num);
|
135
|
+
}
|
136
|
+
}
|
137
|
+
return result;
|
138
|
+
}
|
139
|
+
|
140
|
+
|
141
|
+
static VALUE method_polygon_interior_ring_n(VALUE self, VALUE n)
|
142
|
+
{
|
143
|
+
VALUE result = Qnil;
|
144
|
+
RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
145
|
+
const GEOSGeometry* self_geom = self_data->geom;
|
146
|
+
if (self_geom) {
|
147
|
+
result = rgeo_wrap_geos_geometry_clone(self_data->factory, GEOSGetInteriorRingN_r(self_data->geos_context, self_geom, NUM2INT(n)), RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_linear_ring);
|
148
|
+
}
|
149
|
+
return result;
|
150
|
+
}
|
151
|
+
|
152
|
+
|
153
|
+
static VALUE method_polygon_interior_rings(VALUE self)
|
154
|
+
{
|
155
|
+
VALUE result = Qnil;
|
156
|
+
RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
157
|
+
const GEOSGeometry* self_geom = self_data->geom;
|
158
|
+
if (self_geom) {
|
159
|
+
GEOSContextHandle_t self_context = self_data->geos_context;
|
160
|
+
int count = GEOSGetNumInteriorRings_r(self_context, self_geom);
|
161
|
+
if (count >= 0) {
|
162
|
+
result = rb_ary_new2(count);
|
163
|
+
VALUE factory = self_data->factory;
|
164
|
+
VALUE linear_ring_class = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_linear_ring;
|
165
|
+
int i;
|
166
|
+
for (i=0; i<count; ++i) {
|
167
|
+
rb_ary_store(result, i, rgeo_wrap_geos_geometry_clone(factory, GEOSGetInteriorRingN_r(self_context, self_geom, i), linear_ring_class));
|
168
|
+
}
|
169
|
+
}
|
170
|
+
}
|
171
|
+
return result;
|
172
|
+
}
|
173
|
+
|
174
|
+
|
175
|
+
static VALUE cmethod_create(VALUE module, VALUE factory, VALUE exterior, VALUE interior_array)
|
176
|
+
{
|
177
|
+
Check_Type(interior_array, T_ARRAY);
|
178
|
+
RGeo_FactoryData* factory_data = RGEO_FACTORY_DATA_PTR(factory);
|
179
|
+
VALUE linear_ring_type = factory_data->globals->feature_linear_ring;
|
180
|
+
GEOSGeometry* exterior_geom = rgeo_convert_to_detached_geos_geometry(exterior, factory, linear_ring_type, NULL);
|
181
|
+
if (exterior_geom) {
|
182
|
+
GEOSContextHandle_t context = factory_data->geos_context;
|
183
|
+
unsigned int len = (unsigned int)RARRAY_LEN(interior_array);
|
184
|
+
GEOSGeometry** interior_geoms = ALLOC_N(GEOSGeometry*, len == 0 ? 1 : len);
|
185
|
+
if (interior_geoms) {
|
186
|
+
unsigned int actual_len = 0;
|
187
|
+
unsigned int i;
|
188
|
+
for (i=0; i<len; ++i) {
|
189
|
+
GEOSGeometry* interior_geom = rgeo_convert_to_detached_geos_geometry(rb_ary_entry(interior_array, i), factory, linear_ring_type, NULL);
|
190
|
+
if (interior_geom) {
|
191
|
+
interior_geoms[actual_len++] = interior_geom;
|
192
|
+
}
|
193
|
+
}
|
194
|
+
if (len == actual_len) {
|
195
|
+
GEOSGeometry* polygon = GEOSGeom_createPolygon_r(context, exterior_geom, interior_geoms, actual_len);
|
196
|
+
if (polygon) {
|
197
|
+
free(interior_geoms);
|
198
|
+
return rgeo_wrap_geos_geometry(factory, polygon, factory_data->globals->geos_polygon);
|
199
|
+
}
|
200
|
+
}
|
201
|
+
for (i=0; i<actual_len; ++i) {
|
202
|
+
GEOSGeom_destroy_r(context, interior_geoms[i]);
|
203
|
+
}
|
204
|
+
free(interior_geoms);
|
205
|
+
}
|
206
|
+
GEOSGeom_destroy_r(context, exterior_geom);
|
207
|
+
}
|
208
|
+
return Qnil;
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
void rgeo_init_geos_polygon(RGeo_Globals* globals)
|
213
|
+
{
|
214
|
+
VALUE geos_polygon_class = rb_define_class_under(globals->geos_module, "PolygonImpl", globals->geos_geometry);
|
215
|
+
globals->geos_polygon = geos_polygon_class;
|
216
|
+
globals->feature_polygon = rb_const_get_at(globals->feature_module, rb_intern("Polygon"));
|
217
|
+
|
218
|
+
rb_define_module_function(geos_polygon_class, "create", cmethod_create, 3);
|
219
|
+
|
220
|
+
rb_define_method(geos_polygon_class, "eql?", method_polygon_eql, 1);
|
221
|
+
rb_define_method(geos_polygon_class, "geometry_type", method_polygon_geometry_type, 0);
|
222
|
+
rb_define_method(geos_polygon_class, "area", method_polygon_area, 0);
|
223
|
+
rb_define_method(geos_polygon_class, "centroid", method_polygon_centroid, 0);
|
224
|
+
rb_define_method(geos_polygon_class, "point_on_surface", method_polygon_point_on_surface, 0);
|
225
|
+
rb_define_method(geos_polygon_class, "exterior_ring", method_polygon_exterior_ring, 0);
|
226
|
+
rb_define_method(geos_polygon_class, "num_interior_rings", method_polygon_num_interior_rings, 0);
|
227
|
+
rb_define_method(geos_polygon_class, "interior_ring_n", method_polygon_interior_ring_n, 1);
|
228
|
+
rb_define_method(geos_polygon_class, "interior_rings", method_polygon_interior_rings, 0);
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
VALUE rgeo_geos_polygons_eql(GEOSContextHandle_t context, const GEOSGeometry* geom1, const GEOSGeometry* geom2, char check_z)
|
233
|
+
{
|
234
|
+
VALUE result = Qnil;
|
235
|
+
if (geom1 && geom2) {
|
236
|
+
result = rgeo_geos_coordseqs_eql(context, GEOSGetExteriorRing_r(context, geom1), GEOSGetExteriorRing_r(context, geom2), check_z);
|
237
|
+
if (RTEST(result)) {
|
238
|
+
int len1 = GEOSGetNumInteriorRings_r(context, geom1);
|
239
|
+
int len2 = GEOSGetNumInteriorRings_r(context, geom2);
|
240
|
+
if (len1 >= 0 && len2 >= 0) {
|
241
|
+
if (len1 == len2) {
|
242
|
+
int i;
|
243
|
+
for (i=0; i<len1; ++i) {
|
244
|
+
result = rgeo_geos_coordseqs_eql(context, GEOSGetInteriorRingN_r(context, geom1, i), GEOSGetInteriorRingN_r(context, geom2, i), check_z);
|
245
|
+
if (!RTEST(result)) {
|
246
|
+
break;
|
247
|
+
}
|
248
|
+
}
|
249
|
+
}
|
250
|
+
else {
|
251
|
+
result = Qfalse;
|
252
|
+
}
|
253
|
+
}
|
254
|
+
else {
|
255
|
+
result = Qnil;
|
256
|
+
}
|
257
|
+
}
|
258
|
+
}
|
259
|
+
return result;
|
260
|
+
}
|
261
|
+
|
262
|
+
|
263
|
+
RGEO_END_C
|
264
|
+
|
265
|
+
#endif
|