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

110
Vistas
Query and get a unique list of values from geoJSON object

So I have a geoJSON object that looks like this:

{"type": "FeatureCollection", "features": 
              [{"type": "Feature",
                "properties": {
                               "site_name": "Active Reef (Active Sound)", 
                               "ccamlr_id": "48.1",
                                "site_id": "ACTI",
                                "model": "penguinmap.site"}, 
                "id": "ACTI",
                 "geometry": {
                               "type": "Point",
                                "coordinates": [-2435551.681071794, 1650542.7689355933]
                 }}, 
                {"type": "Feature",
                 "properties": {
                                "site_name": "Acuna Island",
                                "ccamlr_id": "48.2",
                                "site_id": "ACUN",
                                 "model": "penguinmap.site"},
                 "id": "ACUN",
                 "geometry": {
                               "type": "Point",
                               "coordinates": [-2279902.543759384, 2308975.9799890867]}}, 
            .......}]

I'm looking for a function that queries this by a property. More specifically, something like:

getObjects(geoJsonObj,"ccamlr_id", ['48.1', '48.2'])  

or something like that, where the query could be on multiple objects. In R the equivalent would be something like filter(geJsonObj, 'ccamlr_id' %in% c('48.1', '48.2'). I'm looking for a jQuery or Javascript analog.

This link: use jQuery's find() on JSON object was pretty close, but it only works on a single value. I.E., getObjects(geoJsonObj, 'ccamlr_id', '48.1'); but I'd like to get it so it works on multiple values of the key.

The getObjects function is:

function getObjects(obj, key, val) {
    var objects = [];
    for (var i in obj) {
        if (!obj.hasOwnProperty(i)) continue;
        if (typeof obj[i] == 'object') {
            objects = objects.concat(getObjects(obj[i], key, val));
        } else if (i == key && obj[key] == val) {
            objects.push(obj);
        }
    }
    return objects;
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

huh - well that ended up being easier than expected... a small tweak to the above function:

function getObjects(obj, key, val) {
    var objects = [];
    for (var i in obj) {
        if (!obj.hasOwnProperty(i)) continue;
        if (typeof obj[i] == 'object') {
            objects = objects.concat(getObjects(obj[i], key, val));
        } else if (i == key && $.inArray(obj[key], val) > -1) {
            objects.push(obj);
        }
    }
    return objects;
}
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