I have a Postgres database with PostGIS extension and some geo-data in it. I need to generate tiles with custom SQL queries (using ST_... functions), that returns binary data (bytea, like \x1a320a0474657374121d12020000180322150946ec3f1a14453b0a09280f091413121e09091e0f1a026331220228012880207802). And I need to send this data from my Rails controller to the requester, with the headers like 'Content-Type: x-application/protobuf'.
So, my question is:
1) How to get the binary data from the Database (Sequel, ActiveRecord::Base.connection.execute ?)
2) How to return this data in the controller action? (send_data ..., tyle: '' ?)
Thanks!
ActiveRecord::Base.connection.executereturnsPG::Resultobject, and I don't sure that i can get raw binary data from it.SELECT ST_AsMVT(q, 'table', 512, 'geom') AS mvt FROM ( WITH a AS ( SELECT ST_AsMVTGeom( ST_Transform(public.table.wkb_geometry, 3857), TileBBox(13, 2411, 3078, 3857), 512, 256, true ) geom , columns FROM public.table WHERE ST_Intersects(TileBBox(13, 2411, 3078, 4326), public.table.wkb_geometry) ) SELECT * FROM a WHERE geom IS NOT NULL ) AS q, 2) yes, in form of Postgres (see example in my answer). How can I get raw data from PG::Result?