armg 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6357d13d722e80d5014732474b708d62318d3b4e
4
- data.tar.gz: 5e64ccc1ddd43b489f690f9bdb0c693c87d6c8f5
3
+ metadata.gz: 96bf61ee4daaa6960675b6f6101419636ecc4a7f
4
+ data.tar.gz: 6e2c5da9a1c844b0ac43ab44ab3d7b460f904adc
5
5
  SHA512:
6
- metadata.gz: 4ed2047d3fa13d2cc42d51a2d21e348472655948dc26de93588fd1be453e53864634a995adc18e8a7ccd0463b0d29c2feaa0cd2b9a457b5aceaa6dd5782b9b9b
7
- data.tar.gz: ee25f6bd443c089cfff31ea63d11ac2cb8bfefaba890ce7ec1da9d55c60f88b8ea0c294feee70a6ba21538800c31045f72f6625b7329429e6502f0f8cf46a6b6
6
+ metadata.gz: 2900aa7568ee144478e6ae4c4da3323693b6bb9a764676ed1a5f32580b8908ae12cb81e642cb695e2d9360a8698266b38b569671a56b6f82e4a86f5c26388270
7
+ data.tar.gz: 268ea2385fd6e0c6ccfa634c64889812c9d708a402eac724ea26dacfffecd02e7b9d6b5d6b97e704fa0a8b670eae98ae9b2f17c4718fe5d789242d990897f354
data/README.md CHANGED
@@ -77,7 +77,7 @@ Geom.take
77
77
  #=> #<Geom id: 1, location: #<RGeo::Geographic::SphericalPointImpl:0x... "POINT (-122.1 47.3)">>
78
78
  ```
79
79
 
80
- ## Using custom WKB serializer
80
+ ## Using custom serializer
81
81
 
82
82
  ```ruby
83
83
  class CustomSerializer
@@ -112,3 +112,8 @@ bundle exec appraisal ar51 rake
112
112
  # ARMG_TEST_MYSQL_PORT=10057 bundle exec appraisal ar51 rake # MySQL 5.7
113
113
  # ARMG_TEST_MYSQL_PORT=10057 ARMG_TEST_MYSQL_ENGINE=InnoDB bundle exec appraisal ar51 rake
114
114
  ```
115
+
116
+ ## Related links
117
+
118
+ * [rgeo/rgeo: Geospatial data library for Ruby](https://github.com/rgeo/rgeo)
119
+ * [MySQL :: MySQL 5.7 Reference Manual :: 11.5.3 Supported Spatial Data Formats](https://dev.mysql.com/doc/refman/5.7/en/gis-data-formats.html)
@@ -4,6 +4,7 @@ require 'armg/version'
4
4
 
5
5
  ActiveSupport.on_load(:active_record) do
6
6
  require 'active_record/connection_adapters/abstract_mysql_adapter'
7
+ require 'armg/utils'
7
8
  require 'armg/wkb_serializer'
8
9
  require 'armg/wkb_deserializer'
9
10
  require 'armg/wkt_serializer'
@@ -13,7 +14,7 @@ ActiveSupport.on_load(:active_record) do
13
14
  require 'armg/table_definition_ext'
14
15
  require 'armg/armg'
15
16
 
16
- ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::NATIVE_DATABASE_TYPES[:geometry] = { name: "geometry" }
17
+ ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::NATIVE_DATABASE_TYPES[:geometry] = { name: 'geometry' }
17
18
  ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend(Armg::AbstractMysqlAdapterExt)
18
19
  ActiveRecord::Type.register(:geometry, Armg::MysqlGeometry, adapter: :mysql2)
19
20
  ActiveRecord::ConnectionAdapters::MySQL::TableDefinition.prepend(Armg::TableDefinitionExt)
@@ -0,0 +1,15 @@
1
+ # see https://dev.mysql.com/doc/refman/5.7/en/gis-data-formats.html
2
+ module Armg::Utils
3
+ def mysql_geometry_to_wkb(wkb)
4
+ wkb = wkb.b
5
+ srid = wkb.slice!(0..3)
6
+ wkb[4] = "\x20"
7
+ wkb.insert(5, srid)
8
+ end
9
+ module_function :mysql_geometry_to_wkb
10
+
11
+ def pack_srid(srid)
12
+ [srid].pack('L<')
13
+ end
14
+ module_function :pack_srid
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Armg
2
- VERSION = '0.5.2'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -3,16 +3,13 @@ class Armg::WkbDeserializer
3
3
  support_ewkb: true,
4
4
  }
5
5
 
6
- def initialize(factory = nil, options = {})
6
+ def initialize(factory: nil, **options)
7
7
  options = DEFAULT_OPTIONS.merge(options)
8
8
  @wkb_parser = RGeo::WKRep::WKBParser.new(factory, options)
9
9
  end
10
10
 
11
- def deserialize(wkb)
12
- wkb = wkb.b
13
- srid = wkb.slice!(0..3)
14
- wkb[4] = "\x20"
15
- wkb.insert(5, srid)
11
+ def deserialize(mysql_geometry)
12
+ wkb = Armg::Utils.mysql_geometry_to_wkb(mysql_geometry)
16
13
  @wkb_parser.parse(wkb)
17
14
  end
18
15
  end
@@ -4,13 +4,13 @@ class Armg::WkbSerializer
4
4
  little_endian: true,
5
5
  }
6
6
 
7
- def initialize(options = {})
7
+ def initialize(**options)
8
8
  options = DEFAULT_OPTIONS.merge(options)
9
9
  @wkb_generator = RGeo::WKRep::WKBGenerator.new(options)
10
10
  end
11
11
 
12
12
  def serialize(obj)
13
- srid = [obj.srid].pack('L<')
13
+ srid = Armg::Utils.pack_srid(obj.srid)
14
14
  srid + @wkb_generator.generate(obj)
15
15
  end
16
16
  end
@@ -1,17 +1,23 @@
1
- class Armg::WktDeserializer < Armg::WkbDeserializer
2
- DEFAULT_OPTIONS = {
1
+ class Armg::WktDeserializer
2
+ DEFAULT_WKB_PARSER_OPTIONS = {
3
+ support_ewkb: true,
4
+ }
5
+
6
+ DEFAULT_WKT_GENERATOR_OPTIONS = {
3
7
  tag_format: :ewkt,
4
8
  #emit_ewkt_srid: true,
5
9
  }
6
10
 
7
- def initialize(factory = nil, options = {})
8
- super(factory, options)
9
- options = DEFAULT_OPTIONS.merge(options)
10
- @generator = RGeo::WKRep::WKTGenerator.new(options)
11
+ def initialize(factory: nil, wkb_parser_options: {}, wkt_generator_options: {})
12
+ @wkb_parser = RGeo::WKRep::WKBParser.new(factory,
13
+ DEFAULT_WKB_PARSER_OPTIONS.merge(wkb_parser_options))
14
+ @wkt_generator = RGeo::WKRep::WKTGenerator.new(
15
+ DEFAULT_WKT_GENERATOR_OPTIONS.merge(wkt_generator_options))
11
16
  end
12
17
 
13
- def deserialize(wkb)
14
- obj = super(wkb)
15
- @generator.generate(obj)
18
+ def deserialize(mysql_geometry)
19
+ wkb = Armg::Utils.mysql_geometry_to_wkb(mysql_geometry)
20
+ obj = @wkb_parser.parse(wkb)
21
+ @wkt_generator.generate(obj)
16
22
  end
17
23
  end
@@ -1,16 +1,23 @@
1
- class Armg::WktSerializer < Armg::WkbSerializer
2
- DEFAULT_OPTIONS = {
1
+ class Armg::WktSerializer
2
+ DEFAULT_WKB_GENERATOR_OPTIONS = {
3
+ type_format: :ewkb,
4
+ little_endian: true,
5
+ }
6
+
7
+ DEFAULT_WKT_PARSER_OPTIONS = {
3
8
  support_ewkt: true
4
9
  }
5
10
 
6
- def initialize(factory = nil, options = {})
7
- super(options)
8
- options = DEFAULT_OPTIONS.merge(options)
9
- @wkt_parser = RGeo::WKRep::WKTParser.new(factory, options)
11
+ def initialize(factory: nil, wkb_generator_options: {}, wkt_parser_options: {})
12
+ @wkb_generator = RGeo::WKRep::WKBGenerator.new(
13
+ DEFAULT_WKB_GENERATOR_OPTIONS.merge(wkb_generator_options))
14
+ @wkt_parser = RGeo::WKRep::WKTParser.new(factory,
15
+ DEFAULT_WKT_PARSER_OPTIONS.merge(wkt_parser_options))
10
16
  end
11
17
 
12
18
  def serialize(wkt)
13
19
  obj = @wkt_parser.parse(wkt)
14
- super(obj)
20
+ srid = Armg::Utils.pack_srid(obj.srid)
21
+ srid + @wkb_generator.generate(obj)
15
22
  end
16
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: armg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
@@ -148,6 +148,7 @@ files:
148
148
  - lib/armg/armg.rb
149
149
  - lib/armg/mysql_geometry.rb
150
150
  - lib/armg/table_definition_ext.rb
151
+ - lib/armg/utils.rb
151
152
  - lib/armg/version.rb
152
153
  - lib/armg/wkb_deserializer.rb
153
154
  - lib/armg/wkb_serializer.rb