nofxx-postgis_adapter 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,7 +19,7 @@ include GeoRuby::SimpleFeatures
19
19
  include SpatialAdapter
20
20
 
21
21
  module PostgisAdapter
22
- VERSION = '0.3.3'
22
+ VERSION = '0.3.4'
23
23
  end
24
24
 
25
25
  #tables to ignore in migration : relative to PostGIS management of geometric columns
@@ -386,10 +386,6 @@ module ActiveRecord
386
386
  new(name,default,"geometry",null,nil,nil,nil)
387
387
  end
388
388
 
389
- def as_kml
390
-
391
- end
392
-
393
389
  end
394
390
  end
395
391
  end
@@ -1,31 +1,30 @@
1
1
  module PostgisFunctions
2
-
3
-
4
- ###
5
- ##
2
+
6
3
  #
7
4
  # Class Methods
8
5
  #
9
- # Falling back to AR here.
10
- #
11
6
  module ClassMethods
12
7
 
13
8
  #
14
- # Returns the closest record
15
- #
16
- def closest_to(p, srid=4326)
17
- find(:first, :order => "ST_Distance(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))" )
9
+ # Returns the closest record
10
+ def closest_to(p, opts = {})
11
+ srid = opts.delete(:srid) || 4326
12
+ opts.merge!(:order => "ST_Distance(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))")
13
+ find(:first, opts)
18
14
  end
19
15
 
20
- def close_to(p, srid=4326)
21
- find(:all, :order => "ST_Distance(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))" )
16
+ #
17
+ # Order by distance
18
+ def close_to(p, opts = {})
19
+ srid = opts.delete(:srid) || 4326
20
+ opts.merge!(:order => "ST_Distance(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))")
21
+ find(:all, opts)
22
22
  end
23
23
 
24
- #
25
- #
26
- #
27
- def by_length sort='asc'
28
- find(:all, :order => "ST_length(geom) #{sort}" )
24
+ def by_length opts = {}
25
+ sort = opts.delete(:sort) || 'asc'
26
+ opts.merge!(:order => "ST_length(geom) #{sort}")
27
+ find(:all, opts)
29
28
  end
30
29
 
31
30
  def longest
@@ -58,7 +57,7 @@ module PostgisFunctions
58
57
  end
59
58
 
60
59
  end
61
-
62
-
63
-
64
- end
60
+
61
+
62
+
63
+ end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{postgis_adapter}
5
- s.version = "0.3.3"
5
+ s.version = "0.3.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Marcos Piccinini"]
9
- s.date = %q{2009-03-14}
9
+ s.date = %q{2009-04-13}
10
10
  s.description = %q{Postgis Adapter for Activer Record}
11
11
  s.email = ["x@nofxx.com"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
@@ -25,16 +25,16 @@ Gem::Specification.new do |s|
25
25
 
26
26
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
27
  s.add_runtime_dependency(%q<activerecord>, [">= 2.0.2"])
28
- s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
28
+ s.add_development_dependency(%q<newgem>, [">= 1.3.0"])
29
29
  s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
30
30
  else
31
31
  s.add_dependency(%q<activerecord>, [">= 2.0.2"])
32
- s.add_dependency(%q<newgem>, [">= 1.2.3"])
32
+ s.add_dependency(%q<newgem>, [">= 1.3.0"])
33
33
  s.add_dependency(%q<hoe>, [">= 1.8.0"])
34
34
  end
35
35
  else
36
36
  s.add_dependency(%q<activerecord>, [">= 2.0.2"])
37
- s.add_dependency(%q<newgem>, [">= 1.2.3"])
37
+ s.add_dependency(%q<newgem>, [">= 1.3.0"])
38
38
  s.add_dependency(%q<hoe>, [">= 1.8.0"])
39
39
  end
40
40
  end
@@ -0,0 +1,54 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe "Class Functions" do
4
+ before(:all) do
5
+ @c1 ||= City.create!(:data => "City1", :geom => Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]],4326))
6
+ @s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[1,1],[88,88]],4326))
7
+ @p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(1,1,4326))
8
+ end
9
+
10
+ it "should find the closest other point" do
11
+ Position.close_to(@p1.geom, :srid => 4326)[0].data.should == @p1.data
12
+ end
13
+
14
+ it "should find the closest other point and limit" do
15
+ Position.close_to(@p1.geom, :limit => 10).should have(10).positions
16
+ end
17
+
18
+ it "should find the closest other point" do
19
+ Position.closest_to(@p1.geom).data.should == @p1.data
20
+ end
21
+
22
+ it "should sort by linestring length" do
23
+ Street.by_length.should be_instance_of(Array)
24
+ end
25
+
26
+ it "should sort by linestring length" do
27
+ Street.by_length(:limit => 10).should have(10).streets
28
+ end
29
+
30
+ it "should find the longest" do
31
+ Street.longest.should be_instance_of(Street)
32
+ end
33
+
34
+ it "should find all dwithin one" do
35
+ Position.all_within(@s1.geom).should be_instance_of(Array)
36
+ end
37
+
38
+ it "should find all dwithin one" do
39
+ City.by_perimeter.should be_instance_of(Array)
40
+ end
41
+
42
+ it "should sort by polygon area" do
43
+ City.by_area.should be_instance_of(Array)
44
+ end
45
+
46
+ it "should sort by all within" do
47
+ City.all_within(@s1.geom).should be_instance_of(Array)
48
+ end
49
+
50
+ it "should sort by all within" do
51
+ City.by_boundaries.should be_instance_of(Array)
52
+ end
53
+
54
+ end
@@ -20,11 +20,11 @@ describe "Common Functions" do
20
20
  describe "Point" do
21
21
 
22
22
  it "should find the closest other point" do
23
- Position.close_to(@p1.geom,4326)[0].data.should == @p1.data
23
+ Position.close_to(@p1.geom)[0].data.should == @p1.data
24
24
  end
25
25
 
26
26
  it "should find the closest other point" do
27
- Position.closest_to(@p1.geom,4326).data.should == @p1.data
27
+ Position.closest_to(@p1.geom).data.should == @p1.data
28
28
  end
29
29
 
30
30
  it { @p1.distance_to(@s2).should be_close(4.24264068711928, 0.0001) }
@@ -20,7 +20,7 @@ describe "PostgisFunctions" do
20
20
  end
21
21
 
22
22
  it "should calculate distance point to line" do
23
- @p1.geom.as_kml.should be_close(0.248069469178417, 0.00000001)
23
+ @p1.geom.as_kml.should eql("<Point>\n<coordinates>-43,-22</coordinates>\n</Point>\n")
24
24
  end
25
25
 
26
26
  it "should calculate inside a city" do
@@ -39,29 +39,4 @@ describe "PostgisFunctions" do
39
39
 
40
40
  end
41
41
 
42
- #TODO is sorted rspec helper
43
- describe "Class methods" do
44
-
45
- it "should find all dwithin one" do
46
- Position.all_within(@s1.geom).should be_instance_of(Array)
47
- end
48
-
49
- it "should find all dwithin one" do
50
- City.by_perimeter.should be_instance_of(Array)
51
- end
52
-
53
- it "should sort by polygon area" do
54
- City.by_area.should be_instance_of(Array)
55
- end
56
-
57
- it "should sort by all within" do
58
- City.all_within(@s1.geom).should be_instance_of(Array)
59
- end
60
-
61
- it "should sort by all within" do
62
- City.by_boundaries.should be_instance_of(Array)
63
- end
64
-
65
- end
66
-
67
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nofxx-postgis_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcos Piccinini
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-14 00:00:00 -07:00
12
+ date: 2009-04-13 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.2.3
33
+ version: 1.3.0
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: hoe