Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

220
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda