Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rgeo generates wrong wkb for mysql5.7 #150

Closed
dcherniv opened this issue Aug 30, 2016 · 2 comments
Closed

Rgeo generates wrong wkb for mysql5.7 #150

dcherniv opened this issue Aug 30, 2016 · 2 comments

Comments

@dcherniv
Copy link

dcherniv commented Aug 30, 2016

bundle show rgeo
/usr/lib/ruby/gems/1.9.1/bundler/gems/rgeo-8eb105a96a7d

Generating wkb as follows:
RGEO_FACTORY` = RGeo::Geos.factory(:srid => 4326)
RGEO_PARSER = RGeo::WKRep::WKTParser.new(RGEO_FACTORY, :support_ewkt => true)
RGEO_PARSER.parse("MULTIPOLYGON(((-104.994621 39.768791, -104.998222 39.767410, -105.000198 39.766449, -105.001610 39.765301, -105.002510 39.764080, -105.002861 39.763519, -105.003540 39.762959, -105.004227 39.762260, -105.005951 39.760681, -105.006554 39.760220, -105.007919 39.759331, -105.015427 39.753750, -105.016983 39.751942, -105.017960 39.749592, -105.018822 39.747349, -105.018867 39.746861, -105.018867 39.746429, -105.018784 39.746136, -105.017799 39.744617, -105.015953 39.742638, -105.015091 39.741909, -105.014580 39.740852, -105.014359 39.740028, -105.014404 39.738708, -105.014664 39.737225, -105.014709 39.736862, -105.013802 39.736820, -105.007187 39.736721, -104.994789 39.736691, -104.989471 39.736721, -104.977409 39.736660, -104.977364 39.747120, -104.983932 39.752102, -104.993927 39.759850, -104.994400 39.760651, -104.994621 39.763882, -104.994621 39.768791)))")

Resulting WKB and error:
ActiveRecord::StatementInvalid:Mysql2::Error: Invalid GIS data provided to function st_geometryfromwkb.: INSERT INTO TABLEHERE VALUES (2, 'downtown denver', GeomFromWKB(0x00000000060000000100000000030000000100000025c05a3fa7ded6ba8c4043e267be553ac5c05a3fe2de8709744043e23a7daa4fcac05a40033e78e1934043e21b003686a5c05a401a60d4562e4043e1f562174c4dc05a40291fb3fa6e4043e1cd5f99c38bc05a402edfe75bc44043e1bafd976ff4c05a4039ffd60e954043e1a8a3f8982dc05a40454152b0a74043e191bc558644c05a4061804d98394043e15dfeb8d823c05a406b6177ea1c4043e14ee392e1efc05a4081beb181174043e131c219eb64c05a40fcc1871e6d4043e07ae147ae14c05a41163fdd65a14043e03fa2ad3e92c05a412641b328b74043dff2a172abefc05a413461309c804043dfa921ccd962c05a41351deefe504043df992428d435c05a41351deefe504043df8afc47e49bc05a4133c1ce6c094043df81626b2f23c05a41239e6ab9b24043df4f9c1f85d7c05a41055fbb517a4043df0ec3116228c05a40f7403dddb14043def6dfc5cdd5c05a40eee0f3cb3e4043ded43d03968dc05a40eb4202d9cf4043deb93ccd0fe9c05a40ebfec13b9f4043de8dfbd6a594c05a40f041461b6d4043de5d63886595c05a40f0fe047d3d4043de517e77d524c05a40e221c8a7a44043de501e2584f5c05a4075c0767d354043de4cdfaca362c05a3faa9f7b5aea4043de4be40420f7c05a3f537e2c55c94043de4cdfaca362c05a3e8dde7a743a4043de4adff822bcc05a3e8d21bc126a4043dfa1a0cf1801c05a3ef8bdec5f394043e044e0daa0cbc05a3f9c7ffde7214043e142c3c9eeccc05a3fa43fe5c91d4043e15d031055b9c05a3fa7ded6ba8c4043e1c6e2a80065c05a3fa7ded6ba8c4043e267be553ac5,4326), NULL, 49)

Proper WKB generated by mysql 5.7:
select hex(st_asWKB(Geomfromtext('MULTIPOLYGON(((-104.994621 39.768791, -104.998222 39.767410, -105.000198 39.766449, -105.001610 39.765301, -105.002510 39.764080, -105.002861 39.763519, -105.003540 39.762959,-105.004227 39.762260, -105.005951 39.760681, -105.006554 39.760220, -105.007919 39.759331, -105.015427 39.753750, -105.016983 39.751942, -105.017960 39.749592, -105.018822 39.747349, -105.018867 39.746861, -105.018867 39.746429, -105.018784 39.746136, -105.017799 39.744617, -105.015953 39.742638, -105.015091 39.741909, -105.014580 39.740852, -105.014359 39.740028, -105.014404 39.738708, -105.014664 39.737225, -105.014709 39.736862, -105.013802 39.736820, -105.007187 39.736721, -104.994789 39.736691, -104.989471 39.736721, -104.977409 39.736660, -104.977364 39.747120, -104.983932 39.752102, -104.993927 39.759850, -104.994400 39.760651, -104.994621 39.763882, -104.994621 39.768791)))')))

RESULT:
010600000001000000010300000001000000250000008CBAD6DEA73F5AC0C53A55BE67E24340740987DEE23F5AC0CA4FAA7D3AE2434093E1783E03405AC0A58636001BE243402E56D4601A405AC04D4C1762F5E143406EFAB31F29405AC08BC3995FCDE14340C45BE7DF2E405AC0F46F97FDBAE14340950ED6FF39405AC02D98F8A3A8E14340A7B0524145405AC0448655BC91E1434039984D8061405AC023D8B8FE5DE143401CEA77616B405AC0EFE192E34EE143401781B1BE81405AC064EB19C231E143406D1E87C1FC405AC014AE47E17AE04340A165DD3F16415AC0923EADA23FE04340B728B34126415AC0EFAB72A1F2DF4340809C306134415AC062D9CC21A9DF434050FEEE1D35415AC035D4282499DF434050FEEE1D35415AC09BE447FC8ADF4340096CCEC133415AC0232F6B6281DF4340B2B96A9E23415AC0D7851F9C4FDF43407A51BB5F05415AC0286211C30EDF4340B1DD3D40F7405AC0D5CDC5DFF6DE43403ECBF3E0EE405AC08D96033DD4DE4340CFD90242EB405AC0E90FCD3CB9DE43409F3BC1FEEB405AC094A5D6FB8DDE43406D1B4641F0405AC0956588635DDE43403D7D04FEF0405AC024D5777E51DE4340A4A7C821E2405AC0F584251E50DE4340357D76C075405AC062A3ACDF4CDE4340EA5A7B9FAA3F5AC0F72004E44BDE4340C9552C7E533F5AC062A3ACDF4CDE43403A747ADE8D3E5AC0BC22F8DF4ADE43406A12BC218D3E5AC00118CFA0A1DF4340395FECBDF83E5AC0CBA0DAE044E0434021E7FD7F9C3F5AC0CCEEC9C342E143401DC9E53FA43F5AC0B95510035DE143408CBAD6DEA73F5AC06500A8E2C6E143408CBAD6DEA73F5AC0C53A55BE67E24340

@jeffgran
Copy link

This is because of the byte order. MySQL only supports little-endian byte order (which is actually a MySQL bug because the WKB spec allows either -- in fact both of the examples you posted are correctly formatted WKB but MySQL only understands the little-endian one).

I fixed this issue in this pull request: rgeo/activerecord-mysql2spatial-adapter#20

In the meantime (doesn't seem to be getting any attention), you can use my fork and it works:

gem 'activerecord-mysql2spatial-adapter', git: 'https://github.com/trelora/activerecord-mysql2spatial-adapter.git'

@teeparham
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants