rgeo 0.1.19 → 0.1.20
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 +11 -0
- data/README.rdoc +23 -7
- data/Version +1 -1
- data/ext/geos_c_impl/factory.c +1 -1
- data/{lib/rgeo/geography/simple_mercator.rb → ext/proj4_c_impl/extconf.rb} +35 -30
- data/ext/proj4_c_impl/main.c +256 -0
- data/lib/rgeo.rb +54 -42
- data/lib/rgeo/active_record/arel_modifications.rb +2 -2
- data/lib/rgeo/active_record/base_modifications.rb +1 -1
- data/lib/rgeo/active_record/mysql_common.rb +12 -12
- data/lib/rgeo/all.rb +5 -4
- data/lib/rgeo/cartesian.rb +3 -2
- data/lib/rgeo/cartesian/bounding_box.rb +9 -9
- data/lib/rgeo/cartesian/factory.rb +30 -13
- data/lib/rgeo/cartesian/feature_classes.rb +33 -33
- data/lib/rgeo/cartesian/interface.rb +2 -2
- data/lib/rgeo/{geography/all.rb → coord_sys.rb} +22 -4
- data/lib/rgeo/coord_sys/proj4.rb +275 -0
- data/lib/rgeo/{errors.rb → error.rb} +5 -6
- data/lib/rgeo/{features.rb → feature.rb} +22 -20
- data/lib/rgeo/{features → feature}/curve.rb +6 -6
- data/lib/rgeo/{features → feature}/factory.rb +19 -3
- data/lib/rgeo/{features → feature}/factory_generator.rb +1 -1
- data/lib/rgeo/{features → feature}/geometry.rb +34 -34
- data/lib/rgeo/{features → feature}/geometry_collection.rb +4 -4
- data/lib/rgeo/{features → feature}/line.rb +1 -1
- data/lib/rgeo/{features → feature}/line_string.rb +4 -4
- data/lib/rgeo/{features → feature}/linear_ring.rb +1 -1
- data/lib/rgeo/{features → feature}/multi_curve.rb +3 -3
- data/lib/rgeo/{features → feature}/multi_line_string.rb +1 -1
- data/lib/rgeo/{features → feature}/multi_point.rb +1 -1
- data/lib/rgeo/{features → feature}/multi_polygon.rb +1 -1
- data/lib/rgeo/{features → feature}/multi_surface.rb +4 -4
- data/lib/rgeo/{features → feature}/point.rb +5 -5
- data/lib/rgeo/{features → feature}/polygon.rb +5 -5
- data/lib/rgeo/{features → feature}/surface.rb +4 -4
- data/lib/rgeo/feature/types.rb +301 -0
- data/lib/rgeo/geo_json.rb +1 -1
- data/lib/rgeo/geo_json/coder.rb +13 -13
- data/lib/rgeo/geo_json/interface.rb +2 -2
- data/lib/rgeo/geography.rb +33 -6
- data/lib/rgeo/geography/factory.rb +82 -39
- data/lib/rgeo/geography/interface.rb +135 -89
- data/lib/rgeo/geography/proj4_projector.rb +98 -0
- data/lib/rgeo/geography/projected_feature_classes.rb +213 -0
- data/lib/rgeo/geography/projected_feature_methods.rb +228 -0
- data/lib/rgeo/geography/projected_window.rb +7 -7
- data/lib/rgeo/geography/simple_mercator_projector.rb +133 -0
- data/lib/rgeo/geography/spherical_feature_classes.rb +212 -0
- data/lib/rgeo/geography/{simple_spherical/feature_methods.rb → spherical_feature_methods.rb} +39 -43
- data/lib/rgeo/geography/{simple_spherical/calculations.rb → spherical_math.rb} +7 -7
- data/lib/rgeo/geos.rb +1 -1
- data/lib/rgeo/geos/factory.rb +37 -19
- data/lib/rgeo/geos/impl_additions.rb +10 -11
- data/lib/rgeo/geos/interface.rb +1 -1
- data/lib/rgeo/geos/zm_factory.rb +15 -15
- data/lib/rgeo/geos/zm_impl.rb +10 -10
- data/lib/rgeo/{impl_helpers.rb → impl_helper.rb} +8 -8
- data/lib/rgeo/{impl_helpers → impl_helper}/basic_geometry_collection_methods.rb +13 -13
- data/lib/rgeo/{impl_helpers → impl_helper}/basic_geometry_methods.rb +2 -2
- data/lib/rgeo/{impl_helpers → impl_helper}/basic_line_string_methods.rb +13 -13
- data/lib/rgeo/{impl_helpers → impl_helper}/basic_point_methods.rb +5 -5
- data/lib/rgeo/{impl_helpers → impl_helper}/basic_polygon_methods.rb +6 -6
- data/lib/rgeo/{impl_helpers → impl_helper}/math.rb +1 -1
- data/lib/rgeo/shapefile.rb +1 -1
- data/lib/rgeo/shapefile/reader.rb +3 -3
- data/lib/rgeo/wkrep.rb +1 -1
- data/lib/rgeo/wkrep/wkb_generator.rb +17 -17
- data/lib/rgeo/wkrep/wkb_parser.rb +12 -12
- data/lib/rgeo/wkrep/wkt_generator.rb +8 -8
- data/lib/rgeo/wkrep/wkt_parser.rb +10 -10
- data/{tests → test}/active_record/readme.txt +0 -0
- data/{tests → test}/active_record/tc_mysqlspatial.rb +2 -2
- data/{tests → test}/common/geometry_collection_tests.rb +22 -22
- data/{tests → test}/common/line_string_tests.rb +20 -20
- data/{tests → test}/common/multi_line_string_tests.rb +19 -19
- data/{tests → test}/common/multi_point_tests.rb +17 -17
- data/{tests → test}/common/multi_polygon_tests.rb +16 -16
- data/{tests → test}/common/point_tests.rb +9 -9
- data/{tests → test}/common/polygon_tests.rb +9 -9
- data/test/coord_sys/tc_proj4.rb +111 -0
- data/{tests → test}/geos/tc_factory.rb +1 -1
- data/{tests → test}/geos/tc_geometry_collection.rb +1 -1
- data/{tests → test}/geos/tc_line_string.rb +0 -0
- data/{tests → test}/geos/tc_misc.rb +1 -1
- data/{tests → test}/geos/tc_multi_line_string.rb +1 -1
- data/{tests → test}/geos/tc_multi_point.rb +1 -1
- data/{tests → test}/geos/tc_multi_polygon.rb +1 -1
- data/{tests → test}/geos/tc_point.rb +1 -1
- data/{tests → test}/geos/tc_polygon.rb +0 -0
- data/{tests → test}/geos/tc_zmfactory.rb +2 -2
- data/test/projected_geography/tc_geometry_collection.rb +62 -0
- data/test/projected_geography/tc_line_string.rb +62 -0
- data/test/projected_geography/tc_multi_line_string.rb +62 -0
- data/test/projected_geography/tc_multi_point.rb +62 -0
- data/test/projected_geography/tc_multi_polygon.rb +63 -0
- data/test/projected_geography/tc_point.rb +93 -0
- data/test/projected_geography/tc_polygon.rb +62 -0
- data/{tests → test}/shapefile/shapelib_testcases/readme.txt +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test.dbf +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test0.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test0.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test1.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test1.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test10.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test10.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test11.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test11.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test12.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test12.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test13.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test13.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test2.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test2.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test3.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test3.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test4.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test4.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test5.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test5.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test6.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test6.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test7.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test7.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test8.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test8.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test9.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test9.shx +0 -0
- data/{tests → test}/shapefile/tc_shapelib_tests.rb +17 -17
- data/{tests → test}/simple_cartesian/tc_calculations.rb +0 -0
- data/{tests → test}/simple_cartesian/tc_geometry_collection.rb +0 -0
- data/{tests → test}/simple_cartesian/tc_line_string.rb +0 -0
- data/{tests → test}/simple_cartesian/tc_multi_line_string.rb +0 -0
- data/{tests → test}/simple_cartesian/tc_multi_point.rb +0 -0
- data/{tests → test}/simple_cartesian/tc_multi_polygon.rb +0 -0
- data/{tests → test}/simple_cartesian/tc_point.rb +0 -0
- data/{tests → test}/simple_cartesian/tc_polygon.rb +0 -0
- data/{tests → test}/simple_mercator/tc_geometry_collection.rb +1 -1
- data/{tests → test}/simple_mercator/tc_line_string.rb +0 -0
- data/{tests → test}/simple_mercator/tc_multi_line_string.rb +1 -1
- data/{tests → test}/simple_mercator/tc_multi_point.rb +1 -1
- data/{tests → test}/simple_mercator/tc_multi_polygon.rb +1 -1
- data/{tests → test}/simple_mercator/tc_point.rb +2 -2
- data/{tests → test}/simple_mercator/tc_polygon.rb +0 -0
- data/{tests → test}/simple_mercator/tc_window.rb +1 -1
- data/test/spherical_geography/tc_calculations.rb +203 -0
- data/{tests/simple_spherical → test/spherical_geography}/tc_geometry_collection.rb +2 -2
- data/{tests/simple_spherical → test/spherical_geography}/tc_line_string.rb +2 -2
- data/{tests/simple_spherical → test/spherical_geography}/tc_multi_line_string.rb +2 -2
- data/{tests/simple_spherical → test/spherical_geography}/tc_multi_point.rb +2 -2
- data/{tests/simple_spherical → test/spherical_geography}/tc_multi_polygon.rb +3 -3
- data/{tests/simple_spherical → test/spherical_geography}/tc_point.rb +7 -7
- data/{tests/simple_spherical → test/spherical_geography}/tc_polygon.rb +2 -2
- data/{tests → test}/tc_cartesian_analysis.rb +0 -0
- data/{tests → test}/tc_geojson.rb +0 -0
- data/{tests → test}/tc_oneoff.rb +2 -1
- data/{tests → test}/wkrep/tc_wkb_generator.rb +0 -0
- data/{tests → test}/wkrep/tc_wkb_parser.rb +32 -32
- data/{tests → test}/wkrep/tc_wkt_generator.rb +0 -0
- data/{tests → test}/wkrep/tc_wkt_parser.rb +46 -46
- metadata +183 -164
- data/lib/rgeo/features/types.rb +0 -272
- data/lib/rgeo/geography/simple_mercator/feature_classes.rb +0 -279
- data/lib/rgeo/geography/simple_mercator/feature_methods.rb +0 -278
- data/lib/rgeo/geography/simple_mercator/projector.rb +0 -112
- data/lib/rgeo/geography/simple_spherical.rb +0 -68
- data/lib/rgeo/geography/simple_spherical/feature_classes.rb +0 -216
- data/tests/simple_spherical/tc_calculations.rb +0 -203
data/History.rdoc
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
=== 0.1.20 / 2010-11-30
|
|
2
|
+
|
|
3
|
+
* API CHANGE: Methods that raised MethodUnimplemented now raise UnsupportedCapability instead. Removed MethodUnimplemented.
|
|
4
|
+
* API CHANGE: Renamed RGeo::Features to RGeo::Feature, RGeo::Errors to RGeo::Error, and RGeo::ImplHelpers to RGeo::ImplHelper. The old pluralized names are aliased to the new names for now for backward compatibility, though they are deprecated and will be removed shortly.
|
|
5
|
+
* Renamed the tests directory to test. Generally speaking, I'm getting rid of pluralized names.
|
|
6
|
+
* Added RGeo::CoordSys::Proj4 representing a proj4 coordinate system. It uses the proj4 library.
|
|
7
|
+
* Added Factory#proj4 as an optional method indicated by the :proj4 capability.
|
|
8
|
+
* All existing geometry implementations now support proj4.
|
|
9
|
+
* You can now cause casting to transform between proj4 projections by specifying the :project parameter.
|
|
10
|
+
* A Geography implementation with an arbitrary projection backed by proj4 is now available.
|
|
11
|
+
|
|
1
12
|
=== 0.1.19 / 2010-11-23
|
|
2
13
|
|
|
3
14
|
* The GEOS implementation now supports ZM (4-dimensional data), via a wrapper since the underlying GEOS library doesn't support 4d data natively.
|
data/README.rdoc
CHANGED
|
@@ -47,11 +47,15 @@ RGeo has the following prerequisites:
|
|
|
47
47
|
available without it. This C/C++ library may be available via your
|
|
48
48
|
operating system's package manager, or you can download it from
|
|
49
49
|
http://geos.osgeo.org/
|
|
50
|
+
* Proj 4.7.0 or later is also recommended. This is needed if you want
|
|
51
|
+
to translate coordinates between geographic projections. It also may
|
|
52
|
+
be available via your operating system's package manager, or from
|
|
53
|
+
http://trac.osgeo.org/proj/
|
|
50
54
|
* If you are using the GeoJSON tools under Ruby 1.8.7, you should
|
|
51
55
|
install the "json" gem. Ruby 1.9 has JSON support in its standard
|
|
52
56
|
library and does not require the gem.
|
|
53
57
|
* If you are using the shapefile reader, you should install the "dbf"
|
|
54
|
-
gem version 1.5.2 or later, which is required to read the attributes.
|
|
58
|
+
gem, version 1.5.2 or later, which is required to read the attributes.
|
|
55
59
|
* The ActiveRecord adapters for MySQL Spatial, PostGIS, and SpatiaLite
|
|
56
60
|
require ActiveRecord 3.0.3 or later, Arel 2.0 or later, and the
|
|
57
61
|
corresponding database driver gems (e.g. "mysql" or "mysql2").
|
|
@@ -77,18 +81,28 @@ the switches interpreted by the gem command. For example:
|
|
|
77
81
|
|
|
78
82
|
gem install rgeo -- --with-geos-dir=/path/to/my/geos/installation
|
|
79
83
|
|
|
84
|
+
Similarly, the gem installation looks for the Proj.4 library in the
|
|
85
|
+
following locations by default:
|
|
86
|
+
|
|
87
|
+
* /usr/local
|
|
88
|
+
* /usr/local/proj
|
|
89
|
+
* /usr/local/proj4
|
|
90
|
+
* /opt/local
|
|
91
|
+
* /usr
|
|
92
|
+
|
|
93
|
+
If Proj4 is installed in a different location, you must provide its
|
|
94
|
+
installation prefix directory using the "--with-proj-dir" option.
|
|
95
|
+
|
|
80
96
|
=== To-do items
|
|
81
97
|
|
|
82
98
|
This is our planned feature roadmap, in rough priority order.
|
|
83
99
|
|
|
84
|
-
* Projection subsystem, and support for arbitrary projections in the
|
|
85
|
-
geography module, utilizing proj4.
|
|
86
100
|
* SpatiaLite and PostGIS adapters for ActiveRecord. (We already have an
|
|
87
101
|
adapter for MySQL Spatial.)
|
|
88
102
|
* Integration with certain third-party services such as SimpleGeo.
|
|
89
103
|
* Support for bbox and crs elements of GeoJSON.
|
|
90
104
|
* Ellipsoidal geography implementation, probably utilizing geographiclib.
|
|
91
|
-
* Rubinius support for
|
|
105
|
+
* Rubinius support for C library integration.
|
|
92
106
|
* JRuby support via JTS integration.
|
|
93
107
|
* Support for writing shapefiles. (Reading is already implemented.)
|
|
94
108
|
* Read and write other formats such as GeoRSS and KML.
|
|
@@ -109,9 +123,11 @@ RGeo is written by Daniel Azuma (http://www.daniel-azuma.com/).
|
|
|
109
123
|
|
|
110
124
|
Development of RGeo is sponsored by GeoPage, Inc. (http://www.geopage.com/).
|
|
111
125
|
|
|
112
|
-
RGeo links with the
|
|
113
|
-
|
|
114
|
-
|
|
126
|
+
RGeo links with the GEOS library to handle most Cartesian geometric
|
|
127
|
+
calculations, and with the Proj4 library to handle projections and
|
|
128
|
+
coordinate transforms. These libraries are maintained by the Open Source
|
|
129
|
+
Geospatial Foundation; these and other OSGeo projects can be found on
|
|
130
|
+
OSGeo's web site (http://www.osgeo.org/).
|
|
115
131
|
|
|
116
132
|
The ActiveRecord adapters owe some debt to the spatial_adapter plugin
|
|
117
133
|
(http://github.com/fragility/spatial_adapter). We made a few different
|
data/Version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.20
|
data/ext/geos_c_impl/factory.c
CHANGED
|
@@ -223,7 +223,7 @@ RGeo_Globals* rgeo_init_geos_factory()
|
|
|
223
223
|
RGeo_Globals* globals = ALLOC(RGeo_Globals);
|
|
224
224
|
VALUE rgeo_module = rb_define_module("RGeo");
|
|
225
225
|
globals->geos_module = rb_define_module_under(rgeo_module, "Geos");
|
|
226
|
-
globals->features_module = rb_define_module_under(rgeo_module, "
|
|
226
|
+
globals->features_module = rb_define_module_under(rgeo_module, "Feature");
|
|
227
227
|
|
|
228
228
|
// Add C methods to the factory.
|
|
229
229
|
VALUE geos_factory_class = rb_const_get_at(globals->geos_module, rb_intern("Factory"));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# -----------------------------------------------------------------------------
|
|
2
2
|
#
|
|
3
|
-
#
|
|
3
|
+
# Makefile builder for Proj4 wrapper
|
|
4
4
|
#
|
|
5
5
|
# -----------------------------------------------------------------------------
|
|
6
6
|
# Copyright 2010 Daniel Azuma
|
|
@@ -34,36 +34,41 @@
|
|
|
34
34
|
;
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
require '
|
|
37
|
+
require 'mkmf'
|
|
38
38
|
|
|
39
|
+
header_dirs_ =
|
|
40
|
+
[
|
|
41
|
+
'/usr/local/include',
|
|
42
|
+
'/usr/local/proj/include',
|
|
43
|
+
'/usr/local/proj4/include',
|
|
44
|
+
'/opt/local/include',
|
|
45
|
+
::Config::CONFIG['includedir'],
|
|
46
|
+
'/usr/include',
|
|
47
|
+
]
|
|
48
|
+
lib_dirs_ =
|
|
49
|
+
[
|
|
50
|
+
'/usr/local/lib',
|
|
51
|
+
'/usr/local/proj/lib',
|
|
52
|
+
'/usr/local/proj4/lib',
|
|
53
|
+
'/opt/local/lib',
|
|
54
|
+
::Config::CONFIG['libdir'],
|
|
55
|
+
'/usr/lib',
|
|
56
|
+
]
|
|
57
|
+
header_dirs_.delete_if{ |path_| !::File.directory?(path_) }
|
|
58
|
+
lib_dirs_.delete_if{ |path_| !::File.directory?(path_) }
|
|
39
59
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
|
|
60
|
+
found_proj_ = false
|
|
61
|
+
header_dirs_, lib_dirs_ = dir_config('proj', header_dirs_, lib_dirs_)
|
|
62
|
+
if have_header('proj_api.h')
|
|
63
|
+
$libs << ' -lproj'
|
|
64
|
+
if have_func('pj_init_plus', 'proj_api.h')
|
|
65
|
+
found_proj_ = true
|
|
66
|
+
else
|
|
67
|
+
$libs.gsub!(' -lproj', '')
|
|
51
68
|
end
|
|
52
|
-
|
|
53
|
-
|
|
54
69
|
end
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
'wkrep',
|
|
61
|
-
'impl_helpers',
|
|
62
|
-
'cartesian',
|
|
63
|
-
'geography/simple_mercator/projector',
|
|
64
|
-
'geography/simple_mercator/feature_methods',
|
|
65
|
-
'geography/simple_mercator/feature_classes',
|
|
66
|
-
'geography/factory',
|
|
67
|
-
'geography/projected_window',
|
|
68
|
-
]
|
|
69
|
-
paths_.each{ |path_| require "rgeo/#{path_}" }
|
|
70
|
+
unless found_proj_
|
|
71
|
+
puts "**** WARNING: Unable to find Proj headers or Proj version is too old."
|
|
72
|
+
puts "**** Compiling without Proj support."
|
|
73
|
+
end
|
|
74
|
+
create_makefile('coord_sys/proj4_c_impl')
|
|
@@ -0,0 +1,256 @@
|
|
|
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
|
+
} RGeo_Proj4Data;
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
#define RGEO_PROJ4_DATA_PTR(obj) ((RGeo_Proj4Data*)DATA_PTR(obj))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
// Destroy function for proj data.
|
|
77
|
+
|
|
78
|
+
static void destroy_proj4_func(RGeo_Proj4Data* data)
|
|
79
|
+
{
|
|
80
|
+
if (data->pj) {
|
|
81
|
+
pj_free(data->pj);
|
|
82
|
+
}
|
|
83
|
+
free(data);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
static void mark_proj4_func(RGeo_Proj4Data* data)
|
|
88
|
+
{
|
|
89
|
+
if (!NIL_P(data->original_str)) {
|
|
90
|
+
rb_gc_mark(data->original_str);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
static VALUE alloc_proj4(VALUE klass)
|
|
96
|
+
{
|
|
97
|
+
VALUE result = Qnil;
|
|
98
|
+
RGeo_Proj4Data* data = ALLOC(RGeo_Proj4Data);
|
|
99
|
+
if (data) {
|
|
100
|
+
data->pj = NULL;
|
|
101
|
+
data->original_str = Qnil;
|
|
102
|
+
result = Data_Wrap_Struct(klass, mark_proj4_func, destroy_proj4_func, data);
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
static VALUE method_proj4_initialize_copy(VALUE self, VALUE orig)
|
|
109
|
+
{
|
|
110
|
+
// Clear out any existing value
|
|
111
|
+
projPJ pj = RGEO_PROJ4_DATA_PTR(self)->pj;
|
|
112
|
+
if (pj) {
|
|
113
|
+
pj_free(pj);
|
|
114
|
+
RGEO_PROJ4_DATA_PTR(self)->pj = NULL;
|
|
115
|
+
RGEO_PROJ4_DATA_PTR(self)->original_str = Qnil;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Copy value from orig
|
|
119
|
+
RGEO_PROJ4_DATA_PTR(self)->pj = RGEO_PROJ4_DATA_PTR(orig)->pj;
|
|
120
|
+
RGEO_PROJ4_DATA_PTR(self)->original_str = RGEO_PROJ4_DATA_PTR(orig)->original_str;
|
|
121
|
+
|
|
122
|
+
return self;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
static VALUE method_proj4_get_geographic(VALUE self)
|
|
127
|
+
{
|
|
128
|
+
VALUE result = Qnil;
|
|
129
|
+
RGeo_Proj4Data* data = ALLOC(RGeo_Proj4Data);
|
|
130
|
+
if (data) {
|
|
131
|
+
data->pj = pj_latlong_from_proj(RGEO_PROJ4_DATA_PTR(self)->pj);
|
|
132
|
+
data->original_str = Qnil;
|
|
133
|
+
result = Data_Wrap_Struct(CLASS_OF(self), mark_proj4_func, destroy_proj4_func, data);
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
static VALUE method_proj4_original_str(VALUE self)
|
|
140
|
+
{
|
|
141
|
+
return RGEO_PROJ4_DATA_PTR(self)->original_str;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
static VALUE method_proj4_canonical_str(VALUE self)
|
|
146
|
+
{
|
|
147
|
+
VALUE result = Qnil;
|
|
148
|
+
projPJ pj = RGEO_PROJ4_DATA_PTR(self)->pj;
|
|
149
|
+
if (pj) {
|
|
150
|
+
char* str = pj_get_def(pj, 0);
|
|
151
|
+
if (str) {
|
|
152
|
+
result = rb_str_new2(str);
|
|
153
|
+
pj_dalloc(str);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
static VALUE method_proj4_is_geographic(VALUE self)
|
|
161
|
+
{
|
|
162
|
+
VALUE result = Qnil;
|
|
163
|
+
projPJ pj = RGEO_PROJ4_DATA_PTR(self)->pj;
|
|
164
|
+
if (pj) {
|
|
165
|
+
result = pj_is_latlong(pj) ? Qtrue : Qfalse;
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
static VALUE method_proj4_is_geocentric(VALUE self)
|
|
172
|
+
{
|
|
173
|
+
VALUE result = Qnil;
|
|
174
|
+
projPJ pj = RGEO_PROJ4_DATA_PTR(self)->pj;
|
|
175
|
+
if (pj) {
|
|
176
|
+
result = pj_is_geocent(pj) ? Qtrue : Qfalse;
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
static VALUE method_proj4_is_valid(VALUE self)
|
|
183
|
+
{
|
|
184
|
+
return RGEO_PROJ4_DATA_PTR(self)->pj ? Qtrue : Qfalse;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
static VALUE cmethod_proj4_transform(VALUE method, VALUE from, VALUE to, VALUE x, VALUE y, VALUE z)
|
|
189
|
+
{
|
|
190
|
+
VALUE result = Qnil;
|
|
191
|
+
projPJ from_pj = RGEO_PROJ4_DATA_PTR(from)->pj;
|
|
192
|
+
projPJ to_pj = RGEO_PROJ4_DATA_PTR(to)->pj;
|
|
193
|
+
if (from_pj && to_pj) {
|
|
194
|
+
double xval = rb_num2dbl(x);
|
|
195
|
+
double yval = rb_num2dbl(y);
|
|
196
|
+
double zval = 0.0;
|
|
197
|
+
if (!NIL_P(z)) {
|
|
198
|
+
zval = rb_num2dbl(z);
|
|
199
|
+
}
|
|
200
|
+
int err = pj_transform(from_pj, to_pj, 1, 1, &xval, &yval, NIL_P(z) ? NULL : &zval);
|
|
201
|
+
if (!err && xval != HUGE_VAL && yval != HUGE_VAL && (NIL_P(z) || zval != HUGE_VAL)) {
|
|
202
|
+
result = rb_ary_new2(NIL_P(z) ? 2 : 3);
|
|
203
|
+
rb_ary_push(result, rb_float_new(xval));
|
|
204
|
+
rb_ary_push(result, rb_float_new(yval));
|
|
205
|
+
if (!NIL_P(z)) {
|
|
206
|
+
rb_ary_push(result, rb_float_new(zval));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
static VALUE cmethod_proj4_create(VALUE klass, VALUE str)
|
|
215
|
+
{
|
|
216
|
+
VALUE result = Qnil;
|
|
217
|
+
Check_Type(str, T_STRING);
|
|
218
|
+
RGeo_Proj4Data* data = ALLOC(RGeo_Proj4Data);
|
|
219
|
+
if (data) {
|
|
220
|
+
data->pj = pj_init_plus(RSTRING_PTR(str));
|
|
221
|
+
data->original_str = str;
|
|
222
|
+
result = Data_Wrap_Struct(klass, mark_proj4_func, destroy_proj4_func, data);
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
static void rgeo_init_proj4()
|
|
229
|
+
{
|
|
230
|
+
VALUE rgeo_module = rb_define_module("RGeo");
|
|
231
|
+
VALUE coordsys_module = rb_define_module_under(rgeo_module, "CoordSys");
|
|
232
|
+
VALUE proj4_class = rb_define_class_under(coordsys_module, "Proj4", rb_cObject);
|
|
233
|
+
rb_define_module_function(proj4_class, "_create", cmethod_proj4_create, 1);
|
|
234
|
+
rb_define_method(proj4_class, "initialize_copy", method_proj4_initialize_copy, 1);
|
|
235
|
+
rb_define_method(proj4_class, "_original_str", method_proj4_original_str, 0);
|
|
236
|
+
rb_define_method(proj4_class, "_canonical_str", method_proj4_canonical_str, 0);
|
|
237
|
+
rb_define_method(proj4_class, "_valid?", method_proj4_is_valid, 0);
|
|
238
|
+
rb_define_method(proj4_class, "_geographic?", method_proj4_is_geographic, 0);
|
|
239
|
+
rb_define_method(proj4_class, "_geocentric?", method_proj4_is_geocentric, 0);
|
|
240
|
+
rb_define_method(proj4_class, "_get_geographic", method_proj4_get_geographic, 0);
|
|
241
|
+
rb_define_module_function(proj4_class, "_transform_coords", cmethod_proj4_transform, 5);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
#endif
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
void Init_proj4_c_impl()
|
|
249
|
+
{
|
|
250
|
+
#ifdef RGEO_PROJ4_SUPPORTED
|
|
251
|
+
rgeo_init_proj4();
|
|
252
|
+
#endif
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
RGEO_END_C
|
data/lib/rgeo.rb
CHANGED
|
@@ -41,46 +41,44 @@
|
|
|
41
41
|
#
|
|
42
42
|
# RGeo comprises a number of modules.
|
|
43
43
|
#
|
|
44
|
-
# The RGeo::
|
|
44
|
+
# The RGeo::Feature module contains interface specifications for spatial
|
|
45
45
|
# objects implemented by RGeo. These interfaces closely follow the OGC
|
|
46
46
|
# Simple Features Specifiation (SFS). This module forms the core of RGeo.
|
|
47
47
|
#
|
|
48
|
+
# The RGeo::CoordSys module contains classes for representing spatial
|
|
49
|
+
# reference systems and coordinate transformations. For example, it
|
|
50
|
+
# includes a wrapper for the Proj4 library, supporting many geographic
|
|
51
|
+
# projections.
|
|
52
|
+
#
|
|
48
53
|
# The RGeo::Cartesian module provides a basic pure ruby implementation of
|
|
49
54
|
# spatial objects in a Cartesian (flat) coordinate system. It does not
|
|
50
55
|
# implement all the geometric analysis operations in the SFS, but it
|
|
51
56
|
# implements the data structures without requiring an external C library,
|
|
52
57
|
# so it is often sufficient for basic applications.
|
|
53
58
|
#
|
|
54
|
-
# The RGeo::Geos module is another
|
|
55
|
-
# GEOS library to provide a full, high-performance implementation of
|
|
59
|
+
# The RGeo::Geos module is another Cartesian implementation that wraps
|
|
60
|
+
# the GEOS library to provide a full, high-performance implementation of
|
|
56
61
|
# Cartesian geometry that includes every operation defined in the SFS. It
|
|
57
62
|
# requires GEOS 3.2 or later.
|
|
58
63
|
#
|
|
59
64
|
# The RGeo::Geography module contains spatial implementations that
|
|
60
65
|
# operate in latitude-longitude coordinates and are well-suited for
|
|
61
|
-
# geographic location based applications.
|
|
62
|
-
#
|
|
63
|
-
# One of the geography implementations is RGeo::Geography::SimpleMercator,
|
|
64
|
-
# which uses the same coordinate system and projection as that used by
|
|
65
|
-
# Google and Bing Maps, and is ideally suited for visualization
|
|
66
|
-
# applications based on those technologies.
|
|
67
|
-
#
|
|
68
|
-
# The RGeo::Geography::SimpleSpherical provides another geography
|
|
69
|
-
# implementation that does not use a projection, but instead performs
|
|
70
|
-
# geometric operations on a spherical approximation of the globe. This
|
|
71
|
-
# implementation does not provide all the geometric analysis operations
|
|
72
|
-
# in the SFS, but it may be useful for cases when you need more accuracy
|
|
73
|
-
# than a projected implementation would provide.
|
|
66
|
+
# geographic location based applications. Geography implementations may
|
|
67
|
+
# also be linked to projections.
|
|
74
68
|
#
|
|
75
69
|
# The RGeo::WKRep module contains tools for reading and writing spatial
|
|
76
70
|
# data in the OGC Well-Known Text (WKT) and Well-Known Binary (WKB)
|
|
77
|
-
# representations. It also supports
|
|
71
|
+
# representations. It also supports common variants such as the PostGIS
|
|
78
72
|
# EWKT and EWKB representations.
|
|
79
73
|
#
|
|
80
74
|
# The RGeo::GeoJSON module contains tools for GeoJSON serialization of
|
|
81
75
|
# spatial objects. These tools work with any of the spatial object
|
|
82
76
|
# implementations.
|
|
83
77
|
#
|
|
78
|
+
# The RGeo::Shapefile module contains tools for reading ESRI shapefiles,
|
|
79
|
+
# an industry standard (if somewhat legacy) file format commonly used for
|
|
80
|
+
# providing geographic data sets.
|
|
81
|
+
#
|
|
84
82
|
# === Loading the library
|
|
85
83
|
#
|
|
86
84
|
# After installing the RGeo gem, you can load the library with:
|
|
@@ -95,43 +93,57 @@
|
|
|
95
93
|
# require 'rgeo/all'
|
|
96
94
|
#
|
|
97
95
|
# You may also eagerly load individual modules:
|
|
98
|
-
# require 'rgeo/
|
|
96
|
+
# require 'rgeo/feature'
|
|
99
97
|
# require 'rgeo/cartesian'
|
|
100
|
-
# require 'rgeo/
|
|
98
|
+
# require 'rgeo/coord_sys'
|
|
101
99
|
# require 'rgeo/geography'
|
|
102
|
-
# require 'rgeo/
|
|
103
|
-
# require 'rgeo/geography/simple_spherical'
|
|
104
|
-
# require 'rgeo/wkrep'
|
|
100
|
+
# require 'rgeo/geos'
|
|
105
101
|
# require 'rgeo/geo_json'
|
|
102
|
+
# require 'rgeo/shapefile'
|
|
103
|
+
# require 'rgeo/wkrep'
|
|
106
104
|
#
|
|
107
|
-
# ===
|
|
108
|
-
#
|
|
109
|
-
# RGeo
|
|
110
|
-
#
|
|
111
|
-
#
|
|
112
|
-
#
|
|
113
|
-
#
|
|
114
|
-
#
|
|
115
|
-
#
|
|
116
|
-
#
|
|
117
|
-
#
|
|
118
|
-
#
|
|
119
|
-
#
|
|
120
|
-
#
|
|
121
|
-
#
|
|
122
|
-
#
|
|
105
|
+
# === Spatial connection adapters for ActiveRecord
|
|
106
|
+
#
|
|
107
|
+
# RGeo also provides ActiveRecord connection adapters for common spatial
|
|
108
|
+
# databases. You can specify and use these connection adapters in the same
|
|
109
|
+
# way you use any other connection adapter, for example by specifying the
|
|
110
|
+
# adapter name in a Rails application's database.yml file. You do not need
|
|
111
|
+
# to require any files to gain access to these adapters. RGeo makes them
|
|
112
|
+
# available to ActiveRecord automatically.
|
|
113
|
+
#
|
|
114
|
+
# These adapters are:
|
|
115
|
+
#
|
|
116
|
+
# <tt>mysqlspatial</tt>::
|
|
117
|
+
# An adapter based on the standard mysql adapter. It extends the stock
|
|
118
|
+
# adapter to provide support for spatial columns in MySQL, mapping the
|
|
119
|
+
# values properly to RGeo spatial objects. Like the standard mysql
|
|
120
|
+
# adapter, this requires the mysql gem (version 2.8 or later).
|
|
121
|
+
# <tt>mysql2spatial</tt>::
|
|
122
|
+
# An adapter for MySQL spatial based on the mysql2 adapter. It requires
|
|
123
|
+
# the mysql2 gem (version 0.2.6 or later).
|
|
124
|
+
# <tt>spatialite</tt>::
|
|
125
|
+
# An adapter for the SpatiaLite extension to Sqlite3. It is based on
|
|
126
|
+
# the stock sqlite3 adapter, and requires the sqlite3-ruby gem.
|
|
127
|
+
# <b>(INCOMPLETE)</b>
|
|
128
|
+
# <tt>postgis</tt>::
|
|
129
|
+
# An adapter for the PostGIS extension to Postgresql. It is based on
|
|
130
|
+
# the stock postgres adapter, and requires the pg gem.
|
|
131
|
+
# <b>(INCOMPLETE)</b>
|
|
123
132
|
|
|
124
133
|
module RGeo
|
|
125
134
|
|
|
126
135
|
autoload(:Cartesian, 'rgeo/cartesian')
|
|
127
|
-
autoload(:
|
|
128
|
-
autoload(:
|
|
136
|
+
autoload(:CoordSys, 'rgeo/coord_sys')
|
|
137
|
+
autoload(:Error, 'rgeo/error')
|
|
138
|
+
autoload(:Errors, 'rgeo/error')
|
|
139
|
+
autoload(:Feature, 'rgeo/feature')
|
|
140
|
+
autoload(:Features, 'rgeo/feature')
|
|
129
141
|
autoload(:GeoJSON, 'rgeo/geo_json')
|
|
130
142
|
autoload(:Geography, 'rgeo/geography')
|
|
131
143
|
autoload(:Geos, 'rgeo/geos')
|
|
132
|
-
autoload(:
|
|
133
|
-
autoload(:WKRep, 'rgeo/wkrep')
|
|
144
|
+
autoload(:ImplHelper, 'rgeo/impl_helper')
|
|
134
145
|
autoload(:Shapefile, 'rgeo/shapefile')
|
|
146
|
+
autoload(:WKRep, 'rgeo/wkrep')
|
|
135
147
|
|
|
136
148
|
end
|
|
137
149
|
|