[postgis-users] Existance of a point on an edge

Simon Greener simon at spatialdbadvisor.com
Fri Apr 10 19:11:32 PDT 2009


> From a multilinestring (road path  which is an edge) how can I find whether a
> particular point exist?
> Both the point and the road paths are in geometry format. I need to find in
> which edge, a particular point exists(e.g. current user position).

Is this like what you are after?

drop table roadcl;
create table roadcl ( 
  gid serial );
SELECT AddGeometryColumn('public', 'roadcl', 'geom', 28355, 'LINESTRING', 2);

insert into roadcl (geom)
select geom
from (select ST_SetSRID(ST_GeomFromText('LINESTRING( 1 0, 1 5, 1 11 )'),28355) as geom
      union all
      select ST_SetSRID(ST_GeomFromText('LINESTRING( 10 0, 10 5, 10 11 )'),28355) as geom
      union all
      select ST_SetSRID(ST_GeomFromText('LINESTRING( 0 1, 5 1, 11 1 )'),28355) as geom
      union all
      select ST_SetSRID(ST_GeomFromText('LINESTRING( 0 10, 5 10, 11 10 )'),28355) as geom) as g;

drop table mypoint;
create table mypoint ( 
  gid serial );
SELECT AddGeometryColumn('public', 'mypoint', 'geom', 28355, 'POINT', 2);

insert into mypoint (geom)
values (ST_SetSRID(ST_GeomFromText('POINT(1 5)'),28355)),
       (ST_SetSRID(ST_GeomFromText('POINT(1 11)'),28355)),
       (ST_SetSRID(ST_GeomFromText('POINT(1 0)'),28355)),
       (ST_SetSRID(ST_GeomFromText('POINT(10 5)'),28355)),
       (ST_SetSRID(ST_GeomFromText('POINT(10 11)'),28355)),
       (ST_SetSRID(ST_GeomFromText('POINT(10 0)'),28355)),
       (ST_SetSRID(ST_GeomFromText('POINT(5 1)'),28355)),
       (ST_SetSRID(ST_GeomFromText('POINT(11 1)'),28355)),
       (ST_SetSRID(ST_GeomFromText('POINT(0 1)'),28355)),
       (ST_SetSRID(ST_GeomFromText('POINT(5 10)'),28355)),
       (ST_SetSRID(ST_GeomFromText('POINT(11 10)'),28355)),
       (ST_SetSRID(ST_GeomFromText('POINT(0 10)'),28355));

select t1.gid, t2.gid
  from mypoint t1,
       roadcl t2
 where ST_Contains(t2.geom,t1.geom);
  
regards
Simon
-- 
SpatialDB Advice and Design, Solutions Architecture and Programming,
Oracle Database 10g Administrator Certified Associate; Oracle Database 10g SQL Certified Professional
Oracle Spatial, SQL Server, PostGIS, MySQL, ArcSDE, Manifold GIS, FME, Radius Topology and Studio Specialist.
39 Cliff View Drive, Allens Rivulet, 7150, Tasmania, Australia.
Website: www.spatialdbadvisor.com
  Email: simon at spatialdbadvisor.com
  Voice: +613 9016 3910
Mobile: +61 418 396391
Skype: sggreener
Longitude: 147.20515 (147° 12' 18" E)
Latitude: -43.01530 (43° 00' 55" S)
NAC:W80CK 7SWP3



More information about the postgis-users mailing list