Skip to content

Instantly share code, notes, and snippets.

@franciscopessoa
Last active February 28, 2020 17:38
Show Gist options
  • Save franciscopessoa/19a7f8dbe58e318e760b428ff893061c to your computer and use it in GitHub Desktop.
Save franciscopessoa/19a7f8dbe58e318e760b428ff893061c to your computer and use it in GitHub Desktop.
Search point in Polygn MySQL
CREATE TABLE `municipal_border` (
`boundary` polygon NOT NULL,
`municipalID` int(10) NOT NULL)
SET @g = 'POLYGON((22.367582117085913 70.71181669186944, 22.225161442616514 70.65582486840117, 22.20736264867434 70.83229276390898, 22.18701840565626 70.9867880031668, 22.22452581029355 71.0918447658621, 22.382709129816103 70.98884793969023, 22.40112042636022 70.94078275414336, 22.411912121843205 70.7849142238699, 22.367582117085913 70.71181669186944))';
INSERT INTO municipal_border (boundary,municipalID) VALUES (ST_GeomFromText(@g),2)
set @p = GeomFromText('POINT(22.4053386588057 70.86240663480157)');
select * FROM municipal_border where ST_Contains(boundary, @p);
select
a.longitude,
a.latitude,
b.id as cerca_id,
b.nome as cerca
FROM
WAVES.tb_orcamentos_rotas AS a
LEFT JOIN WAVES.tb_mapas_cercas AS b ON
(ST_Contains(b.poligono, GeomFromText(CONCAT('POINT(', a.longitude, a.latitude, ')'))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment