schleyfox-rgeo 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- 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,66 @@
|
|
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
|
+
#ifndef RGEO_GEOS_POLYGON_INCLUDED
|
39
|
+
#define RGEO_GEOS_POLYGON_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 polygon module. This should be called after
|
51
|
+
the geometry module is initialized.
|
52
|
+
*/
|
53
|
+
void rgeo_init_geos_polygon(RGeo_Globals* globals);
|
54
|
+
|
55
|
+
/*
|
56
|
+
Comopares the values of two GEOS polygons. The two given geometries MUST
|
57
|
+
be polygon types.
|
58
|
+
Returns Qtrue if the polygons are equal, Qfalse if they are inequal, or
|
59
|
+
Qnil if an error occurs.
|
60
|
+
*/
|
61
|
+
VALUE rgeo_geos_polygons_eql(GEOSContextHandle_t context, const GEOSGeometry* geom1, const GEOSGeometry* geom2, char check_z);
|
62
|
+
|
63
|
+
|
64
|
+
RGEO_END_C
|
65
|
+
|
66
|
+
#endif
|
@@ -0,0 +1,50 @@
|
|
1
|
+
/*
|
2
|
+
-----------------------------------------------------------------------------
|
3
|
+
|
4
|
+
Preface header 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
|
+
#ifdef HAVE_GEOS_C_H
|
39
|
+
#ifdef HAVE_INITGEOS_R
|
40
|
+
#define RGEO_GEOS_SUPPORTED
|
41
|
+
#endif
|
42
|
+
#endif
|
43
|
+
|
44
|
+
#ifdef __cplusplus
|
45
|
+
#define RGEO_BEGIN_C extern "C" {
|
46
|
+
#define RGEO_END_C }
|
47
|
+
#else
|
48
|
+
#define RGEO_BEGIN_C
|
49
|
+
#define RGEO_END_C
|
50
|
+
#endif
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Makefile builder for Proj4 wrapper
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
# Copyright 2010 Daniel Azuma
|
7
|
+
#
|
8
|
+
# All rights reserved.
|
9
|
+
#
|
10
|
+
# Redistribution and use in source and binary forms, with or without
|
11
|
+
# modification, are permitted provided that the following conditions are met:
|
12
|
+
#
|
13
|
+
# * Redistributions of source code must retain the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer.
|
15
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
+
# this list of conditions and the following disclaimer in the documentation
|
17
|
+
# and/or other materials provided with the distribution.
|
18
|
+
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
+
# contributors to this software, may be used to endorse or promote products
|
20
|
+
# derived from this software without specific prior written permission.
|
21
|
+
#
|
22
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
+
# -----------------------------------------------------------------------------
|
34
|
+
;
|
35
|
+
|
36
|
+
|
37
|
+
if ::RUBY_DESCRIPTION =~ /^jruby\s/
|
38
|
+
|
39
|
+
::File.open('Makefile', 'w'){ |f_| f_.write(".PHONY: install\ninstall:\n") }
|
40
|
+
|
41
|
+
else
|
42
|
+
|
43
|
+
require 'mkmf'
|
44
|
+
|
45
|
+
header_dirs_ =
|
46
|
+
[
|
47
|
+
'/usr/local/include',
|
48
|
+
'/usr/local/proj/include',
|
49
|
+
'/usr/local/proj4/include',
|
50
|
+
'/opt/local/include',
|
51
|
+
'/opt/proj/include',
|
52
|
+
'/opt/proj4/include',
|
53
|
+
'/opt/include',
|
54
|
+
::Config::CONFIG['includedir'],
|
55
|
+
'/usr/include',
|
56
|
+
]
|
57
|
+
lib_dirs_ =
|
58
|
+
[
|
59
|
+
'/usr/local/lib',
|
60
|
+
'/usr/local/proj/lib',
|
61
|
+
'/usr/local/proj4/lib',
|
62
|
+
'/opt/local/lib',
|
63
|
+
'/opt/proj/lib',
|
64
|
+
'/opt/proj4/lib',
|
65
|
+
'/opt/lib',
|
66
|
+
::Config::CONFIG['libdir'],
|
67
|
+
'/usr/lib',
|
68
|
+
]
|
69
|
+
header_dirs_.delete_if{ |path_| !::File.directory?(path_) }
|
70
|
+
lib_dirs_.delete_if{ |path_| !::File.directory?(path_) }
|
71
|
+
|
72
|
+
found_proj_ = false
|
73
|
+
header_dirs_, lib_dirs_ = dir_config('proj', header_dirs_, lib_dirs_)
|
74
|
+
if have_header('proj_api.h')
|
75
|
+
$libs << ' -lproj'
|
76
|
+
if have_func('pj_init_plus', 'proj_api.h')
|
77
|
+
found_proj_ = true
|
78
|
+
else
|
79
|
+
$libs.gsub!(' -lproj', '')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
unless found_proj_
|
83
|
+
puts "**** WARNING: Unable to find Proj headers or Proj version is too old."
|
84
|
+
puts "**** Compiling without Proj support."
|
85
|
+
end
|
86
|
+
create_makefile('rgeo/coord_sys/proj4_c_impl')
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,271 @@
|
|
1
|
+
/*
|
2
|
+
-----------------------------------------------------------------------------
|
3
|
+
|
4
|
+
Main initializer for Proj4 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
|
+
#ifdef HAVE_PROJ_API_H
|
39
|
+
#ifdef HAVE_PJ_INIT_PLUS
|
40
|
+
#define RGEO_PROJ4_SUPPORTED
|
41
|
+
#endif
|
42
|
+
#endif
|
43
|
+
|
44
|
+
#ifdef __cplusplus
|
45
|
+
#define RGEO_BEGIN_C extern "C" {
|
46
|
+
#define RGEO_END_C }
|
47
|
+
#else
|
48
|
+
#define RGEO_BEGIN_C
|
49
|
+
#define RGEO_END_C
|
50
|
+
#endif
|
51
|
+
|
52
|
+
|
53
|
+
#ifdef RGEO_PROJ4_SUPPORTED
|
54
|
+
|
55
|
+
#include <ruby.h>
|
56
|
+
#include <proj_api.h>
|
57
|
+
|
58
|
+
#endif
|
59
|
+
|
60
|
+
|
61
|
+
RGEO_BEGIN_C
|
62
|
+
|
63
|
+
|
64
|
+
#ifdef RGEO_PROJ4_SUPPORTED
|
65
|
+
|
66
|
+
|
67
|
+
typedef struct {
|
68
|
+
projPJ pj;
|
69
|
+
VALUE original_str;
|
70
|
+
char uses_radians;
|
71
|
+
} RGeo_Proj4Data;
|
72
|
+
|
73
|
+
|
74
|
+
#define RGEO_PROJ4_DATA_PTR(obj) ((RGeo_Proj4Data*)DATA_PTR(obj))
|
75
|
+
|
76
|
+
|
77
|
+
// Destroy function for proj data.
|
78
|
+
|
79
|
+
static void destroy_proj4_func(RGeo_Proj4Data* data)
|
80
|
+
{
|
81
|
+
if (data->pj) {
|
82
|
+
pj_free(data->pj);
|
83
|
+
}
|
84
|
+
free(data);
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
static void mark_proj4_func(RGeo_Proj4Data* data)
|
89
|
+
{
|
90
|
+
if (!NIL_P(data->original_str)) {
|
91
|
+
rb_gc_mark(data->original_str);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
static VALUE alloc_proj4(VALUE klass)
|
97
|
+
{
|
98
|
+
VALUE result = Qnil;
|
99
|
+
RGeo_Proj4Data* data = ALLOC(RGeo_Proj4Data);
|
100
|
+
if (data) {
|
101
|
+
data->pj = NULL;
|
102
|
+
data->original_str = Qnil;
|
103
|
+
data->uses_radians = 0;
|
104
|
+
result = Data_Wrap_Struct(klass, mark_proj4_func, destroy_proj4_func, data);
|
105
|
+
}
|
106
|
+
return result;
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
static VALUE method_proj4_initialize_copy(VALUE self, VALUE orig)
|
111
|
+
{
|
112
|
+
// Clear out any existing value
|
113
|
+
RGeo_Proj4Data* self_data = RGEO_PROJ4_DATA_PTR(self);
|
114
|
+
projPJ pj = self_data->pj;
|
115
|
+
if (pj) {
|
116
|
+
pj_free(pj);
|
117
|
+
self_data->pj = NULL;
|
118
|
+
self_data->original_str = Qnil;
|
119
|
+
}
|
120
|
+
|
121
|
+
// Copy value from orig
|
122
|
+
RGeo_Proj4Data* orig_data = RGEO_PROJ4_DATA_PTR(orig);
|
123
|
+
self_data->pj = orig_data->pj;
|
124
|
+
self_data->original_str = orig_data->original_str;
|
125
|
+
self_data->uses_radians = orig_data->uses_radians;
|
126
|
+
|
127
|
+
return self;
|
128
|
+
}
|
129
|
+
|
130
|
+
|
131
|
+
static VALUE method_proj4_get_geographic(VALUE self)
|
132
|
+
{
|
133
|
+
VALUE result = Qnil;
|
134
|
+
RGeo_Proj4Data* new_data = ALLOC(RGeo_Proj4Data);
|
135
|
+
if (new_data) {
|
136
|
+
RGeo_Proj4Data* self_data = RGEO_PROJ4_DATA_PTR(self);
|
137
|
+
new_data->pj = pj_latlong_from_proj(self_data->pj);
|
138
|
+
new_data->original_str = Qnil;
|
139
|
+
new_data->uses_radians = self_data->uses_radians;
|
140
|
+
result = Data_Wrap_Struct(CLASS_OF(self), mark_proj4_func, destroy_proj4_func, new_data);
|
141
|
+
}
|
142
|
+
return result;
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
static VALUE method_proj4_original_str(VALUE self)
|
147
|
+
{
|
148
|
+
return RGEO_PROJ4_DATA_PTR(self)->original_str;
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
static VALUE method_proj4_uses_radians(VALUE self)
|
153
|
+
{
|
154
|
+
return RGEO_PROJ4_DATA_PTR(self)->uses_radians ? Qtrue : Qfalse;
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
static VALUE method_proj4_canonical_str(VALUE self)
|
159
|
+
{
|
160
|
+
VALUE result = Qnil;
|
161
|
+
projPJ pj = RGEO_PROJ4_DATA_PTR(self)->pj;
|
162
|
+
if (pj) {
|
163
|
+
char* str = pj_get_def(pj, 0);
|
164
|
+
if (str) {
|
165
|
+
result = rb_str_new2(str);
|
166
|
+
pj_dalloc(str);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
return result;
|
170
|
+
}
|
171
|
+
|
172
|
+
|
173
|
+
static VALUE method_proj4_is_geographic(VALUE self)
|
174
|
+
{
|
175
|
+
VALUE result = Qnil;
|
176
|
+
projPJ pj = RGEO_PROJ4_DATA_PTR(self)->pj;
|
177
|
+
if (pj) {
|
178
|
+
result = pj_is_latlong(pj) ? Qtrue : Qfalse;
|
179
|
+
}
|
180
|
+
return result;
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
static VALUE method_proj4_is_geocentric(VALUE self)
|
185
|
+
{
|
186
|
+
VALUE result = Qnil;
|
187
|
+
projPJ pj = RGEO_PROJ4_DATA_PTR(self)->pj;
|
188
|
+
if (pj) {
|
189
|
+
result = pj_is_geocent(pj) ? Qtrue : Qfalse;
|
190
|
+
}
|
191
|
+
return result;
|
192
|
+
}
|
193
|
+
|
194
|
+
|
195
|
+
static VALUE method_proj4_is_valid(VALUE self)
|
196
|
+
{
|
197
|
+
return RGEO_PROJ4_DATA_PTR(self)->pj ? Qtrue : Qfalse;
|
198
|
+
}
|
199
|
+
|
200
|
+
|
201
|
+
static VALUE cmethod_proj4_transform(VALUE method, VALUE from, VALUE to, VALUE x, VALUE y, VALUE z)
|
202
|
+
{
|
203
|
+
VALUE result = Qnil;
|
204
|
+
projPJ from_pj = RGEO_PROJ4_DATA_PTR(from)->pj;
|
205
|
+
projPJ to_pj = RGEO_PROJ4_DATA_PTR(to)->pj;
|
206
|
+
if (from_pj && to_pj) {
|
207
|
+
double xval = rb_num2dbl(x);
|
208
|
+
double yval = rb_num2dbl(y);
|
209
|
+
double zval = 0.0;
|
210
|
+
if (!NIL_P(z)) {
|
211
|
+
zval = rb_num2dbl(z);
|
212
|
+
}
|
213
|
+
int err = pj_transform(from_pj, to_pj, 1, 1, &xval, &yval, NIL_P(z) ? NULL : &zval);
|
214
|
+
if (!err && xval != HUGE_VAL && yval != HUGE_VAL && (NIL_P(z) || zval != HUGE_VAL)) {
|
215
|
+
result = rb_ary_new2(NIL_P(z) ? 2 : 3);
|
216
|
+
rb_ary_push(result, rb_float_new(xval));
|
217
|
+
rb_ary_push(result, rb_float_new(yval));
|
218
|
+
if (!NIL_P(z)) {
|
219
|
+
rb_ary_push(result, rb_float_new(zval));
|
220
|
+
}
|
221
|
+
}
|
222
|
+
}
|
223
|
+
return result;
|
224
|
+
}
|
225
|
+
|
226
|
+
|
227
|
+
static VALUE cmethod_proj4_create(VALUE klass, VALUE str, VALUE uses_radians)
|
228
|
+
{
|
229
|
+
VALUE result = Qnil;
|
230
|
+
Check_Type(str, T_STRING);
|
231
|
+
RGeo_Proj4Data* data = ALLOC(RGeo_Proj4Data);
|
232
|
+
if (data) {
|
233
|
+
data->pj = pj_init_plus(RSTRING_PTR(str));
|
234
|
+
data->original_str = str;
|
235
|
+
data->uses_radians = RTEST(uses_radians) ? 1 : 0;
|
236
|
+
result = Data_Wrap_Struct(klass, mark_proj4_func, destroy_proj4_func, data);
|
237
|
+
}
|
238
|
+
return result;
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
static void rgeo_init_proj4()
|
243
|
+
{
|
244
|
+
VALUE rgeo_module = rb_define_module("RGeo");
|
245
|
+
VALUE coordsys_module = rb_define_module_under(rgeo_module, "CoordSys");
|
246
|
+
VALUE proj4_class = rb_define_class_under(coordsys_module, "Proj4", rb_cObject);
|
247
|
+
rb_define_module_function(proj4_class, "_create", cmethod_proj4_create, 2);
|
248
|
+
rb_define_method(proj4_class, "initialize_copy", method_proj4_initialize_copy, 1);
|
249
|
+
rb_define_method(proj4_class, "_original_str", method_proj4_original_str, 0);
|
250
|
+
rb_define_method(proj4_class, "_canonical_str", method_proj4_canonical_str, 0);
|
251
|
+
rb_define_method(proj4_class, "_valid?", method_proj4_is_valid, 0);
|
252
|
+
rb_define_method(proj4_class, "_geographic?", method_proj4_is_geographic, 0);
|
253
|
+
rb_define_method(proj4_class, "_geocentric?", method_proj4_is_geocentric, 0);
|
254
|
+
rb_define_method(proj4_class, "_radians?", method_proj4_uses_radians, 0);
|
255
|
+
rb_define_method(proj4_class, "_get_geographic", method_proj4_get_geographic, 0);
|
256
|
+
rb_define_module_function(proj4_class, "_transform_coords", cmethod_proj4_transform, 5);
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
#endif
|
261
|
+
|
262
|
+
|
263
|
+
void Init_proj4_c_impl()
|
264
|
+
{
|
265
|
+
#ifdef RGEO_PROJ4_SUPPORTED
|
266
|
+
rgeo_init_proj4();
|
267
|
+
#endif
|
268
|
+
}
|
269
|
+
|
270
|
+
|
271
|
+
RGEO_END_C
|