Exemplo n.º 1
0
function overpassApi (query, callback, options) {
	var overpass = require('query-overpass');

	console.log(overpass);

	overpass(query, callback, options);
}
Exemplo n.º 2
0
module.exports = function(id, callback) {
  query_overpass('[out:json];relation('+id+');>;out;', function(error, data){
    if(!error){
      linestringArray = [];
      pointPolygon = [];

      data.features.forEach(function(entry) {
        if(entry.geometry.type == 'LineString'){
          linestringArray.push(entry.geometry.coordinates);
        }
      });

      var n = linestringArray.length;
      var igeo = 0;

      for (var i = 0; i < n; i++) {
        if(!pointPolygon[igeo]){
          pointPolygon[igeo] = linestringArray[igeo];
          linestringArray.splice(0,1);
        }
        var pointtofind = pointPolygon[igeo][pointPolygon[igeo].length-1];
        linestringArray.forEach(function(entry,index) {
          if(entry[0][0] == pointtofind[0] && entry[0][1] == pointtofind[1]){
            var arraytoadd = entry;
            arraytoadd.splice(0,1);
            pointPolygon[igeo] = pointPolygon[igeo].concat(arraytoadd);
            linestringArray.splice(index,1);
          }
          if(entry[entry.length-1][0] == pointtofind[0] && entry[entry.length-1][1] == pointtofind[1]){
            var arraytoadd = entry.reverse();
            arraytoadd.splice(0,1);
            pointPolygon[igeo] = pointPolygon[igeo].concat(arraytoadd);
            linestringArray.splice(index,1);
          }
        });
        if(
          pointPolygon[igeo][0][0] == pointPolygon[igeo][pointPolygon[igeo].length-1][0]
          && pointPolygon[igeo][0][1] == pointPolygon[igeo][pointPolygon[igeo].length-1][1]
          && linestringArray.length != 0
        ){
          igeo++;
        }
      }

      if(linestringArray.length == 0){
        try {
          var poly1 = turf.polygon(pointPolygon);
          var poly2 = turf.polygon(pointPolygon, {bbox:turf.bbox(poly1)});
          callback(fc([poly2]));
        }
        catch (e) {
           callback(false);
        }
      }else{
        callback(false);
      }
    }else{
      callback(false);
    }

  }, {flatProperties:true});
};
Exemplo n.º 3
0
    handler: function(request, reply) {
        var bbox, longitude, latitude, numberOfResults, zoomLevel, query;
        
        // Given a bounding box, return some results.
        if (request.url.query.bbox) {
            bbox = request.url.query.bbox;
            query = '[out:json];node(' + bbox + ')[tourism=artwork];out;';
        } else {
            // If no bounding box is provided, assume Norfolk.
            // tk do some response limiting here with query string in app
            // or by getting long/lat from request source IP.
            bbox = '36.75,-76.44,36.98,-76.13';
            query = '[out:json];node(' + bbox + ')[tourism=artwork];out;';
        }

        // Alternatively, use latitude and longitude.
        if (request.url.query.longitude &&
                request.url.query.latitude &&
                request.url.query.zoomLevel) {
            longitude = request.url.query.longitude;
            latitude = request.url.query.latitude;
            zoomLevel = request.url.query.zoomLevel;

            // tk mathemagic happens here.
        }

        queryOverpass(query, function(error, data) {
            var properties, tags, geometry;
            var formattedResponse = [];

            // SCHEMA

            // id => node:id
            // title => tag:name
            // longitude => node:lon
            // latitude => node:lat
            // location => ? // (may no longer have relevance)
            // artists => tag:artist_name
            // url => tag:source
            // imageurl => tag:website_1
            // fullimage => tag:website
            // description => tag:note, tag:note_1 // if more required.

            _.each(data.features, function(element, index) {
                properties = element.properties;
                tags = properties.tags;
                geometry = element.geometry;

                formattedResponse.push({
                    id: properties.id,
                    title: tags.name,
                    longitude: geometry.coordinates[0],
                    latitude: geometry.coordinates[1],
                    artists: tags.artist_name,
                    url: tags.source,
                    imageurl: tags.website_1,
                    fullimage: tags.website,
                    description: tags.note +
                        (function extendedDescription(tags) {
                            var i = arguments.length > 1 ? 
                                arguments[1] :
                                1;
                            return (function (element) {
                                return tags.hasOwnProperty(element) ? 
                                    tags[element] +
                                        extendedDescription(tags, i + 1) :
                                    '';
                            })('note_' + i.toString());
                        })(tags)
                });
            });
            reply({
                exhibit: request.params.id ? 
                    formattedResponse.filter(
                        function (exhibit, i, list) {
                            return exhibit.id === parseInt(request.params.id);
                        }) : 
                    formattedResponse
            });
        });
    }
Exemplo n.º 4
0
var name = argv.name;

var query = fs.readFileSync(__dirname + '/' + input, {encoding: 'utf-8'});
process.stdout.write('Querying overpass...' + '\n');
overpass(query, function(err, data) {
    if (err) throw err;

    process.stdout.write('Cleaning up geojson...' + '\n');
    data.features.forEach(function(feature) {
        var props = feature.properties;
        var keys = Object.keys(props);
        keys.forEach(function(key) {
            if (props[key] instanceof Array) {
                props[key].forEach(function(prop) {
                    flatten(prop, key, props);
                });
            }

            if (props[key] instanceof Object) {
                flatten(props[key], key, props);
            }
        });
    });
    var geojson = JSON.stringify(raju(data));
    fs.writeFileSync('query.geojson', geojson);
    process.stdout.write('Uploading to Mapbox...' + '\n');
    uploadData(__dirname + '/query.geojson', accessToken, mapid, user);
});


function uploadData(file, accessToken, mapid, user) {
    var progress = upload({
Exemplo n.º 5
0
  (around: 200000, 23.825623, 120.982937);
out;
`;

console.log('syncing peaks')
query_overpass(query, (err, peaks) => {
  if (err) throw err;

  peaks.features = peaks.features.map( peak => {
    if (peak.properties.tags.name) {
      return ({
        "type": "Feature",
        "properties": {
            "tags": {
                "name": peak.properties.tags.name
            }
        },
        "geometry": {
            "type": "Point",
            "coordinates": peak.geometry.coordinates
        }
      })
    }
  })

  fs.writeFile(__dirname + '/peaks.geojson', JSON.stringify(peaks), (err) => {
    if (err) throw err;
    console.log('finished')
  })
})