passing url to my model to do a query

10 views
Skip to first unread message

Gery Herbozo

unread,
Dec 19, 2012, 5:28:29 PM12/19/12
to geoal...@googlegroups.com
Hello,

this is something I've been thinking about but not sure if it's
possible. I've been testing FeatureServer with GeoAlchemy to make some
queries and so far things have worked great. Now I'm trying to query a
tsvector column in this way, but FS doesn't have this option so far.
So I was wondering if it's possible to use the same and normal queries
and ulr (ie. queryable and eq, lt, like, etc, etc), and those values
(ie. tsvector column and searched value) put them as a GA query in my
model.py, so in that way I can retrieve those features. For instance:

****
url (queryable and ilike are understood by FS)
****
http://www.web.web/fs/Boreholes?format=GeoJSON&ts__ilike=yabadabadu&queryable=ts
(SQL translation: "select * from boreholes_table where ts ilike '%yabadabadu%';)
("ts__ilike=yabadabadu&queryable=ts" is understood by FS, but using
"ts" as column is not possible because the error in postgresql:
tsvector ~~* unknown)

*************************
expected SQL query
*************************
session.query(Boreholes).filter(Boreholes.ts.op('@@')(func.plainto_tsquery("yabadabadu"))).all()
(this works well as query in mymodel.py)

***************
mymodel.py
***************
#
# importing stuff - geoalchemy for postgis in declarative way
#
from sqlalchemy import *
from ... etc

#
# db connection.
#
etc...

#
# open a bound session on db
#
session = sessionmaker(bind=engine)()

#
# define tsvector class
#
class TsVector(types.UserDefinedType):
def get_col_spec(self):
return 'TSVECTOR'

#
# define classes
#
class Boreholes(Base):
__tablename__ = 'boreholes_table'
id = Column(SMALLINT, primary_key=True)
fid = Column(SMALLINT)
comments = Column(TEXT)
ts = Column(TsVector)
geom = GeometryColumn(Point(3))

#
# enable DDL extension, which allows CREATE/DROP operations to work
correctly. this is not needed if working with externally defined
tables.
#
GeometryDDL(Boreholes.__table__)


so I was thinking about something that could be written in mymodel.py
to "translate" the url to get the expected SQL query above. I'd
appreciate any hint on this, thanks in advance,

Best regards,

Gery

Eric Lemoine

unread,
Dec 20, 2012, 4:51:51 PM12/20/12
to geoal...@googlegroups.com
I think you'd need to to extend FeatureServer's GeoAlchemy data
source, so the feature_predicate can work with a new operator_name.
See <https://github.com/iocast/featureserver/blob/master/FeatureServer/DataSource/GeoAlchemy.py#L58>.
You might be able to just subclass GeoAlchemy.py - I'm not sure if
FeatureServer allows you to "plug" your own class in.

Good luck,

--
Eric
Reply all
Reply to author
Forward
0 new messages