Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

CREATE TABLE test_geog (
    id SERIAL PRIMARY KEY,
    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

1 Answer 1

up vote 4 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)')), 
          Geometry(boundary)
       )
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

 
discard

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.