Skip to content

Commit

Permalink
add/fixes some specs
Browse files Browse the repository at this point in the history
  • Loading branch information
nofxx committed Sep 20, 2010
1 parent 518c689 commit d04bf4a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/postgis_adapter.rb
Expand Up @@ -254,10 +254,10 @@ def columns(table_name, name = nil) #:nodoc:
alias :original_disable_referential_integrity :disable_referential_integrity
def disable_referential_integrity(&block) #:nodoc:
ignore_tables = %w{ geometry_columns spatial_ref_sys geography_columns }
execute(tables.select { |name| !ignore_tables.include?(name) }.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
execute(tables.select { |name| !ignore_tables.include?(name) }.map { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
yield
ensure
execute(tables.select { |name| !ignore_tables.include?(name)}.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
execute(tables.select { |name| !ignore_tables.include?(name)}.map { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/postgis_adapter/common_spatial_adapter.rb
Expand Up @@ -49,7 +49,7 @@ def table(table, stream)

columns.each do |column|

raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" if @types[column.type].nil?
raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}' in table '#{table}'" if @types[column.type].nil?
next if column.name == pk
#need to use less_simplified_type here or have each specific geometry type be simplified to a specific simplified type in Column and each one treated separately in the Column methods
if column.is_a?(SpatialColumn)
Expand Down
26 changes: 23 additions & 3 deletions lib/postgis_adapter/functions/common.rb
Expand Up @@ -9,6 +9,13 @@
module PostgisAdapter
module Functions

#
# Test if a geometry is well formed.
#
def valid_geom?
postgis_calculate(:isvalid, self)
end

#
# True if the given geometries represent the same geometry.
# Directionality is ignored.
Expand Down Expand Up @@ -233,12 +240,17 @@ def simplify(tolerance=0.1)
postgis_calculate(:simplify, self, tolerance)
end


def simplify!(tolerance=0.1)
#FIXME: not good..
self.update_attribute(geo_columns.first, simplify)
end

#
#
def buffer(width=0.1)
postgis_calculate(:buffer, self, width)
end

#
# Returns a "simplified" version of the given geometry using the Douglas-Peuker
# algorithm. Will avoid creating derived geometries (polygons in particular) that
Expand Down Expand Up @@ -510,10 +522,18 @@ def to_utm
#
# http://geojson.org/
#
def as_geo_json(precision=15, bbox=0)
def as_geo_json(precision=15, bbox = 0)
postgis_calculate(:AsGeoJSON, self, [precision, bbox])
end

#
# ST_PointOnSurface — Returns a POINT guaranteed to lie on the surface.
#
# geometry ST_PointOnSurface(geometry g1);eometry A, geometry B);
#
def point_on_surface
postgis_calculate(:pointonsurface, self)
end

#
#
Expand Down Expand Up @@ -875,7 +895,7 @@ def covers? other
end

end

#
#
#
Expand Down
4 changes: 4 additions & 0 deletions spec/postgis_adapter/functions/class_spec.rb
Expand Up @@ -9,6 +9,10 @@
@p2 ||= Position.create!(:data => "PointClassClose", :geom => Point.from_x_y(99.9,99.9,4326))
end

after(:all) do
[City, Street, Position].each { |m| m.delete_all }
end

it "should find the closest other point" do
Position.close_to(Point.from_x_y(99,99,4326), :srid => 4326)[0].data.should == @p1.data
end
Expand Down
6 changes: 6 additions & 0 deletions spec/postgis_adapter/functions/common_spec.rb
Expand Up @@ -126,6 +126,8 @@

describe "Polygon" do

it { City.first.data.should eql("City1") }

it "sort by area size" do
City.by_area.first.data.should == "City1" #[@c1, @c2, @c3]
end
Expand Down Expand Up @@ -268,6 +270,10 @@
@s1.intersection(@p2).should be_instance_of(GeometryCollection)
end

it "have a point on surface" do
@s3.point_on_surface.should be_a GeoRuby::SimpleFeatures::Point
end

describe "Self" do

it do
Expand Down

0 comments on commit d04bf4a

Please sign in to comment.