[postgis-tickets] [PostGIS] #2825: ST_Intersection broken with Z coordinates

PostGIS trac at osgeo.org
Mon Jul 7 14:56:14 PDT 2014


#2825: ST_Intersection broken with Z coordinates
----------------------------+-----------------------------------------------
  Reporter:  TBL            |       Owner:  robe         
      Type:  defect         |      Status:  new          
  Priority:  medium         |   Milestone:  PostGIS 2.1.4
 Component:  documentation  |     Version:  2.1.x        
Resolution:                 |    Keywords:               
----------------------------+-----------------------------------------------

Comment(by robe):

 I think this is sorta already resulting in expected behavior if you have
 sfcgal support.

 Just for example:


 {{{
 set postgis.backend = sfcgal;
 with linestring as (
   select st_makeline(
     (select
 st_setsrid(st_makeline(st_makepoint((a-400)/20.0,(a-400)/20.0,a)),4326)
 from generate_series(0,800) as a),
     (select
 st_setsrid(st_makeline(st_makepoint(-(a-1200)/20.0,-(a-1200)/20.0,a)),4326)
 from generate_series(801,1600) as a)
   ) as geom
 ),
 polygon as (select ST_GeomFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))',
 4326) as geom)
 select st_astext(st_intersection(linestring.geom, polygon.geom)) from
 linestring, polygon

 }}}

 output is 2D as many people would expect from a 2D function:


 {{{
 MULTILINESTRING((0.05 0.05,0 0),(0.1 0.1,0.05 0.05),(0.15 0.15,0.1
 0.1),(0.2 0.2,0.15 0.15),(0.25 0.25,0.2 0.2),(0.3 0.3,0.25 0.25),(0.35
 0.35,0.3 0.3),(0.4 0.4,0.35 0.35),(0.45 0.45,0.4 0.4),(0.5 0.5,0.45
 0.45),(0.55 0.55,0.5 0.5),(0.6 0.6,0.55 0.55),(0.65 0.65,0.6 0.6),(0.7
 0.7,0.65 0.65),(0.75 0.75,0.7 0.7),(0.8 0.8,0.75 0.75),(0.85 0.85,0.8
 0.8),(0.9 0.9,0.85 0.85),(0.95 0.95,0.9 0.9),(1 1,0.95 0.95))

 }}}


 now if I use the ST_3DIntersection


 {{{
 set postgis.backend=sfcgal
 with linestring as (
   select st_makeline(
     (select
 st_setsrid(st_makeline(st_makepoint((a-400)/20.0,(a-400)/20.0,a)),4326)
 from generate_series(0,800) as a),
     (select
 st_setsrid(st_makeline(st_makepoint(-(a-1200)/20.0,-(a-1200)/20.0,a)),4326)
 from generate_series(801,1600) as a)
   ) as geom
 ),
 polygon as (select ST_GeomFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))',
 4326) as geom)
 select st_astext(st_3dintersection(linestring.geom, polygon.geom)),
 ST_3DIntersects(linestring.geom, polygon.geom) from linestring, polygon
 }}}

 I get


 {{{
        st_astext         | st_3dintersects
 -------------------------+-----------------
 GEOMETRYCOLLECTION EMPTY | f
 }}}

 I tried swapping out change

 set postgis.backend = geos;

 and both the built in native ST_3DIntersects agrees that these don't
 intersect.

 Now if I take a slightly modified that should intersect it does


 {{{
 with linestring as (
   select st_makeline(
     st_geomfromtext('LINESTRING Z (-1 -1 0,-0.5 -0.5 1,0 0 2,0.5 0.5 3,1 1
 4,1.5 1.5 5)', 4326),
     st_geomfromtext('LINESTRING Z (2 2 6,1.5 1.5 7,1 1 8,0.5 0.5 8,0 0
 10)', 4326)
   ) as geom
 ),
 polygon as (select ST_GeomFromText('POLYGON((0 0 8, 0 1 8, 1 1 8, 1 0 8, 0
 0 8))', 4326) as geom)
 select st_astext(st_3dintersection(linestring.geom, polygon.geom)) from
 linestring, polygon;
 }}}

 -- output is --
 {{{
 LINESTRING Z (1 1 8,0.5 0.5 8)
 }}}

-- 
Ticket URL: <http://trac.osgeo.org/postgis/ticket/2825#comment:12>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list