Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
Sequelize – finding point in range

I have an Address model that has a point attribute of type geometry defined. I want to create a function when I pass latitude, longitude and range and it returns all of the addresses within that range (in meters). I tried to follow what has been written here but I'm getting:

DatabaseError [SequelizeDatabaseError]: LWGEOM_dwithin: Operation on mixed SRID geometries (Point, 4326) != (Point, 0)

This is how I defined by point in the Address model:

point: {
   type: DataTypes.GEOMETRY('Point'),
   allowNull: true,
},

And this is the function I'm trying to write:

const findInRangeFrom = (latitude, longitude, range) => {
  return Address.findAll({
    attributes: {
      include: [[
        Sequelize.fn(
          'ST_Distance',
          Sequelize.col('point'),
          Sequelize.fn('ST_MakePoint', longitude, latitude),
        ),
        'distance',
      ]],
    },
    where: Sequelize.where(
      Sequelize.fn(
        'ST_DWithin',
        Sequelize.col('point'),
        Sequelize.fn('ST_MakePoint', longitude, latitude),
        range,
      ),
      true,
    ),
    order: Sequelize.literal('distance ASC'),
  });
};

How can I make this work?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If geometries in DB are stored in the SRID 4326, then you need to set the same SRID for your test point like this:

Sequelize.fn('ST_SetSRID', Sequelize.fn('ST_MakePoint', longitude, latitude), 4326)

If vice versa then you need to indicate SRID 4326 for the point column:

Sequelize.fn('ST_SetSRID', Sequelize.col('point'), 4326)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda