problem with saving Polygon type

52 views
Skip to first unread message

Xin

unread,
Nov 30, 2007, 5:25:12 AM11/30/07
to georuby
Hi Everyone,

I am having problems saving a GeoRuby Polygon type in Rails. The
strange thing is everything appears to save correctly until I refresh
the object.

I have geom field set to Polygon. For each object, I am converting lat/
lon locations stored in Float to a Polygon type.

I know I have a saving problem from performing the following in Rails
console:

1. o = Model.find(id)
2. o.convert_points_to_polygon
3. o.geom
=> #<GeoRuby::SimpleFeatures::Polygon:0x20ef5cc @with_z=false,
@srid=-1, @with_m=false, @rings=[#<GeoRuby::SimpleFeatures::LinearRing:
0x20ef4c8 @with_z=false, @points=[#<GeoRuby::SimpleFeatures::Point:
0x20efba8 @m=0.0, @with_z=false, @z=0.0, @srid=-1, @y=12.2287,
@with_m=false, @x=32.8954>, #<GeoRuby::SimpleFeatures::Point:0x20efa04
@m=0.0, @with_z=false, @z=0.0, @srid=-1, @y=12.26, @with_m=false,
@x=32.8954>, #<GeoRuby::SimpleFeatures::Point:0x20ef860 @m=0.0,
@with_z=false, @z=0.0, @srid=-1, @y=12.26, @with_m=false, @x=32.8565>,
#<GeoRuby::SimpleFeatures::Point:0x20ef6bc @m=0.0, @with_z=false,
@z=0.0, @srid=-1, @y=12.2287, @with_m=false, @x=32.8565>], @srid=-1,
@with_m=false>]>
4. o.save
=> true
5. o.geom
=> #<GeoRuby::SimpleFeatures::Polygon:0x20d0604 @with_z=false,
@srid=-1, @with_m=false, @rings=[#<GeoRuby::SimpleFeatures::LinearRing:
0x20d0500 @with_z=false, @points=[#<GeoRuby::SimpleFeatures::Point:
0x20d0be0 @m=0.0, @with_z=false, @z=0.0, @srid=-1, @y=12.2287,
@with_m=false, @x=32.8954>, #<GeoRuby::SimpleFeatures::Point:0x20d0a3c
@m=0.0, @with_z=false, @z=0.0, @srid=-1, @y=12.26, @with_m=false,
@x=32.8954>, #<GeoRuby::SimpleFeatures::Point:0x20d0898 @m=0.0,
@with_z=false, @z=0.0, @srid=-1, @y=12.26, @with_m=false, @x=32.8565>,
#<GeoRuby::SimpleFeatures::Point:0x20d06f4 @m=0.0, @with_z=false,
@z=0.0, @srid=-1, @y=12.2287, @with_m=false, @x=32.8565>], @srid=-1,
@with_m=false>]>
5. o.reload
=> #<Object id: 1, port_id: 26051, ..other fields... geom: nil>

The database confirms that the Polygon geom field was not saved.

Out of 135 records, it did however manage to save 6 of them. Each
object has 4 points to be converted to a Polygon. I'm not sure why a
few are working whilst others are not.

My setup:
Mac OS X Leopard
Using native Ruby/Rails
Darwin MySQL 5.0.38
Fink's MySQL Server
I'm using InnoDB and latin1_swedish_ci

I am stumped here. Any help is greatly appreciated.

I am going to install Fink's version of Ruby/Rails and see if it makes
a difference.

Regards,
Xin

Xin

unread,
Nov 30, 2007, 5:28:05 AM11/30/07
to georuby
Oh, I am using Rails 2.0 PR1(maybe PR2). 1.99.0

Xin

unread,
Nov 30, 2007, 5:35:01 AM11/30/07
to georuby
The method convert_points_to_polygon is defined like this:

def convert_points_to_polygon
[north, west, south, east].each do |coor|
return false unless coor
end

nw = Point.from_x_y(north, west)
ne = Point.from_x_y(north, east)
se = Point.from_x_y(south, east)
sw = Point.from_x_y(south, west)

self.geom = Polygon.from_points([[nw, ne, se, sw]])
true
end

paron

unread,
Nov 30, 2007, 6:42:13 AM11/30/07
to georuby
> The method convert_points_to_polygon is defined like this:
>
> def convert_points_to_polygon
> [north, west, south, east].each do |coor|
> return false unless coor
> end
>
> nw = Point.from_x_y(north, west)
> ne = Point.from_x_y(north, east)
> se = Point.from_x_y(south, east)
> sw = Point.from_x_y(south, west)
>
> self.geom = Polygon.from_points([[nw, ne, se, sw]])
> true
> end
>
That doesn't seem to do what one might hope. It might be better
defined as "convert_points_to_bounding_box"
Reply all
Reply to author
Forward
0 new messages