Opened 15 years ago

Closed 15 years ago

#263 closed defect (fixed)

Casting from geography to geometry Huh?

Reported by: robe Owned by: pramsey
Priority: medium Milestone: PostGIS 1.5.0
Component: postgis Version:
Keywords: Cc:

Description

I can't figure out what is wrong here but this suggests something is wrong with our casting from geography to geometry:

SELECT ST_AsEWKT(geometry(geography(pt.the_geom))) As wkt,
	ST_Covers(
		ST_Transform(poly.the_geom,32611), 
		ST_Transform(pt.the_geom,32611)) As utm,
	ST_Covers(
		poly.the_geom, 
		pt.the_geom)
	 As pca,
	ST_Covers(geometry(geography(poly.the_geom)),
		geometry(geography(pt.the_geom))) As gm_to_gg_gm_pca
	
FROM (SELECT ST_GeomFromEWKT('SRID=4326;POLYGON((-119.5434 34.9438,-119.5437 34.9445,-119.5452 34.9442,-119.5434 34.9438))') As the_geom) 
	As poly
    CROSS JOIN 
	(VALUES
		( ST_GeomFromEWKT('SRID=4326;POINT(-119.5434 34.9438)') ) ,
		( ST_GeomFromEWKT('SRID=4326;POINT(-119.5452 34.9442)') ) ,
		( ST_GeomFromEWKT('SRID=4326;POINT(-119.5434 34.9438)') ),
		( ST_GeomFromEWKT('SRID=4326;POINT(-119.5438 34.9443)')  )
	)
	As pt(the_geom);

Results in:

                wkt                 | utm | pca | gm_to_gg_gm_pca
------------------------------------+-----+-----+-----------------
 SRID=4326;POINT(-119.5434 34.9438) | t   | t   | f
 SRID=4326;POINT(-119.5452 34.9442) | t   | t   | f
 SRID=4326;POINT(-119.5434 34.9438) | t   | t   | f
 SRID=4326;POINT(-119.5438 34.9443) | t   | t   | f

Shouldn't pca and gm_to_gg_gm_pca yield the same answer. How do I lose my covers by converting back to geometry. Inquiring minds want to know.

Change History (3)

comment:1 by robe, 15 years ago

I thought this may be a rounding issue, but my polygon astext rep in both cases seems the same. Strangely converting geometry→geography→geometry→geography maintains ST_covers (also tried with an ST_DWithin super small margin).

But geometry→geography→geometry ST_Intersects — my boundary point no longer intersects.

SELECT ST_AsText(geometry(geography(poly.the_geom))) As wkt,
	ST_AsText(geography(poly.the_geom)) As wkt_geog,
ST_Intersects(geometry(geography(poly.the_geom)), ST_GeomFromText('POINT(-119.5434 34.9438)',4326) ) As convintpt,
ST_Covers(geography(geometry(geography(poly.the_geom) ) ), geography(geometry(ST_GeographyFromText('SRID=4326;POINT(-119.5434 34.9438)')))) As cov,
	ST_Intersects(poly.the_geom, ST_GeomFromText('POINT(-119.5434 34.9438)',4326) ) As pintpt
	
FROM (SELECT ST_GeomFromEWKT('SRID=4326;POLYGON((-119.5434 34.9438,-119.5437 34.9445,-119.5452 34.9442,-119.5434 34.9438))') As the_geom) 
	As poly;

Yields:

                                        wkt
    |                                      wkt_geog
         | convintpt | cov | pintpt
--------------------------------------------------------------------------------
----+---------------------------------------------------------------------------
---------+-----------+-----+--------
 POLYGON((-119.5434 34.9438,-119.5437 34.9445,-119.5452 34.9442,-119.5434 34.943
8)) | POLYGON((-119.5434 34.9438,-119.5437 34.9445,-119.5452 34.9442,-119.5434 3
4.9438)) | f         | t   | t

comment:2 by robe, 15 years ago

Its a bounding box bug. Observe. I knew that ST_DropBBOx would come in handy some day :).

SELECT ST_AsEWKT(geometry(geography(pt.the_geom))) As wkt,
	ST_Covers(
		ST_Transform(poly.the_geom,32611), 
		ST_Transform(pt.the_geom,32611)) As utm,
	ST_Covers(
		poly.the_geom, 
		pt.the_geom)
	 As pca,
	_ST_Covers(ST_DropBBOX(geometry(geography(poly.the_geom))),
		ST_DropBBOx(geometry(geography(pt.the_geom)))) As gm_to_gg_gm_pca
	
FROM (SELECT ST_GeomFromEWKT('SRID=4326;POLYGON((-119.5434 34.9438,-119.5437 34.9445,-119.5452 34.9442,-119.5434 34.9438))') As the_geom) 
	As poly
    CROSS JOIN 
	(VALUES
		( ST_GeomFromEWKT('SRID=4326;POINT(-119.5434 34.9438)') ) ,
		( ST_GeomFromEWKT('SRID=4326;POINT(-119.5452 34.9442)') ) ,
		( ST_GeomFromEWKT('SRID=4326;POINT(-119.5434 34.9438)') ),
		( ST_GeomFromEWKT('SRID=4326;POINT(-119.5438 34.9443)')  )
	)
	As pt(the_geom);


Results in:

               wkt                 | utm | pca | gm_to_gg_gm_pca
-----------------------------------+-----+-----+-----------------
SRID=4326;POINT(-119.5434 34.9438) | t   | t   | t
SRID=4326;POINT(-119.5452 34.9442) | t   | t   | t
SRID=4326;POINT(-119.5434 34.9438) | t   | t   | t
SRID=4326;POINT(-119.5438 34.9443) | t   | t   | t

comment:3 by pramsey, 15 years ago

Resolution: fixed
Status: newclosed

Great sleuthing. Fixed at r4640

Note: See TracTickets for help on using tickets.