1

I have a array called place_names which holds some place names. I have a GeoJSON layer loaded in CartoDB, which has three columns id, name and the_geom (which is a geometry object) that can be queried and retrieved as JSON. What I need is I am comparing the names in place_names array to the GeoJSON name column, if the name in place_names array matches with that of the GeoJSON names, I want to retrieve the geometry of the matched names and add that to Google maps. How could this could be done? My code so far:

var place_names = [];
$.getJSON(json_link,
    function (data) {
            for (i=0; i<data.rows.length; i++) {
                            unique = data.rows[i].region_name;
                            place_names.push(unique);
                        }
/*geojson names field*/
var msa_place = [];
$.getJSON(msa_usa_json_link,
  function (data) {
            for (i=0; i<data.rows.length; i++) {
                            msa_name = data.rows[i].name;
                            msa_place.push(msa_name);
                        }
                    });

var places = [];
    for (i=0; i<place_names.length; i++) {
        for (j=0; j<msa_place.length; j++) {

            if (place_names[i] === msa_place[j]) {
                places.push(place_names[i]);
                console.log(places);
                for (e=0; e<places.length; e++) {
                    ....../*do something to get geometry of matched places */
                }
            }
            else {
                console.log("no matches found");
            }

         }
      }
   });
});
  • What geometry type do you have? Are these points, polygons or polylines or even mixed? – eltomaco Nov 30 '15 at 12:53
  • Multipolygons. Which is equivalent to polygons in google maps. – User123 Nov 30 '15 at 12:54
  • edit: How does the json object of the geometries look? Can you post a sample? – eltomaco Nov 30 '15 at 12:55
  • When i print the geometry of the json to the console, it prints something like 0106000020E610000001000000010300000001000000800000…0D7A3703D0A974540C3F5285C8F2256C09999999999994540. I think its in WKB and we want to convert it to WKT. – User123 Nov 30 '15 at 13:02
  • Doesn't it look something like '[ { "id": ..., "coors": ..., "other stuff": .. }]' so then it would be pretty easy. You could then get the coordinates from each object to create a new google maps polygon. – eltomaco Nov 30 '15 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.