EzDevInfo.com

rgeo

Geospatial data library for Ruby

Create point by offset in RGeo

I'm writing a relatively simple app in which I'm using RGeo to calculate distances between points on the globe. I'm doing this using a RGeo::Geographic.spherical_factory.

Now I want to be able to create a new point by adding an offset to an existing point. For example, I would like to be able to find the longitude and latitude of the point 500 metres north and 200 metres east of an existing point.

How should I go about doing this?


Source: (StackOverflow)

Add distance to a particular latitude/longitude position

Rails 4 + Postgres. New to geospatial. Happy to accept solutions that involve RGeo, Geokit, Geocoder, or any other gem that helps solve this issue.

Model contains two fields latitude and longitude.

I have an offset attribute that contains a distance in meters and an orientation attribute that contains one of the 4 cardinal directions (N, E, W, S).

Example: offset: 525.5 orientation: W

What's a standard way of adding the offset distance to the lat-long position, to give me a new lat-long pair as the result of the distance addition?


Source: (StackOverflow)

Advertisements

activerecord-postgis-adapter returns string instead of geometry after saving the record

I'm having an issue when retrieving the value of a geometry column from the database. I save an RGeo::Cartesian::PolygonImpl instance, reload the record, and when I retrieve the value, I get a String instead of a Geometry.

My config/database.yml has:

development: 
  adapter: postgis
  encoding: unicode
  pool: 10
  timeout: 5000
  schema_search_path: public
  database: XXXX
  username: XXXX
  password: XXXX

My table has the following column definition:

CREATE TABLE properties
# ...
parcel geometry(Polygon,3785),
# ...

And my model has the following setup:

class Property < ActiveRecord::Base

  set_rgeo_factory_for_column(:parcel, RGeo::Geographic.simple_mercator_factory(srid: 3785))
  # ...
end

Through Rails console, I am creating a polygon and saving it to the DB (output abridged for brevity):

2.1.5 :052 > f = Property.rgeo_factory_for_column(:parcel)
2.1.5 :053 > points_array = [{"latitude"=>49.130917114292146, "longitude"=>-122.85873269458159}, {"latitude"=>49.131504470050885, "longitude"=>-122.85873269458159}, {"latitude"=>49.131504470050885, "longitude"=>-122.85743450541838}, {"latitude"=>49.130917114292146, "longitude"=>-122.85743450541838}, {"latitude"=>49.130917114292146, "longitude"=>-122.85873269458159}]
2.1.5 :054 > points = points_array.collect {|p| f.point(p['longitude'], p['latitude'])}
2.1.5 :055 > projection = f.polygon(f.linear_ring(points)).projection
2.1.5 :056 > property = Property.find(123)
2.1.5 :057 > property.parcel = projection
 => #<RGeo::Cartesian::PolygonImpl:0xb82223c "POLYGON ((-13676571.563067732 6297104.554633035, -13676571.563067732 6297204.480123126, -13676427.049311131 6297204.480123126, -13676427.049311131 6297104.554633035, -13676571.563067732 6297104.554633035))">
2.1.5 :058 > property.save!
2.1.5 :059 > property.parcel.class
 => RGeo::Cartesian::PolygonImpl

At this point, if I get the value of property.parcel, I correctly get the RGeo::Cartesian::PolygonImpl. However, if I now reload the record, I get a String:

2.1.5 :060 > property.reload
2.1.5 :061 > p.parcel
 => "0103000020C90E000001000000050000009FA6047203166AC18F1B7F23840558419FA6047203166AC15956BA1E9D055841F0F49361F1156AC15956BA1E9D055841F0F49361F1156AC18F1B7F23840558419FA6047203166AC18F1B7F2384055841"
2.1.5 :062 > p.parcel.class
 => String

Now, an interesting thing to notice is that if I use #pluck on an ActiveRecord::Relation, I do get the RGeo polygon:

2.1.5 :069 > props = Property.where('parcel is not null').limit(1)
 => #<ActiveRecord::Relation [#<Property id: 37362, parcel: "0103000020C90E0000010000000700000050550F59F9C35EC0...">]>
2.1.5 :070 > props[0].parcel
 => "0103000020C90E0000010000000700000050550F59F9C35EC0F3C61F98209B4840F2A22041F9C35EC0698E70A32C9B484094FF2041F9C35EC0DA12B4A52C9B484048F5426AFCC35EC03C9ED6B02C9B48405079426AFCC35EC0B7EDD1AD2C9B4840E0E72F82FCC35EC0C0BA55A3209B484050550F59F9C35EC0F3C61F98209B4840"
2.1.5 :071 > props.collect(&:parcel)
 => ["0103000020C90E0000010000000700000050550F59F9C35EC0F3C61F98209B4840F2A22041F9C35EC0698E70A32C9B484094FF2041F9C35EC0DA12B4A52C9B484048F5426AFCC35EC03C9ED6B02C9B48405079426AFCC35EC0B7EDD1AD2C9B4840E0E72F82FCC35EC0C0BA55A3209B484050550F59F9C35EC0F3C61F98209B4840"]
2.1.5 :072 > props.pluck(:parcel)
 => [#<RGeo::Geographic::ProjectedPolygonImpl:0xac42e08 "POLYGON ((-123.06209398744 49.2119321971094, -123.062088281509 49.2122997569648, -123.062088281846 49.2123000268236, -123.062281194104 49.2123013542118, -123.062281193653 49.2123009944002, -123.062286898406 49.2119335335351, -123.06209398744 49.2119321971094))">]

So I believe there is an issue with Rails not knowing to cast the value into a Geometry when accessed via the column accessor, but I'm not entirely sure why this is happening.

My project has the following setup:

  • Ruby 2.1.5
  • Rails 4.1.8
  • activerecord-postgis-adapter 2.2.1
  • rgeo 0.3.20
  • rgeo-activerecord 2.0.0
  • Postgres 9.3.5
  • PostGIS 2.1.4

Source: (StackOverflow)

RGeo: spatial data in fixtures

I've got a model containing a location attribute, represented by a RGeo::Cartesian::Point object, and stored in my database as spatial data.

In order to run tests, I need to create some samples of such a model through fixtures.

I tried several different syntaxes to initialize the location attribute in erb YAML, but none of them worked.

How can I do that?


Source: (StackOverflow)

Ruby on Rails PostGIS - insert a polygon record into DB

I'm using RoR with PostGIS to store locations data. I'm trying to store an estimated location using circle (e.g. center point with radius).

I've tried something like that, but it doesn't work:

@location = Location.new(:place_id => place.id,
                         :circle => %{ST_Buffer(ST_MakePoint(#{latitude}, #{longitude})::geography, #{accuracy})})

I've also tried using RGeo and it's factory but not sure how to use it exactly.

Any help will be appreciated. Thanks.

Edit 1: I made some progress.

factory = RGeo::Cartesian.factory
center_point = factory.point(latitude, longitude)
circle = center_point.buffer(accuracy)

@location = Location.new(:place_id => place.id,
                         :circle => circle)

BUT - now it throws the following exception:

can't cast RGeo::Cartesian::Polygon Impl to string

Again, any help will be appreciated.


Source: (StackOverflow)

How to create RGeo polygon in Ruby from WKT when the polygon has errors

I'm working with a MySQL database with polygons stored in WKT format. Many polygons in the database have duplicate points (e.g. in the below example, the point -122.323502 47.600959 is repeated three times).

When attempting to call RGeo::Cartesian::Factory.parse_wkt() on these polygons, the result is nil.

How can I create RGeo objects from these polygons, without modifying the polygon data.

poly = "MULTIPOLYGON(((-122.362163 47.618641,-122.344621 47.592555,-122.332017 47.592458,-122.32748 47.59241,-122.326109 47.592652,-122.324738 47.592895,-122.323147 47.593478,-122.321412 47.59411,-122.320826 47.594984,-122.320669 47.596296,-122.321149 47.598627,-122.323502 47.600959,-122.323502 47.600959,-122.323502 47.600959,-122.324071 47.601688,-122.320757 47.601688,-122.32073 47.604262,-122.320767 47.607663,-122.320746 47.609703,-122.320723 47.611938,-122.320714 47.612812,-122.320772 47.614075,-122.320799 47.618495,-122.362163 47.618641)))"

parsed_poly = RGeo::Cartesian::Factory.new().parse_wkt(poly)

=>nil

Source: (StackOverflow)

RGeo Projected Buffer Polygon too small

I have a rails app that is using rgeo 0.3.19 with proj4 support connecting to a PostGIS 1.5 database with the rgeo-activerecord 0.4.5 gem.

My app has a model called Region which contains a geographic point, a radius, and a polygon shape. When a new region is about to save it uses the region's geofactory's buffer function to create a polygon using the radius and the geographic point.

Here is the geofactory that is being used for the region model

GEOFACTORY = RGeo::Geographic.projected_factory(:buffer_resolution => 8, :projection_proj4 => '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs', :projection_srid => 3857)

The projection_srid I am using is that of Apple and Google maps mercator projection 3857. The problem is that the buffer that is being created is not the same size as the one I am drawing in either apple maps or google maps. For example, if I use the built in MapKit function MKCircle

[MKCircle circleWithCenterCoordinate:self.coordinate radius:50];

The circle will draw and overlay like this. iOS Drawing Radius

But if I take the coordinates that were created form the buffer function that make up the polygon shape in the database and plot them on google maps I get this.

GoogleMaps Radius

As you can see, the polygon that was created using the same projection system is smaller than it should be. This problem exponentially grows out of control based on the size of the radius defined. I have also tried to use the simple_mercator factory as defined in RGeo which yielded the same results.

Hopefully somebody has some insight into why, when a longitude,latitude projected point is buffered it creates an incorrectly sized polygon.


Source: (StackOverflow)

Use KML to generate geometry

I'm asking if someone has already done the following description. I don't even know if it's possible.

I would like to use a KML file to generate a polygon recorded on my PostgreSQL database (with PostGIS).


Source: (StackOverflow)

natural neighbour interpolation. error in calculating polygon intersection area

I am trying to write this algorithm in R. Does it exist in any package already?!?

This is what I did (with help from SO and various blog posts):

library(rgdal)
library(ggmap)
require("maptools")
require("plyr")

locations<- unique(cbind(data22[,1], data22[,2]))
      [,1]    [,2]
  [1,] 24.9317 60.1657
  [2,] 24.9415 60.1608
  [3,] 24.9331 60.1577
  [4,] 24.9228 60.1477
  [5,] 24.9370 60.1545
  [6,] 24.9491 60.1559
  [7,] 24.9468 60.1591
  [8,] 24.9494 60.1675
  [9,] 24.9561 60.1609
 [10,] 24.9218 60.1632
 [11,] 24.9213 60.1605
 [12,] 24.9219 60.1557
 [13,] 24.9208 60.1704
 [14,] 24.9233 60.1714
 [15,] 24.9469 60.1737
 [16,] 24.9440 60.1738
 [17,] 24.9531 60.1714
 [18,] 24.9601 60.1736
 [19,] 24.9304 60.1687
 [20,] 24.9312 60.1659
 [21,] 24.9313 60.1658
 [22,] 24.9418 60.1608
 [23,] 24.9336 60.1577
 [24,] 24.9213 60.1494
 [25,] 24.9415 60.1538
 [26,] 24.9560 60.1620
 [27,] 24.9610 60.1587
 [28,] 24.9142 60.1635
 [29,] 24.9072 60.1636
 [30,] 24.9132 60.1582
 [31,] 24.9166 60.1668
 [32,] 24.9146 60.1742
 [33,] 24.9259 60.1751
 [34,] 24.9308 60.1742
 [35,] 24.9524 60.1690
 [36,] 24.9601 60.1709
 [37,] 24.9570 60.1742
 [38,] 24.9324 60.1655
 [39,] 24.9426 60.1610
 [40,] 24.9332 60.1581
 [41,] 24.9274 60.1480
 [42,] 24.9393 60.1539
 [43,] 24.9466 60.1550
 [44,] 24.9478 60.1593
 [45,] 24.9431 60.1670
 [46,] 24.9559 60.1615
 [47,] 24.9623 60.1581
 [48,] 24.9144 60.1632
 [49,] 24.9077 60.1634
 [50,] 24.9110 60.1575
 [51,] 24.9212 60.1685
 [52,] 24.9193 60.1739
 [53,] 24.9270 60.1752
 [54,] 24.9305 60.1746
 [55,] 24.9517 60.1700
 [56,] 24.9598 60.1710
 [57,] 24.9565 60.1737
 [58,] 24.9306 60.1686
 [59,] 24.9361 60.1621
 [60,] 24.9415 60.1580
 [61,] 24.9312 60.1561
 [62,] 24.9253 60.1528
 [63,] 24.9501 60.1589
 [64,] 24.9467 60.1591
 [65,] 24.9458 60.1630
 [66,] 24.9374 60.1715
 [67,] 24.9438 60.1707
 [68,] 24.9527 60.1674
 [69,] 24.9556 60.1604
 [70,] 24.9205 60.1698
 [71,] 24.9141 60.1633
 [72,] 24.9082 60.1633
 [73,] 24.9118 60.1569
 [74,] 24.9220 60.1683
 [75,] 24.9231 60.1630
 [76,] 24.9475 60.1735
 [77,] 24.9434 60.1735
 [78,] 24.9535 60.1713
 [79,] 24.9605 60.1739
 [80,] 24.9307 60.1685
 [81,] 24.9373 60.1618
 [82,] 24.9402 60.1582
 [83,] 24.9311 60.1560
 [84,] 24.9257 60.1527
 [85,] 24.9485 60.1589
 [86,] 24.9460 60.1635
 [87,] 24.9374 60.1709
 [88,] 24.9519 60.1673
 [89,] 24.9554 60.1595
 [90,] 24.9228 60.1629
 [91,] 24.9215 60.1602
 [92,] 24.9217 60.1556
 [93,] 24.9212 60.1706
 [94,] 24.9239 60.1715
 [95,] 24.9466 60.1735
 [96,] 24.9436 60.1740
 [97,] 24.9532 60.1715
 [98,] 24.9609 60.1738
 [99,] 24.9354 60.1626
[100,] 24.9351 60.1626
[101,] 24.9374 60.1579
[102,] 24.9300 60.1542
[103,] 24.9263 60.1529
[104,] 24.9522 60.1589
[105,] 24.9435 60.1622
[106,] 24.9369 60.1721
[107,] 24.9580 60.1615
[108,] 24.9620 60.1586
[109,] 24.9545 60.1545

# Carson's Voronoi polygons function
# http://stackoverflow.com/a/9405831/489704
# http://www.carsonfarmer.com/2009/09/voronoi-polygons-with-r/
voronoipolygons <- function(x) {
  require(deldir)
  require(sp)
  if (.hasSlot(x, 'coords')) {
    crds <- x@coords  
  } else crds <- x
  z <- deldir(crds[, 1], crds[, 2])
  w <- tile.list(z)
  polys <- vector(mode='list', length=length(w))
  for (i in seq(along=polys)) {
    pcrds <- cbind(w[[i]]$x, w[[i]]$y)
    pcrds <- rbind(pcrds, pcrds[1, ])
    polys[[i]] <- Polygons(list(Polygon(pcrds)), ID=as.character(i))
  }
  SP <- SpatialPolygons(polys)
  voronoi <- SpatialPolygonsDataFrame(SP, data=data.frame(x=crds[, 1],
    y=crds[,2], row.names=sapply(slot(SP, 'polygons'), 
    function(x) slot(x, 'ID'))))
}


v2 <- voronoipolygons(locations)
a=fortify(v2)

bbox<-c(24.90, 60.14, 
        24.97, 60.18)
predgrid <- expand.grid(lon=seq(from=bbox[1], to=bbox[3], length.out=10), 
                        lat=seq(from=bbox[2], to=bbox[4], length.out=10))

N <- 100
loc <- as.matrix(cbind(predgrid[,1:2]))
proj4string(v2) <- CRS("+proj=longlat +ellps=WGS84 +no_defs+ellps=WGS84 
                       +towgs84=0,0,0 ") 
int<-matrix(nrow=N, ncol=109)
for (i in 1:N){
  loc.temp<-rbind(locations, loc[i,])
  vor.temp<-voronoipolygons(loc.temp)
  proj4string(vor.temp) <- CRS("+proj=longlat +ellps=WGS84 +no_defs+ellps=WGS84 
                               +towgs84=0,0,0 ") 
  for (j in 1:109){
    s<-gIntersection(SpatialPolygons(vor.temp@polygons[110]), 
                     SpatialPolygons(vor.temp@polygons[i]))
    if(is.null(s)) {
      int[i,j]=0
    } else {
      # my.area <- vor.temp@polygons[[i]]@Polygons[[1]]@area 
      int[i,j] <- 
        gArea(gIntersection(SpatialPolygons(vor.temp@polygons[i]), 
                            SpatialPolygons(vor.temp@polygons[overlaid.poly])))
    }
  }
}



max(int)

So basically I draw the voronoi tassellation adding one point at a time and try to calculate the intersection between polygons, problem is: max(int) gives 0, as if there was no interpolation, why is this so? is the area calculated with gIntersection correct? they are super small value and I have no idea of the measure unity.

EDIT: Tassellation before new locationhere and the one after it here. I am not sure about the areas given back by the tassellation, that is where I would think the error is, I am not sure though.


Source: (StackOverflow)

RGeo: proj4 not supported error?

I am new to working with geospatial datam and am working with the Rails RGeo gem. I am getting the following error in my rails console:

> geo_shape = ES_Zone::FACTORY.parse_wkt
RGeo::Error::UnsupportedOperation: Proj4 is not supported because the proj4 library was not found at install time.

When I test to see if proj4 is supported, it predictably comes back as false.

> RGeo::CoordSys::Proj4.supported?
=> false 

I googled the error message, but I cannot find any resources for this particular problem. Any ideas?


Source: (StackOverflow)

Rails Mongoid geo_near sort by distance

What I'm trying to do is to sort mongoid geo_near(or within_circle) max_distance results by distance because I don't know why but it doesn't do that by default.

I have mongoid_geospatial, mongoid_spacial and rgeo in my Rails gem file. I know mongoid_spacial has this ability but I could not use it and it caused problems with gmaps4rails.

I'm trying on mongoid_geospatial(which uses mongoid libraries) with no success and I could not find any resource except this one MongoDB Aggregate geoNear maxdistance but I don't know how to convert mongo that to mongoid.

Any one had an experience on sorting geo_near or within_circle in mongoid? Any help will be greatly appreciated.

The code in my Controller

      searchterm = session[:categoryid].to_s
      radius = session[:distance].to_f / 10       
      @places = Provider.all.where(:category.to_s => /.*#{searchterm}.*/)
      .geo_near([ session[:latitude].to_f,session[:longitude].to_f ]).max_distance(radius)    

      #@places = Provider.all.where(:category.to_s => /.*#{searchterm}.*/)
      #.within_circle(location: [[ session[:latitude].to_f,session[:longitude].to_f ], radius ])      
      #.sort(:servicescore.desc).sort(:pricescore.desc)

The code in my model

include Mongoid::Document 
  include Mongoid::Timestamps
  include Mongoid::Paranoia
  include Mongoid::Geospatial
  include Mongoid::MultiParameterAttributes
  include Mongoid::Slug
  include Mongoid::Spacial::Document  
  include Gmaps4rails::ActsAsGmappable
  acts_as_gmappable :lat => 'latitude', :lon => 'longitude', :process_geocoding => true,
                    :check_process => :prevent_geocoding,
                    :address => "business_address"
  field :location, :type => Point
  spatial_index :location
  field :officialname
  field :business_description
  field :category#, :type => Array
  field :business_type
  field :tax_office
  field :tax_number
  field :pin  
  field :business_phone
  field :web_site
  field :business_address   
  field :latitude
  field :longitude

-------------------------------------------------------------------------------

-------------------------------------------------------------------------------

EDIT ON QUESTION

map

I've tried almost anything related without success. Read mongo and mongoid geo_near documentation. It does comment on storing location [lon, lat] order. I've tried both [lon, lat] and [lat, long] both when saving the provider and for the center location. Tried spherical geo_near and within_circle too. Still without success. Geo_near returns my results incorrectly ordered as seen on the map above and on the list below. There should be something I'm missing but can't find it.

The red parts are the "geo_near_distance" output results, the list is sorted according to those but they are wrong as seen on the map. The green calculation is jquery code I've been using that returns correct distances(though cannot use in controller).

There should be something I'm missing. Can anyone spot that?

results

here is my latest code:

Provider.rb

  field :location, :type => Array  # [lat,lng]
  index({ location: "2d" }, { min: -180, max: 180 })
  spatial_index :location  

Providers_controller

  center = [session[:longitude].to_f, session[:latitude].to_f]
  radious = 100
  searchterm = session[:categoryid].to_s
  radius = session[:distance].to_f / 10     
  @places = Provider.all.where(:category.to_s => /.*#{searchterm}.*/)
  .geo_near(center).max_distance(radious)#.spherical
  #.near(location: center)
  #.within_circle( location: [center,radius] )
  #.sort(:geo_near_distance.desc)
  #.geo_near([ session[:latitude].to_f,session[:longitude].to_f ]).max_distance(100).spherical   
  #.unit("km")
  #.geo_near([ session[:latitude].to_f,session[:longitude].to_f ], max_distance: radius, unit: "km".to_sym, spherical: true).sort_by!{|r| r.geo[:distance] }
  #.geo_near([ session[:latitude].to_f,session[:longitude].to_f ]).max_distance(radius)   
  #.sort(:geo_near_distance)

JQuery for the green part

 var p1 = new LatLon(Geo.parseDMS($('#lat1_{{id}}').val()), Geo.parseDMS($('#lon1_{{id}}').val()));
    var p2 = new LatLon(Geo.parseDMS($('#lat2_{{id}}').val()), Geo.parseDMS($('#lon2_{{id}}').val()));
    var new_number = parseFloat(p1.distanceTo(p2)).toFixed(2);
    $('#result-distance_{{id}}').html(new_number+' km');

Data for Provider

{ "_id" : ObjectId("5295ef0fdd5063ce1600002a"), "workdonecount" : 0, "pricescore" : 0, "servicescore" : 0, "_slugs" : [  "5295ef0fdd5063ce1600002a-1" ], "officialname" : "çeşme", "business_description" : "dsadsa", "category" : "5280ad334b315241af406c79", "business_type" : "Ticari", "tax_office" : "dads", "tax_number" : "dss", "pin" : "", "business_address" : "Balçova/İzmir, Türkiye", "latitude" : 38.3692939, "longitude" : 27.093442, "pink" : false, "hizmetkutusu_verified" : false, "user_id" : ObjectId("52946f54dd50636df6000002"), "location" : [  27.093441999999982,  38.3692939 ], "gmaps" : true, "updated_at" : ISODate("2013-11-27T13:09:36.214Z"), "created_at" : ISODate("2013-11-27T13:09:36.214Z") }
{ "_id" : ObjectId("5295f248dd5063ce16000030"), "workdonecount" : 0, "pricescore" : 0, "servicescore" : 0, "_slugs" : [  "5295f248dd5063ce16000030-1" ], "officialname" : "izmirdsads", "business_description" : "dsdsadsdsa", "category" : "5280ad334b315241af406c79", "business_type" : "Ticari", "tax_office" : "dasds", "tax_number" : "dadsa", "pin" : "", "business_address" : "Çeşme, Türkiye", "latitude" : 38.32980999999999, "longitude" : 26.3149209, "pink" : false, "hizmetkutusu_verified" : false, "user_id" : ObjectId("52946f54dd50636df6000002"), "location" : [  26.31492090000006,  38.32980999999999 ], "gmaps" : true, "updated_at" : ISODate("2013-11-27T13:23:20.423Z"), "created_at" : ISODate("2013-11-27T13:23:20.423Z") }
{ "_id" : ObjectId("5295f260dd5063ce16000032"), "workdonecount" : 0, "pricescore" : 0, "servicescore" : 0, "_slugs" : [  "5295f260dd5063ce16000032-1" ], "officialname" : "dsadsa", "business_description" : "dsadsa", "category" : "5280ad334b315241af406c79", "business_type" : "Ticari", "tax_office" : "dsadsa", "tax_number" : "dsads", "pin" : "", "business_address" : "Çiğli, 35580 İzmir, Türkiye", "latitude" : 38.496303, "longitude" : 27.0603911, "pink" : false, "hizmetkutusu_verified" : false, "user_id" : ObjectId("52946f54dd50636df6000002"), "location" : [  27.06039110000006,  38.496303 ], "gmaps" : true, "provider_image" : "gmaps1.jpg", "updated_at" : ISODate("2013-11-27T13:23:44.686Z"), "created_at" : ISODate("2013-11-27T13:23:44.686Z") }
{ "_id" : ObjectId("5295eee3dd5063ce16000026"), "workdonecount" : 0, "pricescore" : 0, "servicescore" : 0, "_slugs" : [  "5295eee3dd5063ce16000026-1" ], "officialname" : "dsdsa", "business_description" : "dadsa", "category" : "5280ad334b315241af406c79", "business_type" : "Ticari", "tax_office" : "dsa", "tax_number" : "dads", "pin" : "", "business_address" : "Buca, İzmir, Türkiye", "latitude" : 38.38813400000001, "longitude" : 27.1753358, "pink" : false, "hizmetkutusu_verified" : false, "user_id" : ObjectId("52946f54dd50636df6000002"), "location" : [  27.291124800000034,  38.3337361 ], "gmaps" : true, "updated_at" : ISODate("2013-11-27T13:08:51.544Z"), "created_at" : ISODate("2013-11-27T13:08:51.544Z") }
{ "_id" : ObjectId("5295eef5dd5063ce16000028"), "workdonecount" : 0, "pricescore" : 0, "servicescore" : 0, "_slugs" : [  "5295eef5dd5063ce16000028-1" ], "officialname" : "dsdsdsa", "business_description" : "dadsds", "category" : "5280ad334b315241af406c79", "business_type" : "Ticari", "tax_office" : "dasds", "tax_number" : "dadsa", "pin" : "", "business_address" : "Bornova, 35100 İzmir, Türkiye", "latitude" : 38.466414, "longitude" : 27.2192191, "pink" : false, "hizmetkutusu_verified" : false, "user_id" : ObjectId("52946f54dd50636df6000002"), "location" : [  27.219219100000032,  38.466414 ], "gmaps" : true, "updated_at" : ISODate("2013-11-27T13:09:10.122Z"), "created_at" : ISODate("2013-11-27T13:09:10.122Z") }

Source: (StackOverflow)

POINT returning nil with activerecord-postgis-adapter on Heroku

I'm using activerecord-postgis-adapter to save (latitude, longitude) values as POINTs. Points are saved using the following syntax: POINT( lat lng). My model, Foo, has an attribute spot, where the POINT is saved. When deployed to Heroku, spot is always nil after creating a new Foo. However, it works as expected in the following situations:

  • Locally with development database (both in production and development environments)
  • Locally while connected to production database
  • In the rails console inside Heroku

activerecord-postgis-adapter is the same version both locally and on Heroku (2.2.0). Does anyone have any ideas as to what could be different in the Heroku production environment (that doesn't surface in the console) that might be causing this?


Source: (StackOverflow)

Installing GEOS on heroku cedar

we have troubles in installing the GEOS library on heroku cedar stack.

We followed this guide: https://devcenter.spacialdb.com/Heroku.html and it didn't work.

We noticed that the path (/app/tmp/geos) stored in the provided geos binaries was wrong, so we built our own binaries with vulcan.

We changed parameters (BUNDLE_BUILD__RGEO) accordingly, but we weren't able to make it work.

We even hardcoded geos paths in our custom rgeo gem without any success

We also tried other buildscripts (https://github.com/roximity/heroku-buildpack-ruby-geos) but they are too old and it will be difficult to keep them up to date with heroku's one

We are using ruby 2.0.0-p195 and Rails 3.2.13


Source: (StackOverflow)

RGeo on Ruby under Windows: How to enable GEOS support?

I'm trying to do some spatial operations in Ruby with the RGeo gem. Unfortunately, a lot of operations require the GEOS library and I can't find any documentation showing how to integrate this in Windows (I am using Windows 7 64bit).

I tried downloading and installing the Windows binaries of GEOS from http://trac.osgeo.org/osgeo4w/ and reinstalling the RGeo gem via gem install rgeo -- --with-geos-dir="C:\OSGeo4W64\bin (<< in this directory there is a file geos_c.dll).

Still, using RGeo::Geos.supported? returns false.

Does anybody know how to solve this?


Source: (StackOverflow)

lat/long Coordinate insertion with form_for in Rails

I'm using Rails 4.4.1, Ruby 2.1.2, RGeo 0.3.20 and activerecord-mysql2spatial-adapter 0.4.3

My problem is probably very simple since I'm new to both Ruby and Rails, but I could not find anything useful in the web so far.

I want to create a form to insert geo-spatial coordinates in my db, but I don't know how to access the :latlon fields x and y. This is my tentative code:

<h1>Inserimento nuova Città</h1>
<%= form_for @city, url: cities_path do |city| %>
    <p>
        <%= city.label :name, "Nome"%><br>
        <%= city.text_field :name %>
    </p>

    <p>
        <%= city.label :latlon, "Coordinate GPS" %><br>
        <%= city.number_field :latlon.x %><br>
        <%= city.number_field :latlon.y %><br>
    </p>
<% end %>

The error I get when I access the localhost:3000/cities/new url is

undefined method `x' for :latlon:Symbol

Anyone knows how do I create a form to insert the latlon.x and latlon.y data in my db?


Source: (StackOverflow)