queryByAttributes...

Paul james pauljame at GMAIL.COM
Tue Apr 12 12:24:02 PDT 2005


Thx Sean, thats worked...

Just one more question... The user will select a point in map, so I
get a x,y in pixel, transform to geo ... Now, how can I compare it
with the_geom ? Is it any postgis function to it?


On Apr 12, 2005 3:48 PM, Sean Gillies <sgillies at frii.com> wrote:
> On Apr 12, 2005, at 12:07 PM, Paul james wrote:
>
> > Thank you Sean... I thoung '1' means sucess ...
> >
> > so, my queryByAttributes() is always returning 1 (Failure)... I dont
> > know why... I think is problem with any parameter...
> >
> > string value = "'[state]' = 'test'";
> > layer.queryByAttributes(mp,"state", value, 0)
> >
> > I have a state column in my table :  > state varchar
> > And I have a 'test' line as well ... And the 'test' point is in my
> > extents mp ...
> > so, any other idea?
> >
> > thank you...
> >
> > On Apr 12, 2005 2:45 PM, Sean Gillies <sgillies at frii.com> wrote:
> >> On Apr 12, 2005, at 11:17 AM, Paul james wrote:
> >>
> >>> I=B4m with problems using queryByAttributes... getResult(0) always
> >>> return n=
> >>> ull...
> >>> any idea?
> >>> ps.: using c#
> >>>
> >>> thx
> >>>
> >>> =20
> >>>
> >>> layer =3D mp.getLayerByName("layer");
> >>> string value =3D "'[oid]' =3D '32141'";
> >>> if ((layer.queryByAttributes(mp,"oid", value, 0))=3D=3D1)
> >>> {
> >>>       resultCacheMemberObj result =3D new resultCacheMemberObj();
> >>>       result =3Dlayer.getResult(0);
> >>> }
> >>>
> >>>
> >>
> >> Is it just me, or is the listserv mangling this (and other) emails?
> >>
> >> I'm assuming you are using MapServer 4.4.  First, of all, you should
> >> generally compare integer results from mapscript to
> >> mapscript.MS_SUCCESS (0) and mapscript.MS_FAILURE (1).  Second, I
> >> think
> >> you really should be doing something like this:
> >>
> >>     layerObj layer = mp.getLayerByName("layer");
> >>     ...
> >>     layer.queryByAttributes(...);
> >>     resultCacheObj results = layer.getResults();
> >>     if (results)
> >>     {
> >>         resultCacheMemberObj result = results.getResult(0);
> >>     }
> >>
> >> Keep in mind that the extents of your 'mp' map are used to filter
> >> results.  If you query by attributes for a feature outside the map
> >> extents, it will not be found.
> >>
> >> cheers,
> >> Sean
> >>
>
> 1 is just a number :)  MapServer follows an old C convention for
> success and failure.
>
> I overlooked that you have a PostGIS layer.  The qstring parameter of
> queryByAttributes becomes, during the query, the layer's filter.  You
> can't use a mapserver logical expression for a postgis layer filter.
> You must use a snippet of SQL instead, like this:
>
>     string qstring = "state = 'test'";
>     layer.queryByAttributes(mp, "state", qstring, 0);
>
> the qstring is turned into an SQL clause: "WHERE state = 'test'".  So
> that's the crux of it, use your layer's specific filter syntax in
> queryByAttributes.
>
> cheers,
> Sean
>
> --
> Sean Gillies
> sgillies at frii dot com
> http://users.frii.com/sgillies
>



More information about the MapServer-users mailing list