Note that there are some explanatory texts on larger screens.

plurals
  1. PORender as GeoJSON (or selectively as WKT/WKB) using MIME-Types
    primarykey
    data
    text
    <p>I have Rails with <code>PostGIS</code>, <code>activerecord-postgis-adapter</code> and <code>rgeo-geojson</code> running.</p> <p>At the moment I can use default "object.json" URLs to get a JSON string with WKT/WKB format. It looks like this:</p> <pre><code>{"description":null,"id":1,"position":"POINT (10.0 47.0)"} </code></pre> <p>But now I want to have a custom MIME-Type, so I can call "object.geojson" to get GeoJSON format like this:</p> <pre><code>{"description":null,"id":1,"position":{"type":"Point","coordinates": [10.0, 47.0]}} </code></pre> <p>The only way I found to set the JSON-encoder to GeoJSON was to set it globally using <code>RGeo::ActiveRecord::GeometryMixin.set_json_generator(:geojson)</code> and <code>RGeo::ActiveRecord::GeometryMixin.set_json_generator(:wkt)</code>. <strong>But I just want to set it locally, is this possible?</strong></p> <p>I already added <code>Mime::Type.register "application/json", :geojson, %w( text/x-json application/jsonrequest )</code> to <code>mime_types.rb</code> and it works fine: I can use this code in my controller:</p> <pre><code>respond_to do |format| format.json { render json: @object } format.geojson { render text: "test" } end </code></pre> <p>I hope someone can tell me how to render some specific object to GeoJSON without setting the global JSON renderer to <code>:geojson</code>. !?</p> <p><strong>EDIT:</strong></p> <p>My objects look like this in Rails Console:</p> <p><code>#&lt;Anchor id: 1, description: nil, position: #&lt;RGeo::Geos::CAPIPointImpl:0x3fc93970aac0 "POINT (10.0 47.0)"&gt;&gt;</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload