A
A
Adelina Turcan2019-02-26 18:40:00
MySQL
Adelina Turcan, 2019-02-26 18:40:00

polygon data type in mysql, how to search among them?

There is a mysql table: objects_on_map(download) . It has 3 columns:

  • id - smallint primary key
  • name-varchar
  • zone-polygon

Added 5 rows for example:
5c755c40f2bb3243849881.png5c755c497e3b8421341298.png5c755c5007d95338945982.png5c755c5a0eb01694094236.png5c755c600a9ed824374434.png
Now I need to search among the objects in the database, for example, this zone
First example polygon
{
  "type": "Polygon",
  "coordinates": [
    [
      [
        26.680096221945632,
        48.321938323603554
      ],
      [
        28.164459014914428,
        46.83322861900734
      ],
      [
        28.255058456442725,
        46.48886163202014
      ],
      [
        28.125931335471023,
        46.1575226177054
      ],
      [
        28.197266937277732,
        45.488822095796266
      ],
      [
        28.471774078391036,
        45.48352675782778
      ],
      [
        29.02078836061753,
        46.00964308670618
      ],
      [
        28.998211456320632,
        46.490161685568545
      ],
      [
        30.161553741476837,
        46.41825757113949
      ],
      [
        29.614678360007133,
        46.93363548533478
      ],
      [
        29.52922875978743,
        47.38462608018191
      ],
      [
        29.160575653097908,
        47.55353053897963
      ],
      [
        29.14836709596898,
        47.97804022625874
      ],
      [
        27.717699981711235,
        48.45366512797827
      ],
      [
        26.680096221945632,
        48.321938323603554
      ]
    ]
  ]
}

How to form a query to search among the polygon column values? All entries should be returned.
And if you look for, for example, something like this:
Second example polygon
{
  "type": "Polygon",
  "coordinates": [
    [
      [
        28.84997134215496,
        47.0428453687384
      ],
      [
        28.73491702086585,
        46.982931417099465
      ],
      [
        28.923826932975317,
        46.99791941766723
      ],
      [
        28.84997134215496,
        47.0428453687384
      ]
    ]
  ]
}

then only id should come in response: 1, 3 and 4. There will be approximately 100 million records in the table, so if you can tell me which indexes to use.
I used this to form objects on the map.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2019-02-26
@adelina_turcan

For a "spherical horse in a vacuum" use the basics of geometry (cosine and sine).
For polygons it's better to switch to PostreSQL and use postgis.net

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question