PostGIS Geography Type

54 views
Skip to first unread message

TsenYing

unread,
Feb 16, 2010, 12:15:03 PM2/16/10
to georuby
Does anyone know if georuby supports the PostGIS Geography Type?
If not what is the best approach for simple operations like getting
points within a given distance (with ST_DWithin) and points within a
bounding box.

My data set spans the globe.
From the Postgis documentation, the Geography type basis is the
sphere, whereas the Geometry type basis is the plane. So it seems like
I should be useing the Geography type; or does distance calculations
come 'close enough' with the Geometry type even over the global scale?

Daniel Cohen

unread,
Feb 16, 2010, 12:37:30 PM2/16/10
to geo...@googlegroups.com
Hi there-

I'm not terribly familiar with the Geography Type. I have just read a bit about it, and it appears to be a newer data type. GeoRuby supports these data types:

Point
Line string
Linear ring
Polygon
Multi point
Multi line string
Multi polygon
Geometry collection

So, you might need to do some type of raw spatial sql query to your Geography type, to pull it out of your spatial database in one of the above formats. You can use ActiveRecord's find_by_sql method to pass sql directly to your database. If the geometry stored in the Geography type is a point for example, you can pull out the x and y values from the databse, and contruct a new Point in GeoRuby. 

As for running simple spatial queries, I have a simply plugin you can try that simply extends ActiveRecord's find method to include the use of the spatial methods like so:

# find all records who's geom contains the given geometry
Property.find(:all, :contain => 'POINT(-71.488049 41.791564)')

# find the first record who's geom overlaps with the given geometry
Property.find(:first, :overlap => 'POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1 ))')

# find the last matching record who's geom intersects with the given geometry
Property.find(:last, :intersect => 'LINESTRING (0 2, 4 2)')


Good luck!
Daniel



--
You received this message because you are subscribed to the Google Groups "georuby" group.
To post to this group, send email to geo...@googlegroups.com.
To unsubscribe from this group, send email to georuby+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/georuby?hl=en.


TsenYing

unread,
Feb 17, 2010, 12:22:13 PM2/17/10
to georuby
Thanks for the pointers.
I'll try using the Geometry type for now, if necessary I'll try your
idea of pulling out x,y values from Geography type and constructing
Points.
Looks like some interesting ideas on your site BTW.

On Feb 16, 10:37 am, Daniel Cohen <daniel.michael.co...@gmail.com>
wrote:

> DanielOn Tue, Feb 16, 2010 at 12:15 PM, TsenYing <tseny...@gmail.com> wrote:
> > Does anyone know if georuby supports the PostGIS Geography Type?
> > If not what is the best approach for simple operations like getting
> > points within a given distance (with ST_DWithin) and points within a
> > bounding box.
>
> > My data set spans the globe.
> > From the Postgis  documentation, the Geography type basis is the
> > sphere, whereas the Geometry type basis is the plane. So it seems like
> > I should be useing the Geography type; or does distance calculations
> > come 'close enough' with the Geometry type even over the global scale?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "georuby" group.
> > To post to this group, send email to geo...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > georuby+u...@googlegroups.com<georuby%2Bunsu...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages