[FeatureServer] GeoAlchemy, what is the trick?

Gery . gamejihou at hotmail.com
Wed Dec 5 03:22:56 PST 2012



Thanks a lot Michel, it worked like a charm. Now I'm getting the whole table as GeoJSON. However I have a doubt about the querying option, for example:

/fs/boreholes?format=GeoJSON&source__ilike=ODP&queryable=source ---> this source_ilike comes from Ext JS, and should give only the rows in source column with "odp".
/fs/boreholes?format=GeoJSON&queryable=source&source=ODP
 ---> this should work as above with FeatureServer but it gives this:
An error occurred: string indices must be integers, not str
  File "/var/www/html/mop/fs/web_request/handlers.py", line 230, in cgi
    accepts = accepts )
  File "/var/www/html/mop/fs/FeatureServer/Server.py", line 245, in dispatchRequest
    result = method(action)
  File "/var/www/html/mop/fs/FeatureServer/DataSource/GeoAlchemy.py", line 160, in select
    for k, v in action.attributes.iteritems()]


{'source': 'ODP', 'queryable': 'source', 'format': 'GeoJSON'}
Because I'm using Ext JS to do the search (search button), I'd like this form: /fs/boreholes?format=GeoJSON&source__ilike=ODP&queryable=source, could it be possible to adapt this in FeatureServer?

Thanks again,

Gery

PS: this is the error coming from the Ext JS example above:
An error occurred: 'str' object has no attribute 'query_action_types'
  File "/var/www/html/mop/fs/web_request/handlers.py", line 230, in cgi
    accepts = accepts )
  File "/var/www/html/mop/fs/FeatureServer/Server.py", line 207, in dispatchRequest
    request.parse(params, path_info, host, post_data, request_method)
  File "/var/www/html/mop/fs/FeatureServer/Service/GeoJSON.py", line 44, in parse
    Request.parse(self, params, path_info, host, post_data, request_method, format_obj=g)
  File "/var/www/html/mop/fs/FeatureServer/Service/Request.py", line 70, in parse
    action = self.get_select_action(path_info, params)
  File "/var/www/html/mop/fs/FeatureServer/Service/Request.py", line 145, in get_select_action
    if type in ds.query_action_types:


{'source__ilike': 'ODP', 'queryable': 'source', 'format': 'GeoJSON'}

__________________________________________________________________________________________
Piensa en el medio ambiente - mantenlo en la pantalla. NO lo imprimas si NO es necesario.
Think green - keep it on the screen. Do NOT print if it is NOT necessary.
Denken Sie an die Umwelt - bewahren Sie es auf dem Bildschirm. Drucken Sie NICHT, wenn es NICHT notwendig ist.


Subject: Re: [FeatureServer] GeoAlchemy, what is the trick?
From: iocast at me.com
Date: Wed, 5 Dec 2012 08:34:15 +0100
CC: featureserver at lists.osgeo.org
To: gamejihou at hotmail.com

Hi Gery
In the test files I found an example and tried to adapt it:
The config entry I changed as follow:************************[boreholes]type=GeoAlchemydburi=postgresql://<user>:<password>@localhost:5432/mapmodel=model.boreholes_modelcls=Boreholesfid=idgeometry=geom************************where the model is a subdirectory of the featureserver root directory and boreholes_model is a file called boreholes_model.py. I also added a __init__.py file in the model folder to be sure that it is recognised as a Python package.cls is the class name of your model, so it should be Boreholes.
You could also look at the 'Road' example in the folder testsDataSource.GeoAlchemy.txt andgeoalchemy_model.py for the model declaration
Hopefully it would helpMichel



On Dec 5, 2012, at 8:00 AM, Iocast <iocast at me.com> wrote:Hi Gery
I never tried/changed the GeoAlchemy data source, however I'm going to try your setup and have a look if I get the same error.
Cheers,Michel

I get this error recently, I'm not sure why, someone has an idea? thanks

An error occurred: 'NoneType' object has no attribute 'items'
  File "/var/www/html/mop/fs/web_request/handlers.py", line 236, in cgi
    for (key, value) in returned_data[2].items():


{}



On Dec 4, 2012, at 10:31 AM, Gery . <gamejihou at hotmail.com> wrote:Hello,

I'm using GeoAlchemy with FeatureServer, but I'm new using both, so sorry for the very simple questions. This is my model (boreholes.model) for one of my PostGis tables:

*****************************
print "Content-type: text/html\n\n";

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.dialects.postgresql import *
from geoalchemy import *
from geoalchemy.postgis import *

engine = create_engine('postgresql://postgres:pass@localhost:5432/map', echo=False)
metadata = MetaData(engine)

session = sessionmaker(bind=engine)()

boreholes_table = Table('boreholes_point_wgs84', metadata,
                        Column('id', SMALLINT, primary_key=True),
                        Column('fid', SMALLINT),
                        Column('longitude', DOUBLE_PRECISION),
                        Column('latitude', DOUBLE_PRECISION),
                        Column('w_depth_m', DOUBLE_PRECISION),
                        Column('station', VARCHAR(150)),
                        Column('type', VARCHAR(150)),
                        Column('survey', VARCHAR(150)),
                        Column('source', VARCHAR(150)),
                        Column('max_pen_m', VARCHAR(150)),
                        Column('core_rec_m', VARCHAR(150)),
                        Column('t_g_ckm1', VARCHAR(150)),
                        Column('h_f_mwm2', VARCHAR(150)),
                        Column('comments', TEXT),
                        GeometryExtensionColumn('geom', Geometry(3)))

class Boreholes(object):
    def __init__ (self, id, fid, longitude, latitude, w_depth_m, station, type, survey, source, max_pen_m, core_rec_m, t_g_ckm1, h_f_mwm2, comments):
        self.id = id
        self.fid = fid
        self.longitude = longitude
        self.latitude = latitude
        self.w_depth_m = w_depth_m
        self.station = station
        self.type = type
        self.survey = survey
        self.source = source
        self.max_pen_m = max_pen_m
        self.core_rec_m = core_rec_m
        self.t_g_ckm1 = t_g_ckm1
        self.h_f_mwm2 = h_f_mwm2
        self.comments = comments

mapper(Boreholes, boreholes_table,
       properties={
                 'geom': GeometryColumn(boreholes_table.c.geom,
                                        comparator=PGComparator)
                  })

GeometryDDL(boreholes_table)

*****************************

and this is what I have in my featureserver.cfg:

*****************************
[boreholes]
type=GeoAlchemy
dburi=postgresql://postgres:pass@localhost:5432/map
model=../model/boreholes.model
cls=boreholes_point_wgs84
fid=id
geometry=geom
*****************************

so what I want is to query this table and output that in GeoJSON format. I'm doing the query in OpenLayers using GeoExt like this:

*****************************
var searchformPanel = new GeoExt.form.FormPanel(
        {
            width: 250,
            bodyStyle: 'padding:5px',
            labelAlign: 'top',
            defaults:
            {
                anchor: '100%'
            },
            protocol: new OpenLayers.Protocol.HTTP(
            {
                url: 'http://www.mop.org/fs/boreholes?format=GeoJSON',
                format: new OpenLayers.Format.GeoJSON(
                {
                    ignoreExtraDims: true,
                    'internalProjection': new OpenLayers.Projection("EPSG:900913"),
                    'externalProjection': new OpenLayers.Projection("EPSG:4326")
                }
                )
            }
            ),
            items:
            [
            {
                xtype: 'textfield',
                name: 'station__like',
                fieldLabel: 'Enter a word',
                allowBlank: false
            }
            ],
...
...
*****************************

by the way, this PostGis table is served by MarServer as WMS, but I think this has nothing to do with the query. So, to do this query I'm sure I need something else related to GeoAlchemy and featureserver itself but not sure what it is, I'd be grateful for some support on this, thanks in advance for any help.

Best regards,

Gery
 
__________________________________________________________________________________________
Piensa en el medio ambiente - mantenlo en la pantalla. NO lo imprimas si NO es necesario.
Think green - keep it on the screen. Do NOT print if it is NOT necessary.
Denken Sie an die Umwelt - bewahren Sie es auf dem Bildschirm. Drucken Sie NICHT, wenn es NICHT notwendig ist.
_______________________________________________
FeatureServer mailing list
FeatureServer at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/featureserver

_______________________________________________
FeatureServer mailing list
FeatureServer at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/featureserver

 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/featureserver/attachments/20121205/81d1915d/attachment-0001.html>


More information about the FeatureServer mailing list