St_within problem

View: New views
13 Messages — Rating Filter:   Alert me  

St_within problem

by Bob Pawley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hi
 
I have a table consisting of 858 points which spatially covers a geometry.
 
I want to pick out the points that are spatially within that geometry.
 
I am using the following but it returns a null (empty?) value.

 select st_astext(graphics.point_grid.the_geom)
 from graphics.point_grid, library.dgm_process
 where library.dgm_process.process_number = '1'
 and st_within(graphics.point_grid.the_geom, library.dgm_process.the_geom);
 
Any thoughts would be appreciated.
 
Bob

_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: St_within problem

by Maxime van Noppen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bob Pawley wrote:
>  select st_astext(graphics.point_grid.the_geom)
>  from graphics.point_grid, library.dgm_process
>  where library.dgm_process.process_number = '1'
>  and st_within(graphics.point_grid.the_geom, library.dgm_process.the_geom);
>  
> Any thoughts would be appreciated.

Hi,

From the documentation here :

http://postgis.refractions.net/documentation/manual-1.4/ST_Within.html

> boolean ST_Within(geometry A, geometry B);
> Returns TRUE if geometry A is completely inside geometry B.

I suggest that you just swap the arguments of the ST_Within function as
 a geometry will never be "completly inside" a point.

--
Maxime
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: St_within problem

by Bob Pawley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have tried it with the point and  geometry reversed with the same result.

Perhaps, I am not looking at this the right way.

According to the manual

st_within Returns TRUE if geometry A  (points) is completely inside geometry
B ( geometry).

If it scans the list of 858 points some of those points are within the
geometry - unless Postgis is looking at the 858 points as one entity.

Bob




----- Original Message -----
From: "Maxime van Noppen" <maxime@...>
To: "PostGIS Users Discussion" <postgis-users@...>
Sent: Monday, October 19, 2009 8:50 AM
Subject: Re: [postgis-users] St_within problem


> Bob Pawley wrote:
>>  select st_astext(graphics.point_grid.the_geom)
>>  from graphics.point_grid, library.dgm_process
>>  where library.dgm_process.process_number = '1'
>>  and st_within(graphics.point_grid.the_geom,
>> library.dgm_process.the_geom);
>>
>> Any thoughts would be appreciated.
>
> Hi,
>
> From the documentation here :
>
> http://postgis.refractions.net/documentation/manual-1.4/ST_Within.html
>
>> boolean ST_Within(geometry A, geometry B);
>> Returns TRUE if geometry A is completely inside geometry B.
>
> I suggest that you just swap the arguments of the ST_Within function as
> a geometry will never be "completly inside" a point.
>
> --
> Maxime
> _______________________________________________
> postgis-users mailing list
> postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users 

_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: St_within problem

by Maxime van Noppen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bob Pawley wrote:

> I have tried it with the point and  geometry reversed with the same result.
>
> Perhaps, I am not looking at this the right way.
>
> According to the manual
>
> st_within Returns TRUE if geometry A  (points) is completely inside
> geometry B ( geometry).
>
> If it scans the list of 858 points some of those points are within the
> geometry - unless Postgis is looking at the 858 points as one entity.

Ooops, sorry, indeed you were right and used the function the right way. :)

Could you provide an example of a geometry & some points you're using ?

You might also try ST_Intersects or ST_Covers.

--
Maxime
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: St_within problem

by Bob Pawley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Funny this does work when I include st_box2d as in -

st_within( graphics.point_grid.the_geom,
st_box2d(library.dgm_process.the_geom))

However, this will include points within the box yet outside of the actual
geometry.

Bob

----- Original Message -----
From: "Maxime van Noppen" <maxime@...>
To: "PostGIS Users Discussion" <postgis-users@...>
Sent: Monday, October 19, 2009 9:16 AM
Subject: Re: [postgis-users] St_within problem


> Bob Pawley wrote:
>> I have tried it with the point and  geometry reversed with the same
>> result.
>>
>> Perhaps, I am not looking at this the right way.
>>
>> According to the manual
>>
>> st_within Returns TRUE if geometry A  (points) is completely inside
>> geometry B ( geometry).
>>
>> If it scans the list of 858 points some of those points are within the
>> geometry - unless Postgis is looking at the 858 points as one entity.
>
> Ooops, sorry, indeed you were right and used the function the right way.
> :)
>
> Could you provide an example of a geometry & some points you're using ?
>
> You might also try ST_Intersects or ST_Covers.
>
> --
> Maxime
> _______________________________________________
> postgis-users mailing list
> postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users 

_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: St_within problem

by Maxime van Noppen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bob Pawley wrote:
> Funny this does work when I include st_box2d as in -
>
> st_within( graphics.point_grid.the_geom,
> st_box2d(library.dgm_process.the_geom))
>
> However, this will include points within the box yet outside of the
> actual geometry.

It's hard to help without some additionnal data. Did you check that your
geometry is valid (ST_IsValid) ? Did you manually check that it actually
contains points ?

--
Maxime
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: St_within problem

by Bob Pawley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The geometry comes up true for st_isvalid and yes the points are covering
the geometry and beyond.

I'm curious as to how I could retrieve the geometry in order to include them
in an e-mail.

As a shapefile perhaps??

Bob



----- Original Message -----
From: "Maxime van Noppen" <maxime@...>
To: "PostGIS Users Discussion" <postgis-users@...>
Sent: Monday, October 19, 2009 9:55 AM
Subject: Re: [postgis-users] St_within problem


> Bob Pawley wrote:
>> Funny this does work when I include st_box2d as in -
>>
>> st_within( graphics.point_grid.the_geom,
>> st_box2d(library.dgm_process.the_geom))
>>
>> However, this will include points within the box yet outside of the
>> actual geometry.
>
> It's hard to help without some additionnal data. Did you check that your
> geometry is valid (ST_IsValid) ? Did you manually check that it actually
> contains points ?
>
> --
> Maxime
> _______________________________________________
> postgis-users mailing list
> postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users 

_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: St_within problem

by Michael Smedberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You can use the astext function to get the WKT ("well known text".)
E.g. you could do something like:

SELECT astext(the_geom) FROM library.dgm_process

which would return a textual representation of the geometries.
ST_GeomFromText is the opposite of astext- it'll convert the text to a
geometry object.

-----Original Message-----
From: postgis-users-bounces@...
[mailto:postgis-users-bounces@...] On Behalf Of Bob
Pawley
Sent: Tuesday, October 20, 2009 8:09 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] St_within problem

The geometry comes up true for st_isvalid and yes the points are
covering
the geometry and beyond.

I'm curious as to how I could retrieve the geometry in order to include
them
in an e-mail.

As a shapefile perhaps??

Bob



----- Original Message -----
From: "Maxime van Noppen" <maxime@...>
To: "PostGIS Users Discussion" <postgis-users@...>
Sent: Monday, October 19, 2009 9:55 AM
Subject: Re: [postgis-users] St_within problem


> Bob Pawley wrote:
>> Funny this does work when I include st_box2d as in -
>>
>> st_within( graphics.point_grid.the_geom,
>> st_box2d(library.dgm_process.the_geom))
>>
>> However, this will include points within the box yet outside of the
>> actual geometry.
>
> It's hard to help without some additionnal data. Did you check that
your
> geometry is valid (ST_IsValid) ? Did you manually check that it
actually
> contains points ?
>
> --
> Maxime
> _______________________________________________
> postgis-users mailing list
> postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users 

_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: St_within problem

by Bob Pawley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Even with astext the geomery is so complex the text can not be deciphered
as shown in the Output pane.

And pgadmin doesn't have a copy feature (as far as I know).

Bob
----- Original Message -----
From: "Michael Smedberg" <Michael.Smedberg@...>
To: "PostGIS Users Discussion" <postgis-users@...>
Sent: Tuesday, October 20, 2009 8:29 AM
Subject: Re: [postgis-users] St_within problem


> You can use the astext function to get the WKT ("well known text".)
> E.g. you could do something like:
>
> SELECT astext(the_geom) FROM library.dgm_process
>
> which would return a textual representation of the geometries.
> ST_GeomFromText is the opposite of astext- it'll convert the text to a
> geometry object.
>
> -----Original Message-----
> From: postgis-users-bounces@...
> [mailto:postgis-users-bounces@...] On Behalf Of Bob
> Pawley
> Sent: Tuesday, October 20, 2009 8:09 AM
> To: PostGIS Users Discussion
> Subject: Re: [postgis-users] St_within problem
>
> The geometry comes up true for st_isvalid and yes the points are
> covering
> the geometry and beyond.
>
> I'm curious as to how I could retrieve the geometry in order to include
> them
> in an e-mail.
>
> As a shapefile perhaps??
>
> Bob
>
>
>
> ----- Original Message -----
> From: "Maxime van Noppen" <maxime@...>
> To: "PostGIS Users Discussion" <postgis-users@...>
> Sent: Monday, October 19, 2009 9:55 AM
> Subject: Re: [postgis-users] St_within problem
>
>
>> Bob Pawley wrote:
>>> Funny this does work when I include st_box2d as in -
>>>
>>> st_within( graphics.point_grid.the_geom,
>>> st_box2d(library.dgm_process.the_geom))
>>>
>>> However, this will include points within the box yet outside of the
>>> actual geometry.
>>
>> It's hard to help without some additionnal data. Did you check that
> your
>> geometry is valid (ST_IsValid) ? Did you manually check that it
> actually
>> contains points ?
>>
>> --
>> Maxime
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users@...
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
> _______________________________________________
> postgis-users mailing list
> postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
> _______________________________________________
> postgis-users mailing list
> postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users 

_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: St_within problem

by Michael Smedberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If you use the psql (command line) client, you can use the \o command to
direct output to a text file.  That way, you can capture very large text
blocks.

Documentation on psql is available at
http://www.postgresql.org/docs/8.3/static/app-psql.html

-----Original Message-----
From: postgis-users-bounces@...
[mailto:postgis-users-bounces@...] On Behalf Of Bob
Pawley
Sent: Tuesday, October 20, 2009 9:11 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] St_within problem

Even with astext the geomery is so complex the text can not be
deciphered
as shown in the Output pane.

And pgadmin doesn't have a copy feature (as far as I know).

Bob
----- Original Message -----
From: "Michael Smedberg" <Michael.Smedberg@...>
To: "PostGIS Users Discussion" <postgis-users@...>
Sent: Tuesday, October 20, 2009 8:29 AM
Subject: Re: [postgis-users] St_within problem


> You can use the astext function to get the WKT ("well known text".)
> E.g. you could do something like:
>
> SELECT astext(the_geom) FROM library.dgm_process
>
> which would return a textual representation of the geometries.
> ST_GeomFromText is the opposite of astext- it'll convert the text to a
> geometry object.
>
> -----Original Message-----
> From: postgis-users-bounces@...
> [mailto:postgis-users-bounces@...] On Behalf Of
Bob

> Pawley
> Sent: Tuesday, October 20, 2009 8:09 AM
> To: PostGIS Users Discussion
> Subject: Re: [postgis-users] St_within problem
>
> The geometry comes up true for st_isvalid and yes the points are
> covering
> the geometry and beyond.
>
> I'm curious as to how I could retrieve the geometry in order to
include

> them
> in an e-mail.
>
> As a shapefile perhaps??
>
> Bob
>
>
>
> ----- Original Message -----
> From: "Maxime van Noppen" <maxime@...>
> To: "PostGIS Users Discussion" <postgis-users@...>
> Sent: Monday, October 19, 2009 9:55 AM
> Subject: Re: [postgis-users] St_within problem
>
>
>> Bob Pawley wrote:
>>> Funny this does work when I include st_box2d as in -
>>>
>>> st_within( graphics.point_grid.the_geom,
>>> st_box2d(library.dgm_process.the_geom))
>>>
>>> However, this will include points within the box yet outside of the
>>> actual geometry.
>>
>> It's hard to help without some additionnal data. Did you check that
> your
>> geometry is valid (ST_IsValid) ? Did you manually check that it
> actually
>> contains points ?
>>
>> --
>> Maxime
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users@...
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
> _______________________________________________
> postgis-users mailing list
> postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
> _______________________________________________
> postgis-users mailing list
> postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users 

_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: St_within problem

by Sufficool, Stanley-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Use save results to file in pgadmin. It's the icon with arrow by the
floppy.

> -----Original Message-----
> From: postgis-users-bounces@...
> [mailto:postgis-users-bounces@...] On
> Behalf Of Bob Pawley
> Sent: Tuesday, October 20, 2009 9:11 AM
> To: PostGIS Users Discussion
> Subject: Re: [postgis-users] St_within problem
>
>
> Even with astext the geomery is so complex the text can not
> be deciphered
> as shown in the Output pane.
>
> And pgadmin doesn't have a copy feature (as far as I know).
>
> Bob
> ----- Original Message -----
> From: "Michael Smedberg" <Michael.Smedberg@...>
> To: "PostGIS Users Discussion" <postgis-users@...>
> Sent: Tuesday, October 20, 2009 8:29 AM
> Subject: Re: [postgis-users] St_within problem
>
>
> > You can use the astext function to get the WKT ("well known text".)
> > E.g. you could do something like:
> >
> > SELECT astext(the_geom) FROM library.dgm_process
> >
> > which would return a textual representation of the geometries.
> > ST_GeomFromText is the opposite of astext- it'll convert
> the text to a
> > geometry object.
> >
> > -----Original Message-----
> > From: postgis-users-bounces@...
> > [mailto:postgis-users-bounces@...] On Behalf Of
> > Bob Pawley
> > Sent: Tuesday, October 20, 2009 8:09 AM
> > To: PostGIS Users Discussion
> > Subject: Re: [postgis-users] St_within problem
> >
> > The geometry comes up true for st_isvalid and yes the points are
> > covering the geometry and beyond.
> >
> > I'm curious as to how I could retrieve the geometry in order to
> > include them in an e-mail.
> >
> > As a shapefile perhaps??
> >
> > Bob
> >
> >
> >
> > ----- Original Message -----
> > From: "Maxime van Noppen" <maxime@...>
> > To: "PostGIS Users Discussion"
> <postgis-users@...>
> > Sent: Monday, October 19, 2009 9:55 AM
> > Subject: Re: [postgis-users] St_within problem
> >
> >
> >> Bob Pawley wrote:
> >>> Funny this does work when I include st_box2d as in -
> >>>
> >>> st_within( graphics.point_grid.the_geom,
> >>> st_box2d(library.dgm_process.the_geom))
> >>>
> >>> However, this will include points within the box yet
> outside of the
> >>> actual geometry.
> >>
> >> It's hard to help without some additionnal data. Did you check that
> > your
> >> geometry is valid (ST_IsValid) ? Did you manually check that it
> > actually
> >> contains points ?
> >>
> >> --
> >> Maxime
> >> _______________________________________________
> >> postgis-users mailing list
> >> postgis-users@...
> >> http://postgis.refractions.net/mailman/listinfo/postgis-users
> >
> > _______________________________________________
> > postgis-users mailing list postgis-users@...
> > http://postgis.refractions.net/mailman/listinfo/postgis-users
> >
> > _______________________________________________
> > postgis-users mailing list postgis-users@...
> > http://postgis.refractions.net/mailman/listinfo/postgis-users 
>
> _______________________________________________
> postgis-users mailing list postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: St_within problem

by Maxime van Noppen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Michael Smedberg wrote:
> You can use the astext function to get the WKT ("well known text".)
> E.g. you could do something like:
>
> SELECT astext(the_geom) FROM library.dgm_process
>
> which would return a textual representation of the geometries.
> ST_GeomFromText is the opposite of astext- it'll convert the text to a
> geometry object.

I suggest the use of the binary WKB format to avoid precision quirks
that might occur with WKT.

SELECT ST_AsBinary(the_geom) FROM ...;

--
Maxime
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: St_within problem

by Maxime van Noppen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bob Pawley wrote:
> The geometry comes up true for st_isvalid and yes the points are
> covering the geometry and beyond.

Did you try with other functions like ST_Intersecs or ST_Covers ?

--
Maxime
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users