Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following table defined, which uses PostGIS geography.

CREATE TABLE test_geog (
    boundary GEOGRAPHY(Polygon)

I added the following test polygon to the table:

INSERT INTO test_geog VALUES (ST_GeographyFromText('SRID=4326;POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'));

I am trying to determine whether a point lies within any of the polygons in this table. I have this query:

SELECT ST_ContainsProperly(ST_GeographyFromText('Point(2 2)'), area)
FROM (SELECT boundary FROM test_geog) AS area;

This yields the following error:

ERROR:  function st_containsproperly(geography, record) does not exist
LINE 1: SELECT ST_ContainsProperly(ST_GeographyFromText('Point(2 2)'...
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

How do I convert this "record" into a POLYGON? I'm confused because it seems like the column has already been declared to only hold POLYGON types, but for some reason that is not what I am pulling out of the database.

I attempted to cast the record to a POLYGON like this:

SELECT ST_ContainsProperly(ST_GeographyFromText('Point(2 2)'), CAST (nitf_area AS POLYGON))
FROM (SELECT boundary FROM source_imagery) AS nitf_area;

But that gives me this error:

ERROR:  cannot cast type record to polygon
LINE 1: ...tainsProperly(ST_GeographyFromText('Point(2 2)'), CAST (nitf...

What am I not understanding here?

share|improve this question
up vote 5 down vote accepted

Do you need the sub-select? And I think ST_ContainsProperly only works with Geometry, not Geography.

SELECT ST_ContainsProperly(
          Geometry(ST_GeographyFromText('Point(2 2)')), 
FROM test_geog;
share|improve this answer
Ah, yes you are right about all of that. ST_ContainsProperly only works for Geometry, so I switched to using ST_Covers instead, which does what I want. I wanted to avoid casting to Geometry if it's not necessary. Here is the code I ended up with that works: SELECT ST_Covers(boundary, ST_GeographyFromText('Point(2 2)')) FROM source_imagery – Steph Jun 22 '11 at 22:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.