postgis_adapter 0.7.8 → 0.7.9

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.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ gem "pg"
4
+ gem "nofxx-georuby"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "rcov", ">= 0"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ json_pure (1.4.6)
6
+ nofxx-georuby (1.9.0)
7
+ json_pure (>= 1.4.6)
8
+ pg (0.10.1)
9
+ rcov (0.9.9)
10
+ rspec (2.3.0)
11
+ rspec-core (~> 2.3.0)
12
+ rspec-expectations (~> 2.3.0)
13
+ rspec-mocks (~> 2.3.0)
14
+ rspec-core (2.3.1)
15
+ rspec-expectations (2.3.0)
16
+ diff-lcs (~> 1.1.2)
17
+ rspec-mocks (2.3.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.0.0)
24
+ nofxx-georuby
25
+ pg
26
+ rcov
27
+ rspec (~> 2.3.0)
data/README.rdoc CHANGED
@@ -8,45 +8,39 @@ This fork adds handy methods to make geometrical calculations on postgis.
8
8
  Based on http://georuby.rubyforge.org Spatial Adapter
9
9
 
10
10
  RDocs - http://docs.github.com/nofxx/postgis_adapter
11
+ Postgis Online reference - http://postgis.refractions.net
11
12
  Postgis Manual - http://postgis.refractions.net/documentation/manual-svn
12
13
 
13
- *PostGIS and Rails 2+ only*.
14
-
15
14
 
16
15
  == Install
17
16
 
18
17
  If you are using Spatial Adapter, *remove it first*.
19
18
 
19
+ gem install postgis_adapter
20
+
20
21
 
21
22
  === Dependencies
22
23
 
23
- - georuby
24
+ - georuby gem
24
25
  - postgres 8.3+
25
26
  - postgis 1.3+
26
27
 
27
28
 
28
- === As gem:
29
-
30
- sudo gem install postgis-adapter
31
-
32
- Rails:
33
-
34
- config.gem "postgis_adapter"
35
-
29
+ === Rails 3+
36
30
 
37
- Github version:
31
+ Add dependency to Gemfile:
38
32
 
33
+ gem "postgis_adapter"
39
34
 
40
- sudo gem install nofxx-postgis_adapter --source http://gems.github.com
41
35
 
42
- Rails:
36
+ Or, to use latest from repository:
43
37
 
44
- config.gem "nofxx-postgis_adapter", :lib => "postgis_adapter", :source => "http://gems.github.com"
38
+ gem "postgis_adapter", :git => 'git://github.com/nofxx/postgis_adapter.git'
45
39
 
46
40
 
47
- === As plugin:
41
+ === Rails 2
48
42
 
49
- script/plugin install git://github.com/nofxx/postgis_adapter.git
43
+ gem install postgis_adapter -v 0.7.8
50
44
 
51
45
 
52
46
  == How to Use
@@ -267,6 +261,34 @@ Types:
267
261
  geometry_collection
268
262
 
269
263
 
264
+ === PostGIS Helper Scripts
265
+
266
+ Optional, this will create postgis enabled database automatically for you.
267
+
268
+ Helpers to create postgis template database. At time of writing,
269
+ postgis.sql and spatial_ref_sys.sql are used.
270
+
271
+
272
+ ==== System wide
273
+
274
+
275
+ Find where your OS put those sql files and:
276
+
277
+ rake postgis:template path/to/sqls/folder
278
+
279
+
280
+ ==== Vendorize
281
+
282
+ Place the following scripts in a folder named 'spatial' under the 'db' folder; For example:
283
+
284
+ RAILS_ROOT/db/spatial/lwpostgis.sql
285
+ RAILS_ROOT/db/spatial/spatial_ref_sys
286
+
287
+ These will be used when creating the Test database when running the Rake Test tasks.
288
+ These scripts should have been installed when the PostGIS libraries were installed.
289
+ Online reference: http://postgis.refractions.net/
290
+
291
+
270
292
  === Fixtures
271
293
 
272
294
  If you use fixtures for your unit tests, at some point,
@@ -323,6 +345,17 @@ something like this :
323
345
  place.the_geom = the_geom
324
346
 
325
347
 
348
+ == Postgis Adapter
349
+
350
+ Marcos Piccinini (nofxx)
351
+ Ying Tsen Hong (tsenying)
352
+ Simon Tokumine (tokumine)
353
+ Fernando Blat (ferblape)
354
+ Shoaib Burq (sabman)
355
+
356
+ (in order of appearance)
357
+
358
+
326
359
  == License
327
360
 
328
361
  Spatial Adapter for Rails is released under the MIT license.
@@ -331,7 +364,7 @@ Postgis Adapter is released under the MIT license.
331
364
 
332
365
  == Support
333
366
 
334
- Tested using rails 2.2.2/2.3.3 / postgresql 8.3.7 / postgis 1.3.3 / linux / osx
367
+ Tested using activerecord 3+ / postgresql 8.5+ / postgis 1.5+ / linux / osx
335
368
 
336
369
  Any questions, enhancement proposals, bug notifications or corrections:
337
370
 
data/Rakefile CHANGED
@@ -1,38 +1,36 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/rdoctask'
5
+ #require 'spec/rake/spectask'
3
6
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "postgis_adapter"
8
- gem.summary = "PostGIS Adapter for Active Record"
9
- gem.description = "Execute PostGIS functions on Active Record"
10
- gem.email = "x@nofxx.com"
11
- gem.homepage = "http://github.com/nofxx/postgis_adapter"
12
- gem.authors = ["Marcos Piccinini"]
13
- gem.rubyforge_project = "postgis_adapter"
14
- # TODO: better way for this.....
15
- # gem.add_dependency 'geo_ruby'
16
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
7
+ CLEAN.include('**/*.gem')
8
+
9
+ namespace :gem do
10
+ desc "Create the postgis_adapter gem"
11
+ task :create => [:clean] do
12
+ spec = eval(IO.read('postgis_adapter.gemspec'))
13
+ Gem::Builder.new(spec).build
17
14
  end
18
- rescue LoadError
19
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
20
- end
21
15
 
22
- require 'spec/rake/spectask'
23
- Spec::Rake::SpecTask.new(:spec) do |spec|
24
- spec.libs << 'lib' << 'spec'
25
- spec.spec_files = FileList['spec/**/*_spec.rb']
16
+ desc "Install the postgis_adapter gem"
17
+ task :install => [:create] do
18
+ file = Dir['*.gem'].first
19
+ sh "gem install #{file}"
20
+ end
26
21
  end
27
22
 
28
- Spec::Rake::SpecTask.new(:rcov) do |spec|
29
- spec.libs << 'lib' << 'spec'
30
- spec.pattern = 'spec/**/*_spec.rb'
31
- spec.rcov = true
32
- end
33
- task :default => :spec
23
+ # Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ # spec.libs << 'lib' << 'spec'
25
+ # spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ # end
27
+
28
+ # Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ # spec.libs << 'lib' << 'spec'
30
+ # spec.pattern = 'spec/**/*_spec.rb'
31
+ # spec.rcov = true
32
+ # end
34
33
 
35
- require 'rake/rdoctask'
36
34
  Rake::RDocTask.new do |rdoc|
37
35
  version = File.exist?('VERSION') ? File.read('VERSION').chomp : ""
38
36
  rdoc.rdoc_dir = 'rdoc'
@@ -41,6 +39,8 @@ Rake::RDocTask.new do |rdoc|
41
39
  rdoc.rdoc_files.include('lib/**/*.rb')
42
40
  end
43
41
 
42
+ task :default => :spec
43
+
44
44
  #
45
45
  # Reek & Roodi
46
46
  #
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.8
1
+ 0.7.9
@@ -5,21 +5,21 @@
5
5
  # Code from
6
6
  # http://georuby.rubyforge.org Spatial Adapter
7
7
  #
8
- require 'activerecord'
8
+ require 'active_record'
9
9
  require 'active_record/connection_adapters/postgresql_adapter'
10
10
  require 'geo_ruby'
11
11
  require 'postgis_adapter/common_spatial_adapter'
12
- require 'postgis_functions'
13
- require 'postgis_functions/common'
14
- require 'postgis_functions/class'
15
- require 'postgis_functions/bbox'
12
+ require 'postgis_adapter/functions'
13
+ require 'postgis_adapter/functions/common'
14
+ require 'postgis_adapter/functions/class'
15
+ require 'postgis_adapter/functions/bbox'
16
16
  require 'postgis_adapter/acts_as_geom'
17
17
 
18
18
  include GeoRuby::SimpleFeatures
19
19
  include SpatialAdapter
20
20
 
21
21
  #tables to ignore in migration : relative to PostGIS management of geometric columns
22
- ActiveRecord::SchemaDumper.ignore_tables << "spatial_ref_sys" << "geometry_columns"
22
+ ActiveRecord::SchemaDumper.ignore_tables.concat %w{ spatial_ref_sys geometry_columns geography_columns }
23
23
 
24
24
  #add a method to_yaml to the Geometry class which will transform a geometry in a form suitable to be used in a YAML file (such as in a fixture)
25
25
  GeoRuby::SimpleFeatures::Geometry.class_eval do
@@ -102,6 +102,25 @@ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
102
102
 
103
103
  include SpatialAdapter
104
104
 
105
+ # SCHEMA STATEMENTS ========================================
106
+
107
+ alias :original_recreate_database :recreate_database
108
+ def recreate_database(configuration, enc_option)
109
+ `dropdb -U "#{configuration["test"]["username"]}" #{configuration["test"]["database"]}`
110
+ `createdb #{enc_option} -U "#{configuration["test"]["username"]}" #{configuration["test"]["database"]}`
111
+ `createlang -U "#{configuration["test"]["username"]}" plpgsql #{configuration["test"]["database"]}`
112
+ `psql -d #{configuration["test"]["database"]} -f db/spatial/postgis.sql`
113
+ `psql -d #{configuration["test"]["database"]} -f db/spatial/spatial_ref_sys.sql`
114
+ end
115
+
116
+ alias :original_create_database :create_database
117
+ def create_database(name, options = {})
118
+ original_create_database(name, options = {})
119
+ `createlang plpgsql #{name}`
120
+ `psql -d #{name} -f db/spatial/postgis.sql`
121
+ `psql -d #{name} -f db/spatial/spatial_ref_sys.sql`
122
+ end
123
+
105
124
  alias :original_native_database_types :native_database_types
106
125
  def native_database_types
107
126
  original_native_database_types.update(geometry_data_types)
@@ -248,16 +267,16 @@ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
248
267
  end
249
268
  end
250
269
 
251
- # # For version of Rails where exists disable_referential_integrity
270
+ # For version of Rails where exists disable_referential_integrity
252
271
  if self.instance_methods.include? "disable_referential_integrity"
253
272
  #Pete Deffendol's patch
254
273
  alias :original_disable_referential_integrity :disable_referential_integrity
255
274
  def disable_referential_integrity(&block) #:nodoc:
256
- ignore_tables = %w{ geometry_columns spatial_ref_sys geography_columns }
257
- execute(tables.select { |name| !ignore_tables.include?(name) }.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
275
+ ignore_tables = %w{ geometry_columns spatial_ref_sys } # geography_columns + views
276
+ execute(tables.select { |name| !ignore_tables.include?(name) }.map { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
258
277
  yield
259
278
  ensure
260
- execute(tables.select { |name| !ignore_tables.include?(name)}.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
279
+ execute(tables.select { |name| !ignore_tables.include?(name)}.map { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
261
280
  end
262
281
  end
263
282
 
@@ -289,8 +308,8 @@ SELECT * FROM geometry_columns WHERE f_table_name = '#{table_name}'
289
308
  end
290
309
 
291
310
  raw_geom_infos
292
- rescue => e
293
- nil
311
+ rescue => e
312
+ nil
294
313
  end
295
314
 
296
315
  end
@@ -3,7 +3,8 @@
3
3
  #
4
4
  # http://github.com/nofxx/postgis_adapter
5
5
  #
6
- module PostgisFunctions
6
+ module PostgisAdapter
7
+ module Functions
7
8
  def self.included(base)
8
9
  base.send :extend, ClassMethods
9
10
  end
@@ -24,6 +25,7 @@ module PostgisFunctions
24
25
  when :point then PointFunctions
25
26
  when :polygon then PolygonFunctions
26
27
  when :line_string, :multi_line_string then LineStringFunctions
28
+ when :multi_polygon then MultiPolygonFunctions
27
29
  end unless geom[0].kind_of? Symbol
28
30
  end
29
31
  alias :acts_as_geom :has_geom
@@ -36,5 +38,6 @@ module PostgisFunctions
36
38
  end
37
39
  end
38
40
  end
41
+ end
39
42
 
40
- ActiveRecord::Base.send :include, PostgisFunctions
43
+ ActiveRecord::Base.send :include, PostgisAdapter::Functions
@@ -49,7 +49,7 @@ ActiveRecord::SchemaDumper.class_eval do
49
49
 
50
50
  columns.each do |column|
51
51
 
52
- raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" if @types[column.type].nil?
52
+ raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}' in table '#{table}'" if @types[column.type].nil?
53
53
  next if column.name == pk
54
54
  #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
55
55
  if column.is_a?(SpatialColumn)
@@ -15,7 +15,8 @@
15
15
  # Earth Spheroid - http://en.wikipedia.org/wiki/Figure_of_the_Earth
16
16
  #
17
17
 
18
- module PostgisFunctions
18
+ module PostgisAdapter
19
+ module Functions
19
20
  # WGS84 Spheroid
20
21
  EARTH_SPHEROID = "'SPHEROID[\"GRS-80\",6378137,298.257222101]'" # SRID => 4326
21
22
 
@@ -114,7 +115,7 @@ module PostgisFunctions
114
115
  end
115
116
 
116
117
  end
117
-
118
+ end
118
119
  #
119
120
  # POINT(0 0)
120
121
  # LINESTRING(0 0,1 1,1 2)
@@ -4,7 +4,8 @@
4
4
  # BBox
5
5
  #
6
6
  #
7
- module PostgisFunctions
7
+ module PostgisAdapter
8
+ module Functions
8
9
 
9
10
  #
10
11
  # These operators utilize indexes. They compare geometries by bounding boxes.
@@ -126,3 +127,4 @@ module PostgisFunctions
126
127
  bbox("=", other)
127
128
  end
128
129
  end
130
+ end
@@ -1,4 +1,5 @@
1
- module PostgisFunctions
1
+ module PostgisAdapter
2
+ module Functions
2
3
 
3
4
  #
4
5
  # Class Methods
@@ -47,17 +48,20 @@ module PostgisFunctions
47
48
  find(:all, :order => "ST_Perimeter(geom) #{sort}" )
48
49
  end
49
50
 
50
- def all_within(other, margin=1)
51
- # find(:all, :conditions => "ST_DWithin(geom, ST_GeomFromEWKB(E'#{other.as_ewkt}'), #{margin})")
51
+ def all_dwithin(other, margin=1)
52
+ # find(:all, :conditions => "ST_DWithin(geom, ST_GeomFromEWKB(E'#{other.as_ewkt}'), #{margin})")
52
53
  find(:all, :conditions => "ST_DWithin(geom, ST_GeomFromEWKT(E'#{other.as_hex_ewkb}'), #{margin})")
53
54
  end
54
55
 
56
+ def all_within(other)
57
+ find(:all, :conditions => "ST_Within(geom, ST_GeomFromEWKT(E'#{other.as_hex_ewkb}'))")
58
+ end
59
+
55
60
  def by_boundaries sort='asc'
56
61
  find(:all, :order => "ST_Boundary(geom) #{sort}" )
57
62
  end
58
63
 
59
64
  end
60
65
 
61
-
62
-
66
+ end
63
67
  end
@@ -6,7 +6,15 @@
6
6
  # The methods here can be used by all geoms.
7
7
  #
8
8
 
9
- module PostgisFunctions
9
+ module PostgisAdapter
10
+ module Functions
11
+
12
+ #
13
+ # Test if a geometry is well formed.
14
+ #
15
+ def valid_geom?
16
+ postgis_calculate(:isvalid, self)
17
+ end
10
18
 
11
19
  #
12
20
  # True if the given geometries represent the same geometry.
@@ -232,12 +240,17 @@ module PostgisFunctions
232
240
  postgis_calculate(:simplify, self, tolerance)
233
241
  end
234
242
 
235
-
236
243
  def simplify!(tolerance=0.1)
237
244
  #FIXME: not good..
238
245
  self.update_attribute(geo_columns.first, simplify)
239
246
  end
240
247
 
248
+ #
249
+ #
250
+ def buffer(width=0.1)
251
+ postgis_calculate(:buffer, self, width)
252
+ end
253
+
241
254
  #
242
255
  # Returns a "simplified" version of the given geometry using the Douglas-Peuker
243
256
  # algorithm. Will avoid creating derived geometries (polygons in particular) that
@@ -509,10 +522,18 @@ module PostgisFunctions
509
522
  #
510
523
  # http://geojson.org/
511
524
  #
512
- def as_geo_json(precision=15, bbox=0)
525
+ def as_geo_json(precision=15, bbox = 0)
513
526
  postgis_calculate(:AsGeoJSON, self, [precision, bbox])
514
527
  end
515
528
 
529
+ #
530
+ # ST_PointOnSurface — Returns a POINT guaranteed to lie on the surface.
531
+ #
532
+ # geometry ST_PointOnSurface(geometry g1);eometry A, geometry B);
533
+ #
534
+ def point_on_surface
535
+ postgis_calculate(:pointonsurface, self)
536
+ end
516
537
 
517
538
  #
518
539
  #
@@ -875,8 +896,20 @@ module PostgisFunctions
875
896
 
876
897
  end
877
898
 
878
- end
899
+ #
900
+ #
901
+ #
902
+ #
903
+ # MultiPolygon
904
+ #
905
+ #
906
+ #
907
+ #
908
+ module MultiPolygonFunctions
909
+ end
879
910
 
911
+ end
912
+ end
880
913
  # NEW
881
914
  #ST_OrderingEquals — Returns true if the given geometries represent the same geometry and points are in the same directional order.
882
915
  #boolean ST_OrderingEquals(g
@@ -0,0 +1,7 @@
1
+ module PostgisAdapter
2
+ class Railtie < Rails::Railtie
3
+ initializer "postgis adapter" do
4
+ require "postgis_adapter"
5
+ end
6
+ end
7
+ end
@@ -1,76 +1,19 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'postgis_adapter'
3
+ spec.version = '0.7.9'
4
+ spec.authors = ['Marcos Piccinini']
5
+ spec.summary = 'PostGIS Adapter for Active Record'
6
+ spec.email = 'x@nofxx.com'
7
+ spec.homepage = 'http://github.com/nofxx/postgis_adapter'
5
8
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{postgis_adapter}
8
- s.version = "0.7.8"
9
+ spec.rdoc_options = ['--charset=UTF-8']
10
+ spec.rubyforge_project = 'postgis_adapter'
9
11
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Marcos Piccinini"]
12
- s.date = %q{2010-02-26}
13
- s.description = %q{Execute PostGIS functions on Active Record}
14
- s.email = %q{x@nofxx.com}
15
- s.extra_rdoc_files = [
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- ".gitignore",
20
- "History.txt",
21
- "MIT-LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "init.rb",
26
- "lib/postgis_adapter.rb",
27
- "lib/postgis_adapter/acts_as_geom.rb",
28
- "lib/postgis_adapter/common_spatial_adapter.rb",
29
- "lib/postgis_functions.rb",
30
- "lib/postgis_functions/bbox.rb",
31
- "lib/postgis_functions/class.rb",
32
- "lib/postgis_functions/common.rb",
33
- "postgis_adapter.gemspec",
34
- "rails/init.rb",
35
- "spec/db/models_postgis.rb",
36
- "spec/db/schema_postgis.rb",
37
- "spec/postgis_adapter/acts_as_geom_spec.rb",
38
- "spec/postgis_adapter/common_spatial_adapter_spec.rb",
39
- "spec/postgis_adapter_spec.rb",
40
- "spec/postgis_functions/bbox_spec.rb",
41
- "spec/postgis_functions/class_spec.rb",
42
- "spec/postgis_functions/common_spec.rb",
43
- "spec/postgis_functions_spec.rb",
44
- "spec/spec.opts",
45
- "spec/spec_helper.rb"
46
- ]
47
- s.homepage = %q{http://github.com/nofxx/postgis_adapter}
48
- s.rdoc_options = ["--charset=UTF-8"]
49
- s.require_paths = ["lib"]
50
- s.rubyforge_project = %q{postgis_adapter}
51
- s.rubygems_version = %q{1.3.5}
52
- s.summary = %q{PostGIS Adapter for Active Record}
53
- s.test_files = [
54
- "spec/db/models_postgis.rb",
55
- "spec/db/schema_postgis.rb",
56
- "spec/postgis_adapter/acts_as_geom_spec.rb",
57
- "spec/postgis_adapter/common_spatial_adapter_spec.rb",
58
- "spec/postgis_functions_spec.rb",
59
- "spec/spec_helper.rb",
60
- "spec/postgis_adapter_spec.rb",
61
- "spec/postgis_functions/class_spec.rb",
62
- "spec/postgis_functions/common_spec.rb",
63
- "spec/postgis_functions/bbox_spec.rb"
64
- ]
12
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
+ spec.test_files = Dir['spec/**/*.rb']
14
+ spec.extra_rdoc_files = ['README.rdoc']
65
15
 
66
- if s.respond_to? :specification_version then
67
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
68
- s.specification_version = 3
16
+ spec.add_dependency 'GeoRuby'
69
17
 
70
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
71
- else
72
- end
73
- else
74
- end
18
+ spec.description = 'Execute PostGIS functions on Active Record'
75
19
  end
76
-
data/rails/init.rb CHANGED
@@ -1,9 +1,28 @@
1
+ # Patch Arel to support geometry type.
2
+ module Arel
3
+ module Attributes
4
+ class << self
5
+ alias original_for for
6
+
7
+ def for(column)
8
+ case column.type
9
+ when :geometry then String
10
+ else
11
+ original_for(column)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
1
18
  class SpatialAdapterNotCompatibleError < StandardError
2
19
  end
3
20
 
4
- unless ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
5
- raise SpatialAdapterNotCompatibleError.
6
- new("Database config file not set or it does not map to PostgreSQL\n" +
7
- "Only PostgreSQL with PostGIS is supported by postgis_adapter.")
21
+ unless ActiveRecord::Base.connection.adapter_name.downcase == 'postgresql'
22
+ error_message = "Database config file not set or it does not map to "
23
+ error_message << "PostgreSQL.\nOnly PostgreSQL with PostGIS is supported "
24
+ error_message << "by postgis_adapter.")
25
+ raise SpatialAdapterNotCompatibleError.new(error_message)
8
26
  end
27
+
9
28
  require 'postgis_adapter'
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  describe "Point" do
4
4
 
@@ -1,12 +1,18 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  describe "ClassMethods" do
4
4
  before(:all) do
5
5
  @c1 ||= City.create!(:data => "CityClass", :geom => Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]],4326))
6
+ @c2 ||= City.create!(:data => "CityClass", :geom => Polygon.from_coordinates([[[10,10],[10,50],[50,50],[10,10]],[[2,5],[5,1],[14,1],[2,5]]],4326))
6
7
  @s1 ||= Street.create!(:data => "StreetClass", :geom => LineString.from_coordinates([[1,1],[99,88]],4326))
7
8
  @s2 ||= Street.create!(:data => "StreetClassTiny", :geom => LineString.from_coordinates([[1,1],[1.1,1.1]],4326))
8
9
  @p1 ||= Position.create!(:data => "PointClass", :geom => Point.from_x_y(99,99,4326))
9
10
  @p2 ||= Position.create!(:data => "PointClassClose", :geom => Point.from_x_y(99.9,99.9,4326))
11
+ @p3 ||= Position.create!(:data => "PointInsideCity", :geom => Point.from_x_y(15.0,15.0,4326))
12
+ end
13
+
14
+ after(:all) do
15
+ [City, Street, Position].each { |m| m.delete_all }
10
16
  end
11
17
 
12
18
  it "should find the closest other point" do
@@ -54,8 +60,16 @@ describe "ClassMethods" do
54
60
  City.by_area.should be_instance_of(Array)
55
61
  end
56
62
 
57
- it "should sort by all within" do
58
- City.all_within(@s1.geom).should be_instance_of(Array)
63
+ it "should sort by all dwithin" do
64
+ City.all_dwithin(@s1.geom).should eql([@c1, @c2])
65
+ end
66
+
67
+ it "should find all within polygon" do
68
+ Position.all_within(@c1.geom).should eql([@p3])#Array)
69
+ end
70
+
71
+ it "should find all within polygon 2" do
72
+ Position.all_within(@c2.geom).should eql([])#Array)
59
73
  end
60
74
 
61
75
  it "should sort by all within" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  describe "Common Functions" do
4
4
 
@@ -77,7 +77,7 @@ describe "Common Functions" do
77
77
  it "should transform non saved srid geoms" do
78
78
  pt = Point.from_x_y(11121381.4586196,10161852.0494475, 29101)
79
79
  pos = Position.new(:geom => pt)
80
- pos.transform(4326)
80
+ pos.transform!(4326)
81
81
  pos.geom.x.should be_close(1.00000000000005, 0.00001)
82
82
  pos.geom.y.should be_close(1.00000000000005, 0.00001)
83
83
  end
@@ -126,6 +126,8 @@ describe "Common Functions" do
126
126
 
127
127
  describe "Polygon" do
128
128
 
129
+ it { City.first.data.should eql("City1") }
130
+
129
131
  it "sort by area size" do
130
132
  City.by_area.first.data.should == "City1" #[@c1, @c2, @c3]
131
133
  end
@@ -156,7 +158,7 @@ describe "Common Functions" do
156
158
 
157
159
  it { @c1.covers?(@p1).should be_false }
158
160
  it { @c1.covers?(@p4).should be_true }
159
- it { @c1.should_not be_within(@c2) }
161
+ it { @c1.within?(@c2).should be_false }
160
162
 
161
163
  it "city overlaps point?" do
162
164
  lambda { @c3.overlaps?(@c2) }.should raise_error # WHY??
@@ -268,6 +270,10 @@ describe "Common Functions" do
268
270
  @s1.intersection(@p2).should be_instance_of(GeometryCollection)
269
271
  end
270
272
 
273
+ it "have a point on surface" do
274
+ @s3.point_on_surface.should be_a GeoRuby::SimpleFeatures::Point
275
+ end
276
+
271
277
  describe "Self" do
272
278
 
273
279
  it do
@@ -380,7 +386,7 @@ describe "Common Functions" do
380
386
  it "should transform non saved" do
381
387
  ls = LineString.from_coordinates([[11435579.3992231,10669620.8116516],[11721337.4281638,11210714.9524106]],29101)
382
388
  str = Street.new(:geom => ls)
383
- str.transform(4326)
389
+ str.transform!(4326)
384
390
  str.geom[0].x.should be_close(4,0.0000001)
385
391
  str.geom[0].y.should be_close(4,0.0000001)
386
392
  str.geom[1].x.should be_close(7,0.0000001)
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
2
 
3
3
  describe "PostgisFunctions" do
4
4
  before(:all) do
@@ -12,11 +12,11 @@ describe "PostgisFunctions" do
12
12
  describe "Common Mix" do
13
13
 
14
14
  it "should calculate distance point to line" do
15
- @p1.distance_to(@s1).should be_close(0.248069469178417, 0.00000001)
15
+ @p1.distance_to(@s1).should be_within(0.00000001).of(0.248069469178417)
16
16
  end
17
17
 
18
18
  it "should calculate distance point to line" do
19
- @cg.distance_to(@s1).should be_close(0.248069469178417, 0.00000001)
19
+ @cg.distance_to(@s1).should be_within(0.00000001).of(0.248069469178417)
20
20
  end
21
21
 
22
22
  it "should calculate distance point to line" do
@@ -28,33 +28,33 @@ describe "PostgisFunctions" do
28
28
  end
29
29
 
30
30
  it "should find the distance from a unsaved point" do
31
- @p1.distance_to(Point.from_x_y(5,5,4326)).should be_close(55.0726792520575, 0.001)
31
+ @p1.distance_to(Point.from_x_y(5,5,4326)).should be_within(0.00001).of(55.0726792520575)
32
32
  end
33
33
 
34
34
  it "should work with unsaved objects" do
35
35
  ss = Street.new(:data => "Street1", :geom => LineString.from_coordinates([[-44,-21],[-43,-29]],4326))
36
- ss.length_spheroid.should be_close(891908.39, 0.01)
36
+ ss.length_spheroid.should be_within(0.01).of(891908.39)
37
37
  end
38
38
 
39
- it { @c1.area(32640).should be_close(9165235788987.37, 0.01) }
39
+ it { @c1.area(32640).should be_within(0.01).of(9165235788987.37) }
40
40
 
41
- it { @c1.area.should be_close(720.0, 0.1) }
41
+ it { @c1.area.should be_within(0.1).of(720.0) }
42
42
 
43
43
  it "should be strictly left of city" do
44
44
  @p1.should be_strictly_left_of(@c1)
45
45
  end
46
46
 
47
- it { @s1.length.should be_close(8.06225774829855, 0.001) }
47
+ it { @s1.length.should be_within(0.0001).of(8.06225774829855) }
48
48
 
49
- it { @s1.length_spheroid.should be_close(891883.597963462,0.0001) }
49
+ it { @s1.length_spheroid.should be_within(0.0001).of(891883.597963462) }
50
50
 
51
51
  it "should work with a diff column name" do
52
52
  px2 = DiffName.create!(:data => "Hey 2", :the_geom => Point.from_x_y(20,20, 4326))
53
- @px.distance_to(px2).should be_close(10.0, 0.1)
53
+ @px.distance_to(px2).should be_within(0.01).of(10.0)
54
54
  end
55
55
 
56
56
  it "should work with mixed column names" do
57
- @px.distance_to(@s1).should be_close(66.4,1)
57
+ @px.distance_to(@s1).should be_within(0.1).of(66.4)
58
58
  end
59
59
  end
60
60
  end
@@ -151,8 +151,8 @@ describe "PostgisAdapter" do
151
151
  end
152
152
 
153
153
  it "should find by geom" do
154
- pts = Area.find_all_by_geom(LineString.
155
- from_coordinates([[0,0],[2,2]],4326))
154
+ pending
155
+ pts = Area.find_all_by_geom(LineString.from_coordinates([[0,0],[2,2]],4326))
156
156
  pts.should be_instance_of(Array)
157
157
  pts.length.should eql(2)
158
158
  pts[0].data.should match(/Point/)
@@ -160,12 +160,13 @@ describe "PostgisAdapter" do
160
160
  end
161
161
 
162
162
  it "should find by geom again" do
163
- pts = Area.find_all_by_geom(LineString.
164
- from_coordinates([[2.49,1.99],[2.51,2.01]],4326))
163
+ pending
164
+ pts = Area.find_all_by_geom(LineString.from_coordinates([[2.49,1.99],[2.51,2.01]],4326))
165
165
  pts[0].data.should eql("Point3")
166
166
  end
167
167
 
168
168
  it "should find by geom column bbox condition" do
169
+ pending
169
170
  pts = Area.find_all_by_geom([[0,0],[2,2],4326])
170
171
  pts.should be_instance_of(Array)
171
172
  pts.length.should eql(2)
@@ -220,8 +221,8 @@ describe "PostgisAdapter" do
220
221
  bar.data.should eql("")
221
222
 
222
223
  if BinaryDefault.connection.encoding == "UTF8"
223
- foo.value.should eql("f\xf4o")
224
- bar.value.should eql("b\xe5r")
224
+ foo.value.encode("UTF-8", "ISO-8859-1").should eql("fôo")
225
+ bar.value.encode("UTF-8", "ISO-8859-1").should eql("bår")
225
226
  end
226
227
  end
227
228
 
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,20 @@
1
+ SPEC_DB = {
2
+ :adapter => "postgresql",
3
+ :database => "postgis_adapter",
4
+ :username => "postgres",
5
+ :password => ""
6
+ }
7
+
1
8
  require 'rubygems'
2
- require 'spec'
3
9
  require 'pg'
4
- require 'activerecord'
5
10
  $:.unshift((File.join(File.dirname(__FILE__), '..', 'lib')))
6
- gem 'activerecord', "=2.3.5"
11
+
12
+ require "rspec"
13
+ require "active_record"
14
+
7
15
  gem 'nofxx-georuby'
8
16
  require 'postgis_adapter'
17
+ require 'logger'
9
18
  # GeoRuby::SimpleFeatures::DEFAULT_SRID = -1
10
19
 
11
20
  # Monkey patch Schema.define logger
@@ -13,17 +22,24 @@ $logger = Logger.new(StringIO.new)
13
22
  def $logger.write(d); self.info(d); end
14
23
  # $stdout = $logger
15
24
 
16
-
17
25
  ActiveRecord::Base.logger = $logger
18
- ActiveRecord::Base.establish_connection({ :adapter => "postgresql",
19
- :database => "postgis_adapter",
20
- :username => "postgres",
21
- :password => "" })
22
26
 
23
- PG_VERSION = ActiveRecord::Base.connection.select_value("SELECT version()").scan(/PostgreSQL ([\d\.]*)/)[0][0]
27
+ begin
28
+ ActiveRecord::Base.establish_connection(SPEC_DB)
29
+ ActiveRecord::Migration.verbose = false
30
+ PG_VERSION = ActiveRecord::Base.connection.select_value("SELECT version()").scan(/PostgreSQL ([\d\.]*)/)[0][0]
31
+
32
+ puts "Running against PostgreSQL #{PG_VERSION}"
33
+
34
+ require File.dirname(__FILE__) + '/db/schema_postgis.rb'
35
+ require File.dirname(__FILE__) + '/db/models_postgis.rb'
36
+
37
+ rescue PGError
38
+ puts "Test DB not found, creating one for you..."
39
+ `createdb -U #{SPEC_DB[:username]} #{SPEC_DB[:database]} -T template_postgis`
40
+ puts "Done. Please run spec again."
41
+ exit
42
+ end
24
43
 
25
- puts "Running against PostgreSQL #{PG_VERSION}"
26
44
 
27
- require File.dirname(__FILE__) + '/db/schema_postgis.rb'
28
- require File.dirname(__FILE__) + '/db/models_postgis.rb'
29
45
 
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgis_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.8
4
+ prerelease:
5
+ version: 0.7.9
5
6
  platform: ruby
6
7
  authors:
7
8
  - Marcos Piccinini
@@ -9,10 +10,20 @@ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2010-02-26 00:00:00 -03:00
13
+ date: 2011-03-05 00:00:00 -03:00
13
14
  default_executable:
14
- dependencies: []
15
-
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: GeoRuby
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
16
27
  description: Execute PostGIS functions on Active Record
17
28
  email: x@nofxx.com
18
29
  executables: []
@@ -22,33 +33,34 @@ extensions: []
22
33
  extra_rdoc_files:
23
34
  - README.rdoc
24
35
  files:
25
- - .gitignore
26
- - History.txt
27
- - MIT-LICENSE
28
- - README.rdoc
29
- - Rakefile
30
- - VERSION
31
- - init.rb
32
- - lib/postgis_adapter.rb
33
- - lib/postgis_adapter/acts_as_geom.rb
34
36
  - lib/postgis_adapter/common_spatial_adapter.rb
35
- - lib/postgis_functions.rb
36
- - lib/postgis_functions/bbox.rb
37
- - lib/postgis_functions/class.rb
38
- - lib/postgis_functions/common.rb
39
- - postgis_adapter.gemspec
40
- - rails/init.rb
37
+ - lib/postgis_adapter/functions.rb
38
+ - lib/postgis_adapter/acts_as_geom.rb
39
+ - lib/postgis_adapter/railtie.rb
40
+ - lib/postgis_adapter/functions/common.rb
41
+ - lib/postgis_adapter/functions/bbox.rb
42
+ - lib/postgis_adapter/functions/class.rb
43
+ - lib/postgis_adapter.rb
41
44
  - spec/db/models_postgis.rb
42
45
  - spec/db/schema_postgis.rb
43
46
  - spec/postgis_adapter/acts_as_geom_spec.rb
47
+ - spec/postgis_adapter/functions/class_spec.rb
48
+ - spec/postgis_adapter/functions/common_spec.rb
49
+ - spec/postgis_adapter/functions/bbox_spec.rb
44
50
  - spec/postgis_adapter/common_spatial_adapter_spec.rb
45
- - spec/postgis_adapter_spec.rb
46
- - spec/postgis_functions/bbox_spec.rb
47
- - spec/postgis_functions/class_spec.rb
48
- - spec/postgis_functions/common_spec.rb
49
- - spec/postgis_functions_spec.rb
50
- - spec/spec.opts
51
+ - spec/postgis_adapter/functions_spec.rb
51
52
  - spec/spec_helper.rb
53
+ - spec/postgis_adapter_spec.rb
54
+ - Gemfile.lock
55
+ - postgis_adapter.gemspec
56
+ - MIT-LICENSE
57
+ - rails/init.rb
58
+ - Rakefile
59
+ - VERSION
60
+ - README.rdoc
61
+ - Gemfile
62
+ - init.rb
63
+ - History.txt
52
64
  has_rdoc: true
53
65
  homepage: http://github.com/nofxx/postgis_adapter
54
66
  licenses: []
@@ -59,21 +71,21 @@ rdoc_options:
59
71
  require_paths:
60
72
  - lib
61
73
  required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
62
75
  requirements:
63
76
  - - ">="
64
77
  - !ruby/object:Gem::Version
65
78
  version: "0"
66
- version:
67
79
  required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
68
81
  requirements:
69
82
  - - ">="
70
83
  - !ruby/object:Gem::Version
71
84
  version: "0"
72
- version:
73
85
  requirements: []
74
86
 
75
87
  rubyforge_project: postgis_adapter
76
- rubygems_version: 1.3.5
88
+ rubygems_version: 1.5.2
77
89
  signing_key:
78
90
  specification_version: 3
79
91
  summary: PostGIS Adapter for Active Record
@@ -81,10 +93,10 @@ test_files:
81
93
  - spec/db/models_postgis.rb
82
94
  - spec/db/schema_postgis.rb
83
95
  - spec/postgis_adapter/acts_as_geom_spec.rb
96
+ - spec/postgis_adapter/functions/class_spec.rb
97
+ - spec/postgis_adapter/functions/common_spec.rb
98
+ - spec/postgis_adapter/functions/bbox_spec.rb
84
99
  - spec/postgis_adapter/common_spatial_adapter_spec.rb
85
- - spec/postgis_functions_spec.rb
100
+ - spec/postgis_adapter/functions_spec.rb
86
101
  - spec/spec_helper.rb
87
102
  - spec/postgis_adapter_spec.rb
88
- - spec/postgis_functions/class_spec.rb
89
- - spec/postgis_functions/common_spec.rb
90
- - spec/postgis_functions/bbox_spec.rb
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- .DS_Store
2
- doc/*
3
- rdoc/*
4
- coverage/*
5
- spec/debug.log
6
- pkg/*
7
- *flymake.rb
data/spec/spec.opts DELETED
@@ -1,4 +0,0 @@
1
- --colour
2
- --format profile
3
- --timeout 20
4
- --diff