[FeatureServer] GeoAlchemy, what is the trick?

Iocast iocast at me.com
Mon Dec 10 06:11:15 PST 2012


Hi Gery

Thanks a lot for testing FS.

I uploaded a new version including the discussed bug fixes (http://featureserver.org/download.html#r1.15.1) and created a new tag on GitHub (https://github.com/iocast/featureserver/tree/1.15.1).

Cheers,
Michel



On Dec 10, 2012, at 12:53 PM, Gery . <gamejihou at hotmail.com> wrote:

> Hi Michel,
> 
> now it works, thanks ;). I'll keep testing FS with GeoAlchemy and will contact you again if have more questions,
> 
> Cheers,
> 
> 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.
> 
> 
> From: iocast at me.com
> Subject: Re: [FeatureServer] GeoAlchemy, what is the trick?
> Date: Fri, 7 Dec 2012 10:54:27 +0100
> To: gamejihou at hotmail.com
> 
> Hi Gery
> 
> I have changed some lines and it should now be solved … at least on my mac :)
> 
> Replace the files
> FeatureServer/Service/Request.py
> FeatureServer/DataSource/GeoAlchemy.py
> with the attached files.
> 
> 
> 
> 
> Please let me know if it works
> Michel
> 
> 
> 
> On Dec 6, 2012, at 11:22 PM, Gery . <gamejihou at hotmail.com> wrote:
> 
> 
> cool, thanks a lot Michel,
> 
> 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.
> 
> 
> From: iocast at me.com
> Subject: Re: [FeatureServer] GeoAlchemy, what is the trick?
> Date: Thu, 6 Dec 2012 15:28:57 +0100
> To: gamejihou at hotmail.com
> 
> Okey, I see � then I need to setup a test env to find the bug. It would take some time.
> 
> I will give you a feedback as soon as i found the solution.
> 
> thanks
> Michel
> 
> 
> 
> 
> On Dec 6, 2012, at 2:06 PM, Gery . <gamejihou at hotmail.com> wrote:
> 
> Hi Michel,
> 
> Thanks for the file, I used it but still I'm getting kind of the same error, this is it:
> 
> -- 1 --
> /fs/boreholes?format=GeoJSON&queryable=source&source=ODP
> 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'}
> -- 2 --
> /fs/boreholes?format=GeoJSON&source__ilike=ODP&queryable=source
> 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 149, in get_select_action
>     type, ",".join(ds.query_action_types) or "None"))
> 
> 
> {'source__ilike': 'ODP', 'queryable': 'source', 'format': 'GeoJSON'}
> 
> in the --1--, I understand that the "string indices must be integers, not str" means that an array index must be integer (string is an array of characters), like this:
> >>> s
> 'abcd12345'
> >>> s[1]
> 'b'
> >>> s['1']
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: string indices must be integers, not str
> 
> so I'm thinking that this error could be related to the GeoJSON format itself (perhaps the quotes??), this is the first record of my table as GeoJSON:
> {"crs": null, "type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [-7.99, -8.99]}, "type": "Feature", "id": 1, "properties": {"h_f_mwm2": "No information available", "core_rec_m": "No information available", "t_g_ckm1": "8.5", "w_depth_m": -19.0, "longitude": -7.99, "source": "RO", "station": "Delfin 20", "survey": "Delfin 20", "comments": "The borehole was drilled.", "fid": 1, "max_pen_m": "26", "latitude": -8.99, "type": "dust"}}, {"geometry": {"type": "Point", "coordinates": ...
> 
> in the --2--, I'm not sure what is the error: 'str' object has no attribute 'query_action_types'
> 
> Cheers,
> 
> 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.
> 
> 
> From: iocast at me.com
> Subject: Re: [FeatureServer] GeoAlchemy, what is the trick?
> Date: Thu, 6 Dec 2012 09:24:34 +0100
> To: gamejihou at hotmail.com
> 
> Hi Gery
> 
> As I can read in the source, your ilike example should work.
> 
> could you try this fix. Replace the file Request.py in the folder FeatureServer/Service/
> 
> 
> Hopefully it works
> 
> Thanks for testing
> Michel
> 
> 
> 
> On Dec 5, 2012, at 12:22 PM, Gery . <gamejihou at hotmail.com> wrote:
> 
> 
> 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=GeoAlchemy
> dburi=postgresql://<user>:<password>@localhost:5432/map
> model=model.boreholes_model
> cls=Boreholes
> fid=id
> geometry=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 tests
> DataSource.GeoAlchemy.txt and
> geoalchemy_model.py for the model declaration
> 
> Hopefully it would help
> Michel
> 
> 
> 
> 
> 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/20121210/5559ba34/attachment-0001.html>


More information about the FeatureServer mailing list