E
E
EVOSandru62017-01-04 08:11:14
PostgreSQL
EVOSandru6, 2017-01-04 08:11:14

How to find all records in posgis where the geocoordinate is contained within the specified polygon?

Good afternoon,
I need to get objects that are in the screen area on the map.
The extreme coordinates of the corners are known. In the database, the coordinate of the object ( field gis_centroid ) is of the geography
type. Tried with 2 options:

select *
            FROM m_waypoints
            where 
              ST_Within( 
               gis_centroid, 
                ST_GeometryFromText(
                  'POLYGON((43.284500434723 76.93922996521, 43.293825032866 76.93922996521, 43.293825032866 76.965687274933, 43.284500434723 76.965687274933, 43.284500434723 76.93922996521))', 4326
                )
            )

I catch: ERROR: function st_within(geography, geometry) does not exist
select *
            FROM m_waypoints
            where 
              ST_Within( 
                ST_GeometryFromText(gis_centroid), 
                ST_GeometryFromText(
                  'POLYGON((43.284500434723 76.93922996521, 43.293825032866 76.93922996521, 43.293825032866 76.965687274933, 43.284500434723 76.965687274933, 43.284500434723 76.93922996521))', 4326
                )
            )

I'm catching :
ERROR: function st_geometryfromtext(geography) does not exis
I don't understand - why convert the point type if there is no data for the input. You just need to find all the objects in the polygon.
Please help with a request.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2017-01-04
@Nipheris

ST_Within seems to only work with the geometry type. You probably need to cast gis_centroid to geometry by adding '::geometry' to it, but I'm not sure if an index would work. You need to think about why you have a geographic type stored if you need to work with it as a geometry (and you need it that way, since you have a map).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question