Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9169555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:53:44+00:00 2026-06-17T15:53:44+00:00

I have a query: (This query uses geographical implementation of ST_Covers function) SELECT ST_Covers(ST_GeoGraphyFromText(‘MULTIPOLYGON(((179

  • 0

I have a query: (This query uses geographical implementation of ST_Covers function)

SELECT ST_Covers(ST_GeoGraphyFromText('MULTIPOLYGON(((179 -89,179 89,-179 89,-179 -89,179 -89)))'),ST_GeographyFromText('POINT(20 30)'));

When I run this query it should return true but it returns false. I don’t know whats wrong with PostGIS (or with this query)

and when i changes geographical implementation with geometrical one, and rearrange the query to be like below:

SELECT ST_Covers(ST_ASTEXT(ST_GeoGraphyFromText('MULTIPOLYGON(((179 -89,179 89,-179 89,-179 -89,179 -89)))')),text('POINT(20 30)'));

it works as it should, returning true:

I can use below query to be content but Problem is when database is too large it takes too much time

Please can someone tell me

how to make query 1 to work right (as intended, returning true), or

how to make query 2 work fast with large tables

(please do not suggest that i should remove *ST_GeoGraphyFromText(‘MULTIPOLYGON(((179 -89,179 89,-179 89,-179 -89,179 -89)* because it only represents geographical data that will be replaced by data from the column of table )

other values with which query 1 dont work are (5 5) (10 10) (-10 -10) and much more

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:53:44+00:00Added an answer on June 17, 2026 at 3:53 pm

    The first query fails because you are using a geography type with something >180° wide. If it were something more realistic, such as 'MULTIPOLYGON(((100 0,100 50,0 50,0 0,100 0)))', it will return TRUE.

    There is no direct way to find the maximum diameter of the exterior rings of the MultiPolygon geography types, but you can attempt to hunt these particular cases down with something like:

    SELECT ST_XMax(geog::geometry) - ST_XMin(geog::geometry) AS width,
           ST_YMax(geog::geometry) - ST_YMin(geog::geometry) AS height
    FROM polygons
    

    examine the ones that are > 180, and see if each of the parts are also > 180. If so, these should be regarded as invalid geographies.


    The only reason why the second query returns TRUE is because ST_AsText converts to WKT, which is then re-interpreted back to WKB as geometry types (and implicitly calls ST_Covers(geometry, geometry), rather than ST_Covers(geography, geography)). This query is slow since it converts from WKB to WKT to WKB, with possible loss of precision in between conversions. A faster version of this is to cast the geography column to geometry using ::geometry, e.g.:

    SELECT ST_Covers(geog::geometry, ST_SetSRID(ST_MakePoint(20, 30), 4326))
    FROM polygons
    

    Geometry types use simple “flat earth” Cartesian logic for ST_Covers, which is why you see TRUE for what you expect. Geography types use a different “round earth” logic, which uses more complicated spherical logic, but is easy to see if you have a globe handy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query that uses a UNION: $this->db->query(' SELECT DISTINCT users.user_pic, users.id, users.username,
I have a query that uses a where clause. At times, this may be
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
I have this query... SELECT Distinct([TargetAttributeID]) FROM (SELECT distinct att1.intAttributeID as [TargetAttributeID] FROM AST_tblAttributes
i have this query: SELECT `completed`.`ID` AS `ID`,`completed`.`level` AS `level`,`completed`.`completed_in` AS `completed_in`, COUNT(1) AS
I have this query SELECT zip, ( 3959 * acos( cos( radians(34.12520) ) *
I have a stored procedure that uses this select statement: SELECT dbo.VendorProgram.id, dbo.VendorProgram.CODE, dbo.Programs.ProgramName
I have this query (shown below) which currently uses temporary and filesort in order
I currently have this query: SELECT *, GEODIST(41.3919671, 2.1757278, latitude, longitude) distance FROM offers_all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.