<commit_before>/**
 * Module dependencies.
 */

var http = require('http'),
    express = require('express'),
    methodOverride = require('method-override'),
    bodyParser = require('body-parser'),
    errorHandler = require('errorhandler'),
    pg = require('pg-query');

var app = express();

// Configuration
app.set('port', process.env.PORT || 3000);
app.use(express.static(__dirname + '/public'));
app.use('/node_modules', express.static(__dirname + '/node_modules'));
app.set('views', __dirname);
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(methodOverride());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

if ('development' == app.get('env')) {
  app.use(errorHandler());
}
/*
app.configure('production', function(){
  app.use(express.errorHandler());
});

app.set('view options', {
  layout: false
});
// Use hamljs for HAML views
app.register('.haml', require('hamljs'));
*/

// Routes
app.get('/', function(req, res){
  res.render('index.html', {
  });
});

app.post('/RetrieveCadastre', function(req, res){
    RetrieveCadastre(req.body, res);
});

// get table names that have geom when server loads
// UPDATE TO YOUR connectionParameters = 'postgres://user:password@host:5432/database';
pg.connectionParameters = 'postgres://clayton:postgres@localhost:5432/postgres';
var tables = [];
pg('SELECT f_table_name tbl FROM geometry_columns;', function(err, rows, result){
  if (err) {
    console.log("error getting table names");
  } else {
    tables = rows;
  }
});

// RetrieveCadastre: returns all data in postgresql db within bounds of map window
function RetrieveCadastre(bounds, res){
  console.log('starting RetrieveCadastre function');
  // var connString = 'tcp://spatial:spatial@localhost/Spatial'; connectionParameters = 'postgres://user:password@host:5432/database';
//  pg.connectionParameters = 'postgres://clayton:postgres@localhost:5432/postgres';
//  var vals = [bounds._southWest.lng, bounds._southWest.lat, bounds._northEast.lng, bounds._southWest.lat, bounds._northEast.lng, bounds._northEast.lat,
//              bounds._southWest.lng, bounds._northEast.lat, bounds._southWest.lng, bounds._southWest.lat];
  var bbox = [[bounds._southWest.lng, bounds._southWest.lat].join(' '), [bounds._northEast.lng, bounds._southWest.lat].join(' '),[bounds._northEast.lng, bounds._northEast.lat]
              .join(' '),[bounds._southWest.lng, bounds._northEast.lat].join(' '),[bounds._southWest.lng, bounds._southWest.lat].join(' ')].join(",");
  //console.log('bbox = ', bbox);
  var sqlFull = [];
  for (i=0; i < tables.length; i++) {
    var sql = 'select ST_AsGeoJSON(geom) as shape ' + 'from ' + tables[i].tbl + ' ';
    sql = sql + 'where geom && ST_GeomFromText(\'SRID=4326;POLYGON((' + bbox + '))\') ';
    sql = sql + 'and ST_Intersects(geom, ST_GeomFromText(\'SRID=4326;POLYGON((' + bbox + '))\'))';
    sqlFull.push(sql);
  }
  var sql = sqlFull.join(' UNION ALL ') + ';'; // concatenate all geom responses and adds end of statement ';'<commit_msg>handle single table in db<commit_after>/**
 * Module dependencies.
 */

var http = require('http'),
    express = require('express'),
    methodOverride = require('method-override'),
    bodyParser = require('body-parser'),
    errorHandler = require('errorhandler'),
    pg = require('pg-query');

var app = express();

// Configuration
app.set('port', process.env.PORT || 3000);
app.use(express.static(__dirname + '/public'));
app.use('/node_modules', express.static(__dirname + '/node_modules'));
app.set('views', __dirname);
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(methodOverride());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

if ('development' == app.get('env')) {
  app.use(errorHandler());
}
/*
app.configure('production', function(){
  app.use(express.errorHandler());
});

app.set('view options', {
  layout: false
});
// Use hamljs for HAML views
app.register('.haml', require('hamljs'));
*/

// Routes
app.get('/', function(req, res){
  res.render('index.html', {
  });
});

app.post('/RetrieveCadastre', function(req, res){
    RetrieveCadastre(req.body, res);
});

// get table names that have geom when server loads
// UPDATE TO YOUR connectionParameters = 'postgres://user:password@host:5432/database';
pg.connectionParameters = 'postgres://clayton:postgres@localhost:5432/postgres';
var tables = [];
pg('SELECT f_table_name tbl FROM geometry_columns;', function(err, rows, result){
  if (err) {
    console.log("error getting table names");
  } else {
    tables = rows;
  }
});

// RetrieveCadastre: returns all data in postgresql db within bounds of map window
function RetrieveCadastre(bounds, res){
  console.log('starting RetrieveCadastre function');
  // var connString = 'tcp://spatial:spatial@localhost/Spatial'; connectionParameters = 'postgres://user:password@host:5432/database';
//  pg.connectionParameters = 'postgres://clayton:postgres@localhost:5432/postgres';
//  var vals = [bounds._southWest.lng, bounds._southWest.lat, bounds._northEast.lng, bounds._southWest.lat, bounds._northEast.lng, bounds._northEast.lat,
//              bounds._southWest.lng, bounds._northEast.lat, bounds._southWest.lng, bounds._southWest.lat];
  var bbox = [[bounds._southWest.lng, bounds._southWest.lat].join(' '), [bounds._northEast.lng, bounds._southWest.lat].join(' '),[bounds._northEast.lng, bounds._northEast.lat]
              .join(' '),[bounds._southWest.lng, bounds._northEast.lat].join(' '),[bounds._southWest.lng, bounds._southWest.lat].join(' ')].join(",");
  //console.log('bbox = ', bbox);
  var sqlFull = [];
  for (i=0; i < tables.length; i++) {
    var sql = 'select ST_AsGeoJSON(geom) as shape ' + 'from ' + tables[i].tbl + ' ';
    sql = sql + 'where geom && ST_GeomFromText(\'SRID=4326;POLYGON((' + bbox + '))\') ';
    sql = sql + 'and ST_Intersects(geom, ST_GeomFromText(\'SRID=4326;POLYGON((' + bbox + '))\'))';
    sqlFull.push(sql);
  }
  if (tables.length > 1) {
    var sql = sqlFull.join(' UNION ALL ') + ';'; // concatenate all geom responses and adds end of statement ';'
  } else {
    var sql = sqlFull + ';';
  }
{'fraction_non_alphanumeric': 0.1887401193740926, 'fraction_numerical': 0.009517664139377319, 'mean_word_length': 4.560538116591928, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4236920', 'n_tokens_mistral': 2160, 'n_tokens_neox': 2046, 'n_words': 407}