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 281255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:11:16+00:00 2026-05-12T05:11:16+00:00

This question is for Mysql geospatial-extension experts. The following query doesn’t the result that

  • 0

This question is for Mysql geospatial-extension experts.

The following query doesn’t the result that I’m expecting:

create database test_db;

use test_db;

create table test_table (g polygon not null);

insert into test_table (g) values (geomfromtext('Polygon((0 5,5 10,7 8,2 3,0 5))'));
insert into test_table (g) values (geomfromtext('Polygon((2 3,7  8,9 6,4 1,2 3))'));

select

X(PointN(ExteriorRing(g),1)), Y(PointN(ExteriorRing(g),1)),
X(PointN(ExteriorRing(g),2)), Y(PointN(ExteriorRing(g),2)),
X(PointN(ExteriorRing(g),3)), Y(PointN(ExteriorRing(g),3)),
X(PointN(ExteriorRing(g),4)), Y(PointN(ExteriorRing(g),4))

from test_table where MBRContains(g,GeomFromText('Point(3 6)'));

Basically we are creating 2 Polygons, and we are trying to use MBRContains to determine whether a Point is within either of the two polygons.

Surprisingly, it returns both polygons! Point 3,6 should only exist in the first inserted polygon.

Note that both polygons are tilted (once you draw the polygons on a piece of paper, you will see)

How come MySql returns both polygons? I’m using MySql Community Edition 5.1.

  • 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-05-12T05:11:16+00:00Added an answer on May 12, 2026 at 5:11 am

    UPDATE: Hopefully this answer has been obsoleted by MySQL: http://forge.mysql.com/wiki/GIS_Functions! Will leave as reference for older MBRContains implementations but a new answer explaining the changes would be welcome and should be “accepted” above this one.

    begin obsolete answer

    You are using (by necessity) minimum bounding rectangles, not the polygons as such. For the purpose of your query the shape being compared is equivalent to:

    'POLYGON(0 2,0 10,7 10,7 2,0 2)'

    for the first shape and:

    'POLYGON(2 1,9 1,9 9,2 9,2 1)'

    for the second. (3,6) is in both.

    MBR is a rough way of estimation, picture the rectangle as having vertical lines at min(x) and max(x), and horizontal lines at max(y) and min(y). Those shapes are easier for the database to calculate, MySQL does not support all polygon functions. (Area yes, linestrings generally yes, contains not yet. More details here.). If you want more precise geospatial geometry at the moment the best choice on the open source side is PostGIS.

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

Sidebar

Related Questions

This question is probably for MySQL experts and admins that have done this sort
Please note that this question is not about the mysql query per se, but
Please note that this question is not about the mysql query per se, but
I have the same tables as in this question: MySql query over many-to-many relationship
This question is geared towards MySQL, since that is what I'm using -- but
I have a MySQL database with two tables (simplified for this question): movies table
I have a webapp written in PHP using a MySQL database backend. This question
After posting this question MySQL update or insert or die query I've change to
This is relating to my last question mysql query with AND, OR and NOT
Following this question , I set the following MySQL parameter in C:\Program Files\MySQL\MySQL Server

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.