nofxx-postgis_adapter 0.2.1 → 0.2.2

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.
@@ -4,7 +4,8 @@
4
4
  # Spatial Adapter PostGIS Adapter for ActiveRecord
5
5
  #
6
6
  #
7
- #require 'active_record'
7
+ require 'activerecord'
8
+ require 'active_record/connection_adapters/postgresql_adapter'
8
9
  require 'geo_ruby'
9
10
  require 'postgis_adapter/common_spatial_adapter'
10
11
  require 'postgis_functions'
@@ -17,7 +18,7 @@ include GeoRuby::SimpleFeatures
17
18
  include SpatialAdapter
18
19
 
19
20
  module PostgisAdapter
20
- VERSION = '0.2.1'
21
+ VERSION = '0.2.2'
21
22
  end
22
23
 
23
24
  #tables to ignore in migration : relative to PostGIS management of geometric columns
@@ -250,7 +251,8 @@ SELECT * FROM geometry_columns WHERE f_table_name = '#{table_name}'
250
251
  end
251
252
 
252
253
  raw_geom_infos
253
-
254
+ rescue => e
255
+ nil
254
256
  end
255
257
 
256
258
  end
@@ -19,7 +19,7 @@ module PostgisFunctions
19
19
  # (it must be noted ST_OrderingEquals is a little more stringent than
20
20
  # simply verifying order of points are the same).
21
21
  #
22
- # This function will return false if either geometry is invalid even
22
+ # This function will return false if either geometry is invalid even
23
23
  # if they are binary equal.
24
24
  #
25
25
  # Returns Boolean ST_Equals(geometry A, geometry B);
@@ -74,9 +74,9 @@ module PostgisFunctions
74
74
  def centroid
75
75
  postgis_calculate(:centroid, self)
76
76
  end
77
-
77
+
78
78
  #
79
- # Returns the closure of the combinatorial boundary of this Geometry.
79
+ # Returns the closure of the combinatorial boundary of this Geometry.
80
80
  # The combinatorial boundary is defined as described in section 3.12.3.2 of the
81
81
  # OGC SPEC. Because the result of this function is a closure, and hence topologically
82
82
  # closed, the resulting boundary can be represented using representational
@@ -100,7 +100,7 @@ module PostgisFunctions
100
100
  def distance_to(other)
101
101
  postgis_calculate(:distance, [self, other]).to_f
102
102
  end
103
-
103
+
104
104
  #
105
105
  # True if geometry A is completely inside geometry B.
106
106
  #
@@ -136,11 +136,11 @@ module PostgisFunctions
136
136
  postgis_calculate(:dwithin, [self, other], margin)
137
137
  end
138
138
  alias_method "in_bounds?", "d_within?"
139
-
139
+
140
140
  #
141
- # True if geometry B is completely inside geometry A.
141
+ # True if geometry B is completely inside geometry A.
142
142
  #
143
- # For this function to make sense, the source geometries must both be of the same
143
+ # For this function to make sense, the source geometries must both be of the same
144
144
  # coordinate projection, having the same SRID. 'contains?' is the inverse of 'within?'.
145
145
  #
146
146
  # So a.contains?(b) is like b.within?(a) except in the case of invalid
@@ -156,7 +156,7 @@ module PostgisFunctions
156
156
  def contains? other
157
157
  postgis_calculate(:contains, [self, other])
158
158
  end
159
-
159
+
160
160
  #
161
161
  # True if no point in Geometry A is outside Geometry B
162
162
  #
@@ -177,7 +177,7 @@ module PostgisFunctions
177
177
  postgis_calculate(:coveredby, [self, other])
178
178
  end
179
179
  alias_method "inside?", "covered_by?"
180
-
180
+
181
181
  #
182
182
  # Eye-candy. See 'covered_by?'.
183
183
  #
@@ -230,8 +230,8 @@ module PostgisFunctions
230
230
  def simplify(tolerance=0.1)
231
231
  postgis_calculate(:simplify, self, tolerance)
232
232
  end
233
-
234
-
233
+
234
+
235
235
  def simplify!(tolerance=0.1)
236
236
  #FIXME: not good..
237
237
  self.update_attribute(get_column_name, simplify)
@@ -255,7 +255,7 @@ module PostgisFunctions
255
255
  #
256
256
  # True if Geometries "spatially intersect", share any portion of space.
257
257
  # False if they don't (they are Disjoint).
258
- #
258
+ #
259
259
  # 'overlaps?', 'touches?', 'within?' all imply spatial intersection.
260
260
  # If any of the aforementioned returns true, then the geometries also
261
261
  # spatially intersect. 'disjoint?' implies false for spatial intersection.
@@ -344,11 +344,11 @@ module PostgisFunctions
344
344
  def convex_hull
345
345
  postgis_calculate(:convexhull, self)
346
346
  end
347
-
347
+
348
348
  #
349
349
  # Creates an areal geometry formed by the constituent linework of given geometry.
350
- # The return type can be a Polygon or MultiPolygon, depending on input.
351
- # If the input lineworks do not form polygons NULL is returned. The inputs can
350
+ # The return type can be a Polygon or MultiPolygon, depending on input.
351
+ # If the input lineworks do not form polygons NULL is returned. The inputs can
352
352
  # be LINESTRINGS, MULTILINESTRINGS, POLYGONS, MULTIPOLYGONS, and GeometryCollections.
353
353
  #
354
354
  # Returns Boolean ST_BuildArea(geometry A);
@@ -356,7 +356,7 @@ module PostgisFunctions
356
356
  def build_area
357
357
  postgis_calculate(:buildarea, self)
358
358
  end
359
-
359
+
360
360
  #
361
361
  # Returns true if this Geometry has no anomalous geometric points, such as
362
362
  # self intersection or self tangency.
@@ -369,10 +369,10 @@ module PostgisFunctions
369
369
  alias_method "simple?", "is_simple?"
370
370
 
371
371
  #
372
- # Aggregate. Creates a GeometryCollection containing possible polygons formed
372
+ # Aggregate. Creates a GeometryCollection containing possible polygons formed
373
373
  # from the constituent linework of a set of geometries.
374
374
  #
375
- # Geometry Collections are often difficult to deal with with third party tools,
375
+ # Geometry Collections are often difficult to deal with with third party tools,
376
376
  # so use ST_Polygonize in conjunction with ST_Dump to dump the polygons out into
377
377
  # individual polygons.
378
378
  #
@@ -381,75 +381,86 @@ module PostgisFunctions
381
381
  def polygonize#(geom)
382
382
  postgis_calculate(:polygonize, self)
383
383
  end
384
-
384
+
385
385
  #
386
- # Returns true if this Geometry is spatially related to anotherGeometry,
387
- # by testing for intersections between the Interior, Boundary and Exterior
388
- # of the two geometries as specified by the values in the
389
- # intersectionPatternMatrix. If no intersectionPatternMatrix is passed in,
386
+ # Returns true if this Geometry is spatially related to anotherGeometry,
387
+ # by testing for intersections between the Interior, Boundary and Exterior
388
+ # of the two geometries as specified by the values in the
389
+ # intersectionPatternMatrix. If no intersectionPatternMatrix is passed in,
390
390
  # then returns the maximum intersectionPatternMatrix that relates the 2 geometries.
391
- #
392
- #
393
- # Version 1: Takes geomA, geomB, intersectionMatrix and Returns 1 (TRUE) if
394
- # this Geometry is spatially related to anotherGeometry, by testing for
395
- # intersections between the Interior, Boundary and Exterior of the two
391
+ #
392
+ #
393
+ # Version 1: Takes geomA, geomB, intersectionMatrix and Returns 1 (TRUE) if
394
+ # this Geometry is spatially related to anotherGeometry, by testing for
395
+ # intersections between the Interior, Boundary and Exterior of the two
396
396
  # geometries as specified by the values in the intersectionPatternMatrix.
397
- #
398
- # This is especially useful for testing compound checks of intersection,
397
+ #
398
+ # This is especially useful for testing compound checks of intersection,
399
399
  # crosses, etc in one step.
400
- #
400
+ #
401
401
  # Do not call with a GeometryCollection as an argument
402
- #
403
- # This is the "allowable" version that returns a boolean, not an integer.
402
+ #
403
+ # This is the "allowable" version that returns a boolean, not an integer.
404
404
  # This is defined in OGC spec.
405
- # This DOES NOT automagically include an index call. The reason for that
406
- # is some relationships are anti e.g. Disjoint. If you are using a relationship
405
+ # This DOES NOT automagically include an index call. The reason for that
406
+ # is some relationships are anti e.g. Disjoint. If you are using a relationship
407
407
  # pattern that requires intersection, then include the && index call.
408
- #
409
- # Version 2: Takes geomA and geomB and returns the DE-9IM
408
+ #
409
+ # Version 2: Takes geomA and geomB and returns the DE-9IM
410
410
  # (dimensionally extended nine-intersection matrix)
411
- #
411
+ #
412
412
  # Do not call with a GeometryCollection as an argument
413
413
  # Not in OGC spec, but implied. see s2.1.13.2
414
- #
414
+ #
415
415
  # Both Performed by the GEOS module
416
- #
416
+ #
417
417
  # Returns:
418
418
  #
419
- # text ST_Relate(geometry geomA, geometry geomB);
420
- # boolean ST_Relate(geometry geomA, geometry geomB, text intersectionPatternMatrix);
419
+ # String ST_Relate(geometry geomA, geometry geomB);
420
+ # Boolean ST_Relate(geometry geomA, geometry geomB, text intersectionPatternMatrix);
421
421
  #
422
422
  def relate?(other, m = nil)
423
423
  # Relate is case sentitive.......
424
424
  m = "'#{m}'" if m
425
425
  postgis_calculate("Relate", [self, other], m)
426
- end
426
+ end
427
427
 
428
- #
429
- # Transform the geometry into a different spatial reference system.
430
428
  #
431
- # Return geometry ST_Transform(geometry g1, integer srid);
432
- # Returns a new geometry with its coordinates transformed to spatial reference system referenced by the SRID integer parameter. The destination SRID must exist in the SPATIAL_REF_SYS table.
433
- # ST_Transform is often confused with ST_SetSRID(). ST_Transform actually changes the coordinates of a geometry from one spatial reference system to another, while ST_SetSRID() simply changes the SRID identifier of the geometry
434
- # Requires PostGIS be compiled with Proj support. Use PostGIS_Full_Version to confirm you have proj support compiled in.
435
- #
436
- # If using more than one transformation, it is useful to have a functional index on the commonly used transformations to take advantage of index usage.
429
+ # Transform the geometry into a different spatial reference system.
430
+ # The destination SRID must exist in the SPATIAL_REF_SYS table.
437
431
  #
438
- # Prior to 1.3.4, this function crashes if used with geometries that contain CURVES. This is fixed in 1.3.4+
439
432
  # This method implements the OpenGIS Simple Features Implementation Specification for SQL.
440
- # This method supports Circular Strings and Curves
433
+ # This method supports Circular Strings and Curves (PostGIS 1.3.4+)
434
+ #
435
+ # Requires PostGIS be compiled with Proj support.
436
+ #
437
+ # Return Geometry ST_Transform(geometry g1, integer srid);
441
438
  #
442
439
  def transform(new_srid)
443
440
  postgis_calculate("Transform", self, new_srid)
444
441
  end
445
-
442
+
443
+ # Return a modified geometry having no segment longer than the given distance. Distance computation is performed in 2d only.
444
+ # Synopsis
445
+
446
+ #geometry ST_Segmentize(geometry geomA, float max_length);
447
+ #Description
448
+
449
+ #Returns a modified geometry having no segment longer than the given distance. Distance computation is performed in 2d only.
450
+
451
+ #This will only increase segments. It will not lengthen segments shorter than max length
452
+
453
+ def segmentize(max_length=1.0)
454
+ postgis_calculate("segmentize", self, max_length)
455
+ end
456
+
446
457
  #
447
458
  # LINESTRING
448
459
  #
449
460
  #
450
461
  #
451
462
  module LineStringFunctions
452
-
463
+
453
464
  #
454
465
  # Returns the 2D length of the geometry if it is a linestring, multilinestring,
455
466
  # ST_Curve, ST_MultiCurve. 0 is returned for areal geometries. For areal geometries
@@ -548,12 +559,12 @@ module PostgisFunctions
548
559
  def locate_point point
549
560
  postgis_calculate(:line_locate_point, [self, point]).to_f
550
561
  end
551
-
562
+
552
563
  #
553
- # Return a derived geometry collection value with elements that match the
564
+ # Return a derived geometry collection value with elements that match the
554
565
  # specified measure. Polygonal elements are not supported.
555
566
  #
556
- # Semantic is specified by: ISO/IEC CD 13249-3:200x(E) - Text for
567
+ # Semantic is specified by: ISO/IEC CD 13249-3:200x(E) - Text for
557
568
  # Continuation CD Editing Meeting
558
569
  #
559
570
  # Returns geometry ST_Locate_Along_Measure(geometry ageom_with_measure, float a_measure);
@@ -561,9 +572,9 @@ module PostgisFunctions
561
572
  def locate_along_measure(measure)
562
573
  postgis_calculate(:locate_along_measure, self, measure)
563
574
  end
564
-
575
+
565
576
  #
566
- # Return a derived geometry collection value with elements that match the
577
+ # Return a derived geometry collection value with elements that match the
567
578
  # specified range of measures inclusively. Polygonal elements are not supported.
568
579
  #
569
580
  # Semantic is specified by: ISO/IEC CD 13249-3:200x(E) - Text for Continuation CD Editing Meeting
@@ -573,7 +584,7 @@ module PostgisFunctions
573
584
  def locate_between_measures(a, b)
574
585
  postgis_calculate(:locate_between_measures, self, [a,b])
575
586
  end
576
-
587
+
577
588
  #
578
589
  # Returns a point interpolated along a line. First argument must be a LINESTRING.
579
590
  # Second argument is a float8 between 0 and 1 representing fraction of total
@@ -603,7 +614,7 @@ module PostgisFunctions
603
614
  postgis_calculate(:line_substring, self, [s, e])
604
615
  end
605
616
 
606
- ###
617
+ ###
607
618
  #Not implemented in postgis yet
608
619
  # ST_max_distance Returns the largest distance between two line strings.
609
620
  #def max_distance other
@@ -699,7 +710,7 @@ module PostgisFunctions
699
710
  end
700
711
 
701
712
  end
702
-
713
+
703
714
  ###
704
715
  ##
705
716
  #
@@ -775,7 +786,7 @@ module PostgisFunctions
775
786
  end
776
787
 
777
788
  end
778
-
789
+
779
790
  end
780
791
 
781
792
  # NEW
@@ -40,7 +40,6 @@ module PostgisFunctions
40
40
  # Distance/DWithin/Length/Perimeter — in projected units.
41
41
  # DistanceSphere/Spheroid — in meters.
42
42
  #
43
- #
44
43
  def construct_geometric_sql(type,geoms,options)
45
44
 
46
45
  tables = geoms.map do |t| {
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{postgis_adapter}
5
- s.version = "0.2.1"
5
+ s.version = "0.2.2"
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-01-10}
9
+ s.date = %q{2009-01-12}
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"]
@@ -39,28 +39,28 @@ describe "Common Functions" do
39
39
  it { @p1.distance_spheroid_to(@p2).should be_close(627129.50,0.01) }
40
40
  it { @p1.distance_spheroid_to(@p2).should be_close(627129.502639041, 0.000001) }
41
41
  it { @p1.distance_spheroid_to(@p3).should be_close(1096324.48117672, 0.000001) }
42
-
42
+
43
43
  it { @p1.should_not be_inside(@c1) }
44
44
  it { @p1.should be_outside(@c1) }
45
45
  it { @p1.should be_inside_circle(2.0,2.0,20.0) }
46
46
  it { @p1.should_not be_inside_circle(50,50,2) }
47
47
  it { @p1.should be_in_bounds(@s1) }
48
48
  it { @p3.should_not be_in_bounds(@s1, 1) }
49
- it { @p4.in_bounds?(@s3, 0.01).should be_false }
50
-
49
+ it { @p4.in_bounds?(@s3, 0.01).should be_false }
50
+
51
51
  it { @p1.azimuth(@p2).should be_close(0.785398163397448,0.000001) }
52
52
  it { @p1.azimuth(@s2).should raise_error }
53
53
  it { @p1.disjoint?(@s2).should be_true }
54
54
  it { @p3.polygonize.geometries.should be_empty }
55
- it { @p4.where_on_line(@s3).should be_close(0.335, 0.0001) }
55
+ it { @p4.where_on_line(@s3).should be_close(0.335, 0.0001) }
56
56
  it { @s3.locate_point(@p4).should be_close(0.335, 0.1)}
57
57
  it { @s3.interpolate_point(0.335).x.should be_close(18.05, 0.01) }
58
-
58
+
59
59
  it { @p1.relate?(@s3, "T*T***FF*").should be_false }
60
60
  it { @p1.relate?(@s3).should eql("FF0FFF102") }
61
61
 
62
62
  it "should transform srid" do
63
- @p1.geom = @p1.transform(29101)
63
+ @p1.geom = @p1.transform(29101)
64
64
  @p1.geom.srid.should eql(29101)
65
65
  end
66
66
 
@@ -68,6 +68,10 @@ describe "Common Functions" do
68
68
  @p1.where_on_line(@s1).should eql(0.0)
69
69
  end
70
70
 
71
+ it "should see in what fraction of the ls it is" do
72
+ @p2.where_on_line(@s2).should be_close(0.3333, 0.1)
73
+ end
74
+
71
75
  end
72
76
 
73
77
  describe "Polygon" do
@@ -83,7 +87,7 @@ describe "Common Functions" do
83
87
  it "should find one city (first) that contains a point" do
84
88
  City.contain(@p4.geom, 4326).data.should eql("City1")
85
89
  end
86
-
90
+
87
91
  it { @c2.should be_closed }
88
92
  it { @c3.area.should be_close(1093.270089, 0.1) }
89
93
  it { @c2.area.should be_close(1159.5, 0.1) }
@@ -143,9 +147,13 @@ describe "Common Functions" do
143
147
  it { @c2.disjoint?(@p2).should be_true }
144
148
  it { @c3.polygonize.should have(2).geometries }
145
149
 
150
+ it "should acts as jack" do
151
+ @c2.segmentize(0.1).should be_instance_of(Polygon)
152
+ end
153
+
146
154
  # weird...
147
155
  # it do
148
- # @c1.disjoint?(@s2).should be_true
156
+ # @c1.disjoint?(@p2).should be_true
149
157
  # end
150
158
 
151
159
  end
@@ -241,7 +249,7 @@ describe "Common Functions" do
241
249
 
242
250
  it do @s1.locate_point(@p1).should eql(0.0) end
243
251
  it do @s1.locate_point(@p2).should eql(1.0) end
244
-
252
+
245
253
  it "should simplify a line" do
246
254
  @s3.simplify.points.length.should eql(2)
247
255
  end
@@ -258,7 +266,7 @@ describe "Common Functions" do
258
266
  it { @s1.overlaps?(@s2).should be_false }
259
267
  it { @s1.convex_hull.should be_instance_of(LineString) }
260
268
  it { @s1.line_substring(0.2,0.5).should be_instance_of(LineString) }
261
-
269
+
262
270
  it do
263
271
  @s1.interpolate_point(0.7).should be_instance_of(Point)
264
272
  @s1.interpolate_point(0.7).x.should be_close(1.7,0.1)
@@ -275,7 +283,10 @@ describe "Common Functions" do
275
283
  @s2.build_area.should be_nil
276
284
  end
277
285
 
286
+ it "should acts as jack" do
287
+ @s2.segmentize(0.1).should be_instance_of(LineString)
288
+ end
289
+
278
290
  end
279
291
 
280
292
  end
281
-
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.2.1
4
+ version: 0.2.2
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-01-10 00:00:00 -08:00
12
+ date: 2009-01-12 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency