Sha256: 2299ab3ad7bc572884959ff88f81438e20c5d0435d28041a236d6c21131abc12

Contents?: true

Size: 1.9 KB

Versions: 8

Compression:

Stored size: 1.9 KB

Contents

$:.unshift(File.dirname(__FILE__))

require 'test/unit'
require 'common/common_postgis'

class Park < ActiveRecord::Base
end

class FindPostgisTest < Test::Unit::TestCase

  def setup
    ActiveRecord::Schema.define() do
      create_table "parks", :force => true do |t|
        t.column "data" , :string, :limit => 100
        t.column "geom", :point,:null=>false,:srid=>123
      end
      add_index "parks","geom",:spatial=>true,:name => "example_spatial_index"
    end
    
    pt = Park.new(:data => "Point1", :geom => Point.from_x_y(1.2,0.75,123))
    assert(pt.save)

    pt = Park.new(:data => "Point2",:geom => Point.from_x_y(0.6,1.3,123))
    assert(pt.save)

    pt = Park.new(:data => "Point3", :geom => Point.from_x_y(2.5,2,123))
    assert(pt.save)
    
  end
   
  def test_find_by_geom_column
    
    pts = Park.find_all_by_geom(LineString.from_coordinates([[0,0],[2,2]],123))
    assert(pts)
    assert(pts.is_a?(Array))
    assert_equal(2,pts.length)
    assert(pts[0].data == "Point1" ||pts[1].data == "Point1" )
    assert(pts[0].data == "Point2" ||pts[1].data == "Point2" )

    pts = Park.find_all_by_geom(LineString.from_coordinates([[2.49,1.99],[2.51,2.01]],123))
    assert(pts)
    assert(pts.is_a?(Array))
    assert_equal(1,pts.length)
    assert(pts[0].data == "Point3")
    
  end

  def test_find_by_geom_column_bbox_condition
    pts = Park.find_all_by_geom([[0,0],[2,2],123])
    assert(pts)
    assert(pts.is_a?(Array))
    assert_equal(2,pts.length)
    assert(pts[0].data == "Point1" ||pts[1].data == "Point1" )
    assert(pts[0].data == "Point2" ||pts[1].data == "Point2" )

    pts = Park.find_all_by_geom([[0,0],[2,2],123])
    assert(pts)
    assert(pts.is_a?(Array))
    assert_equal(2,pts.length)
    assert(pts[0].data == "Point1" ||pts[1].data == "Point1" )
    assert(pts[0].data == "Point2" ||pts[1].data == "Point2" )
  end
  

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
GeoRuby-1.2.0 tools/lib/spatial_adapter/test/find_postgis_test.rb
GeoRuby-1.2.1 tools/lib/spatial_adapter/test/find_postgis_test.rb
GeoRuby-1.2.2 tools/lib/spatial_adapter/test/find_postgis_test.rb
GeoRuby-1.2.3 tools/lib/spatial_adapter/test/find_postgis_test.rb
GeoRuby-1.2.4 tools/lib/spatial_adapter/test/find_postgis_test.rb
GeoRuby-1.3.0 tools/lib/spatial_adapter/test/find_postgis_test.rb
GeoRuby-1.3.1 tools/lib/spatial_adapter/test/find_postgis_test.rb
GeoRuby-1.3.2 tools/lib/spatial_adapter/test/find_postgis_test.rb