Pergunta

Suponha que eu tenha uma tabela de 2 colunas como esta:

| user_id      | int(11) | NO   | UNI | NULL    |                |
| utm          | point   | NO   | MUL | NULL    |                |

Como você pode ver, é muito simples. utm é a Ponto tipo de dados. Eu insiro assim:

INSERT INTO mytable(user_id, utm) VALUES(1, PointFromWKB(point(50, 50)));

Então, eu crio um índice espacial.

ALTER TABLE mytable ...add spatial index on(utm) or something. (forgot)

Tudo bem, está tudo bem. Agora eu quero Selecione * onde distância <99999.Mas não funciona!

//This is supposed to select all where the distance is less than 99999999.
set @mypoint = PointFromWKB(point(20,20))
select * from mytable where GLength(LineString(utm, @mypoint)) < 9999999;
Empty set (0.00 sec)
select * from mytable where GLength(LineStringFromWKB(LineString(utm, @mypoint))) < 9999;
Empty set (0.00 sec)

A propósito, tentei inserir sem o ponto de ponto ... e não funcionou ... foi por isso que alguém sugeriu esse ponto de ponto para mim.

Foi útil?

Solução

Resolvido. Isso é o que eu fiz:

where GLength(LineStringFromWKB(LineString(asbinary(utm), asbinary(@mypoint)))) < 9999999999999;

Outras dicas

Você também pode fazer dessa maneira. Não tenho certeza se é mais rápido ou não.

select * from mytable where glength(geomfromtext(concat('linestring(', x(utm), ' ', y(utm), ',20 20', ')'))) < 99999999

Tanto quanto eu sei, você tem que tentar assim-

select * from mytable
   where 
    (
        GLength(
          LineStringFromWKB(
            LineString(
              geoPoint, 
              GeomFromText('POINT(51.5177 -0.0968)')
            )
          )
        )
      ) < 99999999

Mais em esta resposta.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top