rgeo-dschee 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +29 -0
- data/ext/geos_c_impl/coordinates.c +65 -0
- data/ext/geos_c_impl/coordinates.h +2 -0
- data/ext/geos_c_impl/extconf.rb +43 -0
- data/ext/geos_c_impl/factory.c +995 -0
- data/ext/geos_c_impl/factory.h +238 -0
- data/ext/geos_c_impl/geometry.c +1093 -0
- data/ext/geos_c_impl/geometry.h +23 -0
- data/ext/geos_c_impl/geometry_collection.c +757 -0
- data/ext/geos_c_impl/geometry_collection.h +46 -0
- data/ext/geos_c_impl/line_string.c +675 -0
- data/ext/geos_c_impl/line_string.h +32 -0
- data/ext/geos_c_impl/main.c +40 -0
- data/ext/geos_c_impl/point.c +236 -0
- data/ext/geos_c_impl/point.h +30 -0
- data/ext/geos_c_impl/polygon.c +359 -0
- data/ext/geos_c_impl/polygon.h +43 -0
- data/ext/geos_c_impl/preface.h +38 -0
- data/ext/proj4_c_impl/extconf.rb +62 -0
- data/ext/proj4_c_impl/main.c +315 -0
- data/lib/rgeo.rb +89 -0
- data/lib/rgeo/cartesian.rb +25 -0
- data/lib/rgeo/cartesian/analysis.rb +77 -0
- data/lib/rgeo/cartesian/bounding_box.rb +398 -0
- data/lib/rgeo/cartesian/calculations.rb +113 -0
- data/lib/rgeo/cartesian/factory.rb +347 -0
- data/lib/rgeo/cartesian/feature_classes.rb +100 -0
- data/lib/rgeo/cartesian/feature_methods.rb +88 -0
- data/lib/rgeo/cartesian/interface.rb +135 -0
- data/lib/rgeo/coord_sys.rb +43 -0
- data/lib/rgeo/coord_sys/cs/entities.rb +1315 -0
- data/lib/rgeo/coord_sys/cs/factories.rb +148 -0
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +272 -0
- data/lib/rgeo/coord_sys/proj4.rb +293 -0
- data/lib/rgeo/coord_sys/srs_database/interface.rb +115 -0
- data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +140 -0
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +62 -0
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +63 -0
- data/lib/rgeo/error.rb +27 -0
- data/lib/rgeo/feature.rb +54 -0
- data/lib/rgeo/feature/curve.rb +111 -0
- data/lib/rgeo/feature/factory.rb +278 -0
- data/lib/rgeo/feature/factory_generator.rb +96 -0
- data/lib/rgeo/feature/geometry.rb +624 -0
- data/lib/rgeo/feature/geometry_collection.rb +95 -0
- data/lib/rgeo/feature/line.rb +26 -0
- data/lib/rgeo/feature/line_string.rb +60 -0
- data/lib/rgeo/feature/linear_ring.rb +26 -0
- data/lib/rgeo/feature/mixins.rb +143 -0
- data/lib/rgeo/feature/multi_curve.rb +71 -0
- data/lib/rgeo/feature/multi_line_string.rb +26 -0
- data/lib/rgeo/feature/multi_point.rb +33 -0
- data/lib/rgeo/feature/multi_polygon.rb +57 -0
- data/lib/rgeo/feature/multi_surface.rb +73 -0
- data/lib/rgeo/feature/point.rb +84 -0
- data/lib/rgeo/feature/polygon.rb +97 -0
- data/lib/rgeo/feature/surface.rb +79 -0
- data/lib/rgeo/feature/types.rb +284 -0
- data/lib/rgeo/geographic.rb +40 -0
- data/lib/rgeo/geographic/factory.rb +450 -0
- data/lib/rgeo/geographic/interface.rb +489 -0
- data/lib/rgeo/geographic/proj4_projector.rb +58 -0
- data/lib/rgeo/geographic/projected_feature_classes.rb +107 -0
- data/lib/rgeo/geographic/projected_feature_methods.rb +212 -0
- data/lib/rgeo/geographic/projected_window.rb +383 -0
- data/lib/rgeo/geographic/simple_mercator_projector.rb +110 -0
- data/lib/rgeo/geographic/spherical_feature_classes.rb +100 -0
- data/lib/rgeo/geographic/spherical_feature_methods.rb +134 -0
- data/lib/rgeo/geographic/spherical_math.rb +188 -0
- data/lib/rgeo/geos.rb +89 -0
- data/lib/rgeo/geos/capi_factory.rb +470 -0
- data/lib/rgeo/geos/capi_feature_classes.rb +129 -0
- data/lib/rgeo/geos/ffi_factory.rb +592 -0
- data/lib/rgeo/geos/ffi_feature_classes.rb +83 -0
- data/lib/rgeo/geos/ffi_feature_methods.rb +574 -0
- data/lib/rgeo/geos/interface.rb +202 -0
- data/lib/rgeo/geos/utils.rb +74 -0
- data/lib/rgeo/geos/zm_factory.rb +405 -0
- data/lib/rgeo/geos/zm_feature_classes.rb +80 -0
- data/lib/rgeo/geos/zm_feature_methods.rb +344 -0
- data/lib/rgeo/impl_helper.rb +19 -0
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +185 -0
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +61 -0
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +146 -0
- data/lib/rgeo/impl_helper/basic_point_methods.rb +104 -0
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +87 -0
- data/lib/rgeo/impl_helper/math.rb +14 -0
- data/lib/rgeo/impl_helper/utils.rb +29 -0
- data/lib/rgeo/version.rb +3 -0
- data/lib/rgeo/wkrep.rb +37 -0
- data/lib/rgeo/wkrep/wkb_generator.rb +201 -0
- data/lib/rgeo/wkrep/wkb_parser.rb +251 -0
- data/lib/rgeo/wkrep/wkt_generator.rb +207 -0
- data/lib/rgeo/wkrep/wkt_parser.rb +415 -0
- data/lib/rgeo/yaml.rb +23 -0
- data/test/cartesian_analysis_test.rb +65 -0
- data/test/cartesian_bbox_test.rb +123 -0
- data/test/common/factory_tests.rb +78 -0
- data/test/common/geometry_collection_tests.rb +237 -0
- data/test/common/line_string_tests.rb +330 -0
- data/test/common/multi_line_string_tests.rb +182 -0
- data/test/common/multi_point_tests.rb +200 -0
- data/test/common/multi_polygon_tests.rb +191 -0
- data/test/common/point_tests.rb +370 -0
- data/test/common/polygon_tests.rb +261 -0
- data/test/coord_sys/ogc_cs_test.rb +342 -0
- data/test/coord_sys/proj4_srs_data_test.rb +41 -0
- data/test/coord_sys/proj4_test.rb +150 -0
- data/test/coord_sys/sr_org_test.rb +32 -0
- data/test/coord_sys/url_reader_test.rb +42 -0
- data/test/geos_capi/factory_test.rb +31 -0
- data/test/geos_capi/geometry_collection_test.rb +24 -0
- data/test/geos_capi/line_string_test.rb +24 -0
- data/test/geos_capi/misc_test.rb +116 -0
- data/test/geos_capi/multi_line_string_test.rb +24 -0
- data/test/geos_capi/multi_point_test.rb +24 -0
- data/test/geos_capi/multi_polygon_test.rb +39 -0
- data/test/geos_capi/parsing_unparsing_test.rb +40 -0
- data/test/geos_capi/point_test.rb +72 -0
- data/test/geos_capi/polygon_test.rb +154 -0
- data/test/geos_capi/zmfactory_test.rb +57 -0
- data/test/geos_ffi/factory_test.rb +31 -0
- data/test/geos_ffi/geometry_collection_test.rb +24 -0
- data/test/geos_ffi/line_string_test.rb +24 -0
- data/test/geos_ffi/misc_test.rb +63 -0
- data/test/geos_ffi/multi_line_string_test.rb +24 -0
- data/test/geos_ffi/multi_point_test.rb +24 -0
- data/test/geos_ffi/multi_polygon_test.rb +33 -0
- data/test/geos_ffi/parsing_unparsing_test.rb +41 -0
- data/test/geos_ffi/point_test.rb +77 -0
- data/test/geos_ffi/polygon_test.rb +46 -0
- data/test/geos_ffi/zmfactory_test.rb +58 -0
- data/test/mixins_test.rb +141 -0
- data/test/oneoff_test.rb +26 -0
- data/test/projected_geographic/factory_test.rb +25 -0
- data/test/projected_geographic/geometry_collection_test.rb +24 -0
- data/test/projected_geographic/line_string_test.rb +24 -0
- data/test/projected_geographic/multi_line_string_test.rb +26 -0
- data/test/projected_geographic/multi_point_test.rb +30 -0
- data/test/projected_geographic/multi_polygon_test.rb +25 -0
- data/test/projected_geographic/point_test.rb +51 -0
- data/test/projected_geographic/polygon_test.rb +24 -0
- data/test/simple_cartesian/calculations_test.rb +99 -0
- data/test/simple_cartesian/factory_test.rb +27 -0
- data/test/simple_cartesian/geometry_collection_test.rb +30 -0
- data/test/simple_cartesian/line_string_test.rb +31 -0
- data/test/simple_cartesian/multi_line_string_test.rb +28 -0
- data/test/simple_cartesian/multi_point_test.rb +31 -0
- data/test/simple_cartesian/multi_polygon_test.rb +31 -0
- data/test/simple_cartesian/point_test.rb +50 -0
- data/test/simple_cartesian/polygon_test.rb +28 -0
- data/test/simple_mercator/factory_test.rb +25 -0
- data/test/simple_mercator/geometry_collection_test.rb +24 -0
- data/test/simple_mercator/line_string_test.rb +24 -0
- data/test/simple_mercator/multi_line_string_test.rb +26 -0
- data/test/simple_mercator/multi_point_test.rb +29 -0
- data/test/simple_mercator/multi_polygon_test.rb +25 -0
- data/test/simple_mercator/point_test.rb +55 -0
- data/test/simple_mercator/polygon_test.rb +24 -0
- data/test/simple_mercator/window_test.rb +173 -0
- data/test/spherical_geographic/calculations_test.rb +167 -0
- data/test/spherical_geographic/factory_test.rb +27 -0
- data/test/spherical_geographic/geometry_collection_test.rb +31 -0
- data/test/spherical_geographic/line_string_test.rb +31 -0
- data/test/spherical_geographic/multi_line_string_test.rb +29 -0
- data/test/spherical_geographic/multi_point_test.rb +31 -0
- data/test/spherical_geographic/multi_polygon_test.rb +31 -0
- data/test/spherical_geographic/point_test.rb +78 -0
- data/test/spherical_geographic/polygon_test.rb +28 -0
- data/test/types_test.rb +42 -0
- data/test/wkrep/wkb_generator_test.rb +185 -0
- data/test/wkrep/wkb_parser_test.rb +293 -0
- data/test/wkrep/wkt_generator_test.rb +294 -0
- data/test/wkrep/wkt_parser_test.rb +412 -0
- metadata +386 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
/*
|
2
|
+
Polygon methods for GEOS wrapper
|
3
|
+
*/
|
4
|
+
|
5
|
+
|
6
|
+
#ifndef RGEO_GEOS_POLYGON_INCLUDED
|
7
|
+
#define RGEO_GEOS_POLYGON_INCLUDED
|
8
|
+
|
9
|
+
#include <ruby.h>
|
10
|
+
#include <geos_c.h>
|
11
|
+
|
12
|
+
#include "factory.h"
|
13
|
+
|
14
|
+
RGEO_BEGIN_C
|
15
|
+
|
16
|
+
|
17
|
+
/*
|
18
|
+
Initializes the polygon module. This should be called after
|
19
|
+
the geometry module is initialized.
|
20
|
+
*/
|
21
|
+
void rgeo_init_geos_polygon(RGeo_Globals* globals);
|
22
|
+
|
23
|
+
/*
|
24
|
+
Comopares the values of two GEOS polygons. The two given geometries MUST
|
25
|
+
be polygon types.
|
26
|
+
Returns Qtrue if the polygons are equal, Qfalse if they are inequal, or
|
27
|
+
Qnil if an error occurs.
|
28
|
+
*/
|
29
|
+
VALUE rgeo_geos_polygons_eql(GEOSContextHandle_t context, const GEOSGeometry* geom1, const GEOSGeometry* geom2, char check_z);
|
30
|
+
|
31
|
+
/*
|
32
|
+
A tool for building up hash values.
|
33
|
+
You must pass in the context, a geos geometry, and a seed hash.
|
34
|
+
Returns an updated hash.
|
35
|
+
This call is useful in sequence, and should be bracketed by calls to
|
36
|
+
rb_hash_start and rb_hash_end.
|
37
|
+
*/
|
38
|
+
st_index_t rgeo_geos_polygon_hash(GEOSContextHandle_t context, const GEOSGeometry* geom, st_index_t hash);
|
39
|
+
|
40
|
+
|
41
|
+
RGEO_END_C
|
42
|
+
|
43
|
+
#endif
|
@@ -0,0 +1,38 @@
|
|
1
|
+
/*
|
2
|
+
Preface header for GEOS wrapper
|
3
|
+
*/
|
4
|
+
|
5
|
+
|
6
|
+
#ifdef HAVE_GEOS_C_H
|
7
|
+
#ifdef HAVE_GEOSSETSRID_R
|
8
|
+
#define RGEO_GEOS_SUPPORTED
|
9
|
+
#endif
|
10
|
+
#endif
|
11
|
+
|
12
|
+
#ifdef HAVE_GEOSPREPAREDCONTAINS_R
|
13
|
+
#define RGEO_GEOS_SUPPORTS_PREPARED1
|
14
|
+
#endif
|
15
|
+
#ifdef HAVE_GEOSPREPAREDDISJOINT_R
|
16
|
+
#define RGEO_GEOS_SUPPORTS_PREPARED2
|
17
|
+
#endif
|
18
|
+
#ifdef HAVE_GEOSWKTWWRITER_SETOUTPUTDIMENSION_R
|
19
|
+
#define RGEO_GEOS_SUPPORTS_SETOUTPUTDIMENSION
|
20
|
+
#endif
|
21
|
+
#ifdef HAVE_RB_MEMHASH
|
22
|
+
#define RGEO_SUPPORTS_NEW_HASHING
|
23
|
+
#endif
|
24
|
+
|
25
|
+
#ifndef RGEO_SUPPORTS_NEW_HASHING
|
26
|
+
#define st_index_t int
|
27
|
+
#define rb_memhash(x,y) rgeo_internal_memhash(x,y)
|
28
|
+
#define rb_hash_start(x) ((st_index_t)(x ^ 0xdeadbeef))
|
29
|
+
#define rb_hash_end(x) ((st_index_t)(x ^ 0xbeefdead))
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#ifdef __cplusplus
|
33
|
+
#define RGEO_BEGIN_C extern "C" {
|
34
|
+
#define RGEO_END_C }
|
35
|
+
#else
|
36
|
+
#define RGEO_BEGIN_C
|
37
|
+
#define RGEO_END_C
|
38
|
+
#endif
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Makefile builder for Proj4 wrapper
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
if ::RUBY_DESCRIPTION =~ /^jruby\s/
|
8
|
+
|
9
|
+
::File.open("Makefile", "w") { |f_| f_.write(".PHONY: install\ninstall:\n") }
|
10
|
+
|
11
|
+
else
|
12
|
+
|
13
|
+
require "mkmf"
|
14
|
+
|
15
|
+
header_dirs_ =
|
16
|
+
[
|
17
|
+
::RbConfig::CONFIG["includedir"],
|
18
|
+
"/usr/local/include",
|
19
|
+
"/usr/local/proj/include",
|
20
|
+
"/usr/local/proj4/include",
|
21
|
+
"/opt/local/include",
|
22
|
+
"/opt/proj/include",
|
23
|
+
"/opt/proj4/include",
|
24
|
+
"/opt/include",
|
25
|
+
"/Library/Frameworks/PROJ.framework/unix/include",
|
26
|
+
"/usr/include"
|
27
|
+
]
|
28
|
+
lib_dirs_ =
|
29
|
+
[
|
30
|
+
::RbConfig::CONFIG["libdir"],
|
31
|
+
"/usr/local/lib",
|
32
|
+
"/usr/local/lib64",
|
33
|
+
"/usr/local/proj/lib",
|
34
|
+
"/usr/local/proj4/lib",
|
35
|
+
"/opt/local/lib",
|
36
|
+
"/opt/proj/lib",
|
37
|
+
"/opt/proj4/lib",
|
38
|
+
"/opt/lib",
|
39
|
+
"/Library/Frameworks/PROJ.framework/unix/lib",
|
40
|
+
"/usr/lib",
|
41
|
+
"/usr/lib64"
|
42
|
+
]
|
43
|
+
header_dirs_.delete_if { |path_| !::File.directory?(path_) }
|
44
|
+
lib_dirs_.delete_if { |path_| !::File.directory?(path_) }
|
45
|
+
|
46
|
+
found_proj_ = false
|
47
|
+
header_dirs_, lib_dirs_ = dir_config("proj", header_dirs_, lib_dirs_)
|
48
|
+
if have_header("proj_api.h")
|
49
|
+
$libs << " -lproj"
|
50
|
+
if have_func("pj_init_plus", "proj_api.h")
|
51
|
+
found_proj_ = true
|
52
|
+
else
|
53
|
+
$libs.gsub!(" -lproj", "")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
unless found_proj_
|
57
|
+
puts "**** WARNING: Unable to find Proj headers or Proj version is too old."
|
58
|
+
puts "**** Compiling without Proj support."
|
59
|
+
end
|
60
|
+
create_makefile("rgeo/coord_sys/proj4_c_impl")
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,315 @@
|
|
1
|
+
/*
|
2
|
+
Main initializer for Proj4 wrapper
|
3
|
+
*/
|
4
|
+
|
5
|
+
#ifdef HAVE_PROJ_API_H
|
6
|
+
#ifdef HAVE_PJ_INIT_PLUS
|
7
|
+
#define RGEO_PROJ4_SUPPORTED
|
8
|
+
#endif
|
9
|
+
#endif
|
10
|
+
|
11
|
+
#ifdef __cplusplus
|
12
|
+
#define RGEO_BEGIN_C extern "C" {
|
13
|
+
#define RGEO_END_C }
|
14
|
+
#else
|
15
|
+
#define RGEO_BEGIN_C
|
16
|
+
#define RGEO_END_C
|
17
|
+
#endif
|
18
|
+
|
19
|
+
|
20
|
+
#ifdef RGEO_PROJ4_SUPPORTED
|
21
|
+
|
22
|
+
#include <ruby.h>
|
23
|
+
#include <proj_api.h>
|
24
|
+
|
25
|
+
#endif
|
26
|
+
|
27
|
+
|
28
|
+
RGEO_BEGIN_C
|
29
|
+
|
30
|
+
|
31
|
+
#ifdef RGEO_PROJ4_SUPPORTED
|
32
|
+
|
33
|
+
|
34
|
+
typedef struct {
|
35
|
+
projPJ pj;
|
36
|
+
VALUE original_str;
|
37
|
+
char uses_radians;
|
38
|
+
} RGeo_Proj4Data;
|
39
|
+
|
40
|
+
|
41
|
+
#define RGEO_PROJ4_DATA_PTR(obj) ((RGeo_Proj4Data*)DATA_PTR(obj))
|
42
|
+
|
43
|
+
|
44
|
+
// Destroy function for proj data.
|
45
|
+
|
46
|
+
static void destroy_proj4_func(RGeo_Proj4Data* data)
|
47
|
+
{
|
48
|
+
if (data->pj) {
|
49
|
+
pj_free(data->pj);
|
50
|
+
}
|
51
|
+
free(data);
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
static void mark_proj4_func(RGeo_Proj4Data* data)
|
56
|
+
{
|
57
|
+
if (!NIL_P(data->original_str)) {
|
58
|
+
rb_gc_mark(data->original_str);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
static VALUE alloc_proj4(VALUE klass)
|
64
|
+
{
|
65
|
+
VALUE result;
|
66
|
+
RGeo_Proj4Data* data;
|
67
|
+
|
68
|
+
result = Qnil;
|
69
|
+
data = ALLOC(RGeo_Proj4Data);
|
70
|
+
if (data) {
|
71
|
+
data->pj = NULL;
|
72
|
+
data->original_str = Qnil;
|
73
|
+
data->uses_radians = 0;
|
74
|
+
result = Data_Wrap_Struct(klass, mark_proj4_func, destroy_proj4_func, data);
|
75
|
+
}
|
76
|
+
return result;
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
static VALUE method_proj4_initialize_copy(VALUE self, VALUE orig)
|
81
|
+
{
|
82
|
+
RGeo_Proj4Data* self_data;
|
83
|
+
projPJ pj;
|
84
|
+
RGeo_Proj4Data* orig_data;
|
85
|
+
char* str;
|
86
|
+
|
87
|
+
// Clear out any existing value
|
88
|
+
self_data = RGEO_PROJ4_DATA_PTR(self);
|
89
|
+
pj = self_data->pj;
|
90
|
+
if (pj) {
|
91
|
+
pj_free(pj);
|
92
|
+
self_data->pj = NULL;
|
93
|
+
self_data->original_str = Qnil;
|
94
|
+
}
|
95
|
+
|
96
|
+
// Copy value from orig
|
97
|
+
orig_data = RGEO_PROJ4_DATA_PTR(orig);
|
98
|
+
if (!NIL_P(orig_data->original_str)) {
|
99
|
+
self_data->pj = pj_init_plus(RSTRING_PTR(orig_data->original_str));
|
100
|
+
}
|
101
|
+
else {
|
102
|
+
str = pj_get_def(orig_data->pj, 0);
|
103
|
+
self_data->pj = pj_init_plus(str);
|
104
|
+
pj_dalloc(str);
|
105
|
+
}
|
106
|
+
self_data->original_str = orig_data->original_str;
|
107
|
+
self_data->uses_radians = orig_data->uses_radians;
|
108
|
+
|
109
|
+
return self;
|
110
|
+
}
|
111
|
+
|
112
|
+
|
113
|
+
static VALUE method_proj4_set_value(VALUE self, VALUE str, VALUE uses_radians)
|
114
|
+
{
|
115
|
+
RGeo_Proj4Data* self_data;
|
116
|
+
projPJ pj;
|
117
|
+
|
118
|
+
Check_Type(str, T_STRING);
|
119
|
+
|
120
|
+
// Clear out any existing value
|
121
|
+
self_data = RGEO_PROJ4_DATA_PTR(self);
|
122
|
+
pj = self_data->pj;
|
123
|
+
if (pj) {
|
124
|
+
pj_free(pj);
|
125
|
+
self_data->pj = NULL;
|
126
|
+
self_data->original_str = Qnil;
|
127
|
+
}
|
128
|
+
|
129
|
+
// Set new data
|
130
|
+
self_data->pj = pj_init_plus(RSTRING_PTR(str));
|
131
|
+
self_data->original_str = str;
|
132
|
+
self_data->uses_radians = RTEST(uses_radians) ? 1 : 0;
|
133
|
+
|
134
|
+
return self;
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
static VALUE method_proj4_get_geographic(VALUE self)
|
139
|
+
{
|
140
|
+
VALUE result;
|
141
|
+
RGeo_Proj4Data* new_data;
|
142
|
+
RGeo_Proj4Data* self_data;
|
143
|
+
|
144
|
+
result = Qnil;
|
145
|
+
new_data = ALLOC(RGeo_Proj4Data);
|
146
|
+
if (new_data) {
|
147
|
+
self_data = RGEO_PROJ4_DATA_PTR(self);
|
148
|
+
new_data->pj = pj_latlong_from_proj(self_data->pj);
|
149
|
+
new_data->original_str = Qnil;
|
150
|
+
new_data->uses_radians = self_data->uses_radians;
|
151
|
+
result = Data_Wrap_Struct(CLASS_OF(self), mark_proj4_func, destroy_proj4_func, new_data);
|
152
|
+
}
|
153
|
+
return result;
|
154
|
+
}
|
155
|
+
|
156
|
+
|
157
|
+
static VALUE method_proj4_original_str(VALUE self)
|
158
|
+
{
|
159
|
+
return RGEO_PROJ4_DATA_PTR(self)->original_str;
|
160
|
+
}
|
161
|
+
|
162
|
+
|
163
|
+
static VALUE method_proj4_uses_radians(VALUE self)
|
164
|
+
{
|
165
|
+
return RGEO_PROJ4_DATA_PTR(self)->uses_radians ? Qtrue : Qfalse;
|
166
|
+
}
|
167
|
+
|
168
|
+
|
169
|
+
static VALUE method_proj4_canonical_str(VALUE self)
|
170
|
+
{
|
171
|
+
VALUE result;
|
172
|
+
projPJ pj;
|
173
|
+
char* str;
|
174
|
+
|
175
|
+
result = Qnil;
|
176
|
+
pj = RGEO_PROJ4_DATA_PTR(self)->pj;
|
177
|
+
if (pj) {
|
178
|
+
str = pj_get_def(pj, 0);
|
179
|
+
if (str) {
|
180
|
+
result = rb_str_new2(str);
|
181
|
+
pj_dalloc(str);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
return result;
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
static VALUE method_proj4_is_geographic(VALUE self)
|
189
|
+
{
|
190
|
+
VALUE result;
|
191
|
+
projPJ pj;
|
192
|
+
|
193
|
+
result = Qnil;
|
194
|
+
pj = RGEO_PROJ4_DATA_PTR(self)->pj;
|
195
|
+
if (pj) {
|
196
|
+
result = pj_is_latlong(pj) ? Qtrue : Qfalse;
|
197
|
+
}
|
198
|
+
return result;
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
static VALUE method_proj4_is_geocentric(VALUE self)
|
203
|
+
{
|
204
|
+
VALUE result;
|
205
|
+
projPJ pj;
|
206
|
+
|
207
|
+
result = Qnil;
|
208
|
+
pj = RGEO_PROJ4_DATA_PTR(self)->pj;
|
209
|
+
if (pj) {
|
210
|
+
result = pj_is_geocent(pj) ? Qtrue : Qfalse;
|
211
|
+
}
|
212
|
+
return result;
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
static VALUE method_proj4_is_valid(VALUE self)
|
217
|
+
{
|
218
|
+
return RGEO_PROJ4_DATA_PTR(self)->pj ? Qtrue : Qfalse;
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
static VALUE cmethod_proj4_version(VALUE module)
|
223
|
+
{
|
224
|
+
return INT2NUM(PJ_VERSION);
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
static VALUE cmethod_proj4_transform(VALUE module, VALUE from, VALUE to, VALUE x, VALUE y, VALUE z)
|
229
|
+
{
|
230
|
+
VALUE result;
|
231
|
+
projPJ from_pj;
|
232
|
+
projPJ to_pj;
|
233
|
+
double xval, yval, zval;
|
234
|
+
int err;
|
235
|
+
|
236
|
+
result = Qnil;
|
237
|
+
from_pj = RGEO_PROJ4_DATA_PTR(from)->pj;
|
238
|
+
to_pj = RGEO_PROJ4_DATA_PTR(to)->pj;
|
239
|
+
if (from_pj && to_pj) {
|
240
|
+
xval = rb_num2dbl(x);
|
241
|
+
yval = rb_num2dbl(y);
|
242
|
+
zval = 0.0;
|
243
|
+
if (!NIL_P(z)) {
|
244
|
+
zval = rb_num2dbl(z);
|
245
|
+
}
|
246
|
+
err = pj_transform(from_pj, to_pj, 1, 1, &xval, &yval, NIL_P(z) ? NULL : &zval);
|
247
|
+
if (!err && xval != HUGE_VAL && yval != HUGE_VAL && (NIL_P(z) || zval != HUGE_VAL)) {
|
248
|
+
result = rb_ary_new2(NIL_P(z) ? 2 : 3);
|
249
|
+
rb_ary_push(result, rb_float_new(xval));
|
250
|
+
rb_ary_push(result, rb_float_new(yval));
|
251
|
+
if (!NIL_P(z)) {
|
252
|
+
rb_ary_push(result, rb_float_new(zval));
|
253
|
+
}
|
254
|
+
}
|
255
|
+
}
|
256
|
+
return result;
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
static VALUE cmethod_proj4_create(VALUE klass, VALUE str, VALUE uses_radians)
|
261
|
+
{
|
262
|
+
VALUE result;
|
263
|
+
RGeo_Proj4Data* data;
|
264
|
+
|
265
|
+
result = Qnil;
|
266
|
+
Check_Type(str, T_STRING);
|
267
|
+
data = ALLOC(RGeo_Proj4Data);
|
268
|
+
if (data) {
|
269
|
+
data->pj = pj_init_plus(RSTRING_PTR(str));
|
270
|
+
data->original_str = str;
|
271
|
+
data->uses_radians = RTEST(uses_radians) ? 1 : 0;
|
272
|
+
result = Data_Wrap_Struct(klass, mark_proj4_func, destroy_proj4_func, data);
|
273
|
+
}
|
274
|
+
return result;
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
static void rgeo_init_proj4()
|
279
|
+
{
|
280
|
+
VALUE rgeo_module;
|
281
|
+
VALUE coordsys_module;
|
282
|
+
VALUE proj4_class;
|
283
|
+
|
284
|
+
rgeo_module = rb_define_module("RGeo");
|
285
|
+
coordsys_module = rb_define_module_under(rgeo_module, "CoordSys");
|
286
|
+
proj4_class = rb_define_class_under(coordsys_module, "Proj4", rb_cObject);
|
287
|
+
|
288
|
+
rb_define_alloc_func(proj4_class, alloc_proj4);
|
289
|
+
rb_define_module_function(proj4_class, "_create", cmethod_proj4_create, 2);
|
290
|
+
rb_define_method(proj4_class, "initialize_copy", method_proj4_initialize_copy, 1);
|
291
|
+
rb_define_method(proj4_class, "_set_value", method_proj4_set_value, 2);
|
292
|
+
rb_define_method(proj4_class, "_original_str", method_proj4_original_str, 0);
|
293
|
+
rb_define_method(proj4_class, "_canonical_str", method_proj4_canonical_str, 0);
|
294
|
+
rb_define_method(proj4_class, "_valid?", method_proj4_is_valid, 0);
|
295
|
+
rb_define_method(proj4_class, "_geographic?", method_proj4_is_geographic, 0);
|
296
|
+
rb_define_method(proj4_class, "_geocentric?", method_proj4_is_geocentric, 0);
|
297
|
+
rb_define_method(proj4_class, "_radians?", method_proj4_uses_radians, 0);
|
298
|
+
rb_define_method(proj4_class, "_get_geographic", method_proj4_get_geographic, 0);
|
299
|
+
rb_define_module_function(proj4_class, "_transform_coords", cmethod_proj4_transform, 5);
|
300
|
+
rb_define_module_function(proj4_class, "_proj_version", cmethod_proj4_version, 0);
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
#endif
|
305
|
+
|
306
|
+
|
307
|
+
void Init_proj4_c_impl()
|
308
|
+
{
|
309
|
+
#ifdef RGEO_PROJ4_SUPPORTED
|
310
|
+
rgeo_init_proj4();
|
311
|
+
#endif
|
312
|
+
}
|
313
|
+
|
314
|
+
|
315
|
+
RGEO_END_C
|