Question

i am using postgresql version : "PostgreSQL 9.3.1 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2), 64-bit"

i have created 2 tables A and B with point and polygon as a data type. now i want to know whether point is inside the polygon or not. for this i am trying to use ST_Intersect(A.point_LatLong , B.polygon_abc); my query is :

SELECT A.id 
FROM A, B 
WHERE A.name = 'callifornia' 
AND ST_Intersect(A.point_LatLong , B.polygon_abc); 

here point_latLong and polygon_abc are column name having datatype point and polygon in table A and B.

but this query gives an error :

ERROR: function st_intersect(point, polygon) does not exist
LINE 3: WHERE city.city_name = 'callifornia' AND ST_intersect(city.c...
HINT: No function matches the given name and argument types. You might need to add
explicit type casts.


How can I solve this problem? I even not be able to use any other spatial method in postgresql like st_contains() etc let me know if you have any solution.

Was it helpful?

Solution

You are trying to mix PostgreSQL's built-in (limited, but useful) geometric types with PostGIS functions. It sounds like you didn't install PostGIS, either. You've also typo'd the function name, it's ST_Intersects not ST_Intersect.

First, if you want to use PostGIS, make sure it's installed and then:

CREATE EXTENSION postgis;

Next, you'll probably find that you can't actually call ST_Intersects with a point and a polygon. PostGIS works with its own geometry type. It has some converters for the PostgreSQL internal types, but they're only limited. So calling PostGIS functions with primitive geometric types can result in errors like:

postgres=# SELECT ST_Intersects( polygon( box(point(0,0), point(10,10)) ), point(5,5) );
ERROR:  function st_intersects(polygon, point) does not exist
LINE 1: SELECT ST_Intersects( polygon( box(point(0,0), point(10,10))...
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

You'll often have to convert them to PostGIS's own geometry type. PostGIS provides some explicit casts for this for most types, e.g.:

postgres=# SELECT ST_Intersects(
    polygon( box(point(0,0), point(10,10)) )::geometry,
    point(5,5)::geometry 
);
 st_intersects 
---------------
 t
(1 row)

So in your query, that'd be:

ST_Intersects(A.point_LatLong::geometry , B.polygon_abc::geometry);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top