[postgis-users] strange query with linestring in one point

Sandro Santilli strk at keybit.net
Thu Sep 29 07:11:50 PDT 2011


On Thu, Sep 29, 2011 at 01:22:11PM +0200, Szymon Guz wrote:
> On 29 September 2011 11:37, Sandro Santilli <strk at keybit.net> wrote:
> 
> > On Thu, Sep 29, 2011 at 11:29:51AM +0200, Szymon Guz wrote:
> > > On 29 September 2011 11:20, Sandro Santilli <strk at keybit.net> wrote:
> > > > On Thu, Sep 29, 2011 at 11:14:52AM +0200, Szymon Guz wrote:
> > > > >
> > > > > this works OK, returns something:
> > > > >
> > > > > SELECT ... FROM ... WHERE
> > > > > st_intersects(
> > > > >   geometry,
> > > > >   st_geomfromtext('POINT(3 50)', 4326)
> > > > > );
> > > > >
> > > > > but this returns nothing:
> > > > >
> > > > > SELECT ... FROM ... WHERE
> > > > > st_intersects(
> > > > >   geometry,
> > > > >   st_geomfromtext('POINT(3 50, 3 50 )', 4326)
> > > > > );
> > > >
> > > > The second should raise an exception due to malformed WKT being used.
> > > > Doesn't it ?
> > >
> > > The second raises exception only if there is exactly one point. When
> > there
> > > are more points it works OK:
> > >
> > > SELECT st_geomfromtext('LINESTRING(3  50)', 4326)
> > > ERROR:  geometry requires more points
> > > HINT:  "LINESTRING(3  50)" <-- parse error at position 17 within geometry
> > >
> > > SELECT st_astext(st_geomfromtext('LINESTRING(3 50, 3 50)', 4326))
> > >
> > > 'LINESTRING(3 50,3 50)'
> >
> > Yes, but you wrote 'POINT(3 50, 3 50)' in your first mail :)
> >
> > Anyway, you're now saying that while POINT(3 50) is reported
> > to intersect something, LINESTRING(3 50, 3 50) isn't. Correct ?
> > Can you provide literal data showing this discrepance ?
> > That is, a query where both operands are in WKT form ?
> >
> > --strk;
> >
> 
> Oh yes, sorry, I meant 'LINESTRING( 3 50, 3 50)' :)
> 
> I managed to replicate the error like this:

...

> 
> CREATE TABLE g2(geometry geometry);
> 
> insert into g2(geometry)
> SELECT ST_Buffer(
>  ST_GeomFromText('POINT(3  50)', 4326),
>  50, 'quad_segs=8'
> );

// TRUE:
select st_intersects(geometry, st_centroid(geometry)) from g2;

// FALSE:
select st_intersects(geometry,
	st_makeline(
		st_centroid(geometry),
		st_centroid(geometry)
	)) from g2;

// TRUE:
select st_intersects(geometry,
	st_makeline(
		st_centroid(geometry),
		st_translate(st_centroid(geometry), 1e-6, 0)
	)) from g2;

Interesting. This is against GEOS 3.3.1.
True, the linestring is invalid, but doesn't give wrong answer when
compared to a point.

ST_MakeValid will fix that line for you, turning into a point.

--strk;

  ()   Free GIS & Flash consultant/developer
  /\   http://strk.keybit.net/services.html



More information about the postgis-users mailing list