GIS support?

30 views
Skip to first unread message

Roy Wright

unread,
Sep 4, 2009, 3:49:24 PM9/4/09
to DataMapper
Howdy,

I'm looking at doing a PostGIS db application and have been
unsuccessful at finding any mention of dm and gis. Something like the
spatial adapter for Rails (ActiveRecord) http://github.com/fragility/spatial_adapter/tree/master
.
Anyone seen anything like this?

TIA,
Roy


Dan Kubb (dkubb)

unread,
Sep 11, 2009, 1:40:27 PM9/11/09
to DataMapper
Hi Roy,

> I'm looking at doing a PostGIS db application and have been  
> unsuccessful at finding any mention of dm and gis.  Something like the  
> spatial adapter for Rails (ActiveRecord)http://github.com/fragility/spatial_adapter/tree/master
> .
> Anyone seen anything like this?

Does dm-geokit do what you need? There's a few forks on github, but
I'm not sure which one is the "official" one, but it looks like Matt
King's is the one with the most recent development:

http://github.com/mattking17/dm-geokit

--

Dan Kubb
(dkubb)

Matt King

unread,
Sep 11, 2009, 1:44:26 PM9/11/09
to datam...@googlegroups.com
On Sep 11, 2009, at 10:40 AM, Dan Kubb (dkubb) wrote:

> Does dm-geokit do what you need? There's a few forks on github, but
> I'm not sure which one is the "official" one, but it looks like Matt
> King's is the one with the most recent development:
>
> http://github.com/mattking17/dm-geokit

No, it doesn't do any PostGIS stuff, and for that matter it's not
ready to use for anything quite yet :-)

Will post to the list when it's ready to go though...

-Matt

Roy Wright

unread,
Sep 11, 2009, 4:20:45 PM9/11/09
to datam...@googlegroups.com

Thank you.

What I'm looking to do is use the geometry functions to find items
(points, linestrings, polygons) within a boundary (polygon). Also
will need to be able to transform dissimilar reference systems to a
common datum before doing the searches.

I've started to look into doing a postgis adapter and have a couple of
questions.

First, postgis adds a geometry column using SELECT AddGeometryColumn,
example:

SELECT AddGeometryColumn ('hello','poi','poi_geom',-1,'POINT',2);

To extend datamapper's property would mean monkey patching
Migrations. Would it be better to create a separate method instead?
For example instead of:

property :geom, Geometry, :type => Point2d, :srid => 1234, :index =>
true

do something like:

geometry :geom, Point2d, :srid => 1234

Best practices recommend indexing geometries, so would it be kosher to
have "geometry" method default to index => true? Or would it be less
confusing to keep "property"'s default of index => false?

Finally, postgis adds several dozen SQL functions. What's the best
way to present these spatial functions? Here's an example query to
find any points within 3km of a coastline:

# this example is from section 1.3.2 of "PostGIS in Action"
# http://www.manning.com/obe/PostGIS_MEAPCH01.pdf
SELECT p.poi_name, round(CAST(ST_Distance(p.poi_geom, c.line_geom) /
1000 As numeric),2) As dist_km
FROM hello.poi As p
INNER JOIN hello.coastline As c ON ST_DWithin(c.line_geom, p.poi_geom,
1000*3);

I haven't been able to visualize what the datamapper syntax should be
for a complex query like this. About the best that I can see is to
get the points within. I don't see how to calculate the dist_km.

class Coastline
include DataMapper::Resource
property :id, Serial
geometry :line_geom, Linestring
end

class Poi
include DataMapper::Resource
property :id, Serial
property :name, String
geometry :geom, Point2d
end

points_within_3km = Poi.all(:spatial_within => [Coastline, :line_geom,
1000*3])

Open for any ideas.

TIA,
Roy

Reply all
Reply to author
Forward
0 new messages