class Stop < ActiveRecord::Baseset_rgeo_factory_for_column(:point,RGeo::Geographic.spherical_factory(:srid => 4326))geocoded_by :adressafter_validation :geocodeend
class CreateStops < ActiveRecord::Migrationdef changecreate_table :stops do |t|t.string :adresst.string :shortNamet.float :latitudet.float :longitudet.point :point , :geographic => truet.timestampsendendend
# Create RGEO factory using the mercator coordinate systemGEOFACTORY = RGeo::Geographic.simple_mercator_factoryset_rgeo_factory_for_column(:coords, GEOFACTORY.projection_factory)# geocode by address created belowgeocoded_by :address do |obj,results|if geo = results.first# Take lat and long from geocoder and use them for point coords# Allows you to use geocoders functionality with postgisobj.coords = "POINT(#{geo.longitude} #{geo.latitude})"endend
# instantiates empty arrayarr = []# creates factory# iterates projects returned in @project variable@projects.each do | project |factory = RGeo::GeoJSON::EntityFactory.instance# sets feature variable to feature properties returned from factoryfeature = factory.feature(project.coords,project.id, { title: project.title,desc: project.description,address: project.address})# adds returned contents to empty array instantiated line 7arr.push(feature)end# sets new feature collection with array containing feature propertiesfeature_collection = RGeo::GeoJSON::FeatureCollection.new(arr)respond_to do |format|format.html { render action: 'index' }# render geojsonformat.geojson { render json: (RGeo::GeoJSON.encode(feature_collection)) }endend
--
You received this message because you are subscribed to the Google Groups "RGeo-Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rgeo-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.