Answer the question
In order to leave comments, you need to log in
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
)
)
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
)
)
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question