<commit_before>var db_access= require('../../persistence/db_access_v3');
var helper = require('./helper');
var parallel = require("async/parallel");
var converter = require('./wgs84_ch1903');
var request = require('request');


//Constants for community types:
const LARGECENTRE = {
    id: 1,
    name: 'Grosszentrum',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const BESIDESCENTREOFLARGECENTRE = {
    id: 2,
    name: 'Nebenzentrum eines Grosszentrums',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const BELTOFLARGECENTRE = {
    id: 3,
    name: 'Gürtel eines Grosszentrums',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const MEDIUMCENTRE = {
    id: 4,
    name: 'Mittelzentrum',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const BELTOFMEDIUMCENTRE = {
    id: 5,
    name: 'Gürtel eines Mittelzentrums',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const SMALLCENTRE = {
    id: 6,
    name: 'Kleinzentrum',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const PERIURBAN = {
    id: 7,
    name: 'Periurbane ländliche Gemeinde',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const AGRICULTURAL = {
    id: 8,
    name: 'Agrargemeinde',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const TOURISTICAL = {
    id: 9,
    name: '<NAME>',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const OTHER = {
    id: 100,
    name:"other",
    osm_key: '',
    osm_value: '',
    description: "OSM-tag is defined, but not supported."
};

const UNKNOWN = {
    id: -1,
    name: "unknown",
    osm_key: 'unknown',
    osm_value: 'unknown',
    description: "No tagging possible."
};


const FIND_MIDDLE_POINT = "WITH middlePoint AS " +
    "(SELECT ST_Centroid(ST_GeomFromText(('MULTIPOINT ({lon1} {lat1}, {lon2} {lat2})'), 4326))) " +
    "SELECT ST_AsText(st_centroid), ST_X(st_centroid), ST_Y(st_centroid) FROM middlePoint;";



//TODO: create Table where the not null part is precalculated
const NATURAL_QUERY = 'SELECT "natural" FROM surroundings ' +
                    'WHERE "natural" IS NOT NULL AND ST_Within(' +
                    'ST_GeomFromText((\'{point}\'), 4326), ' +
                    'ST_GeomFromEWKB(wkb_geometry));';

const BOUNDARY_QUERY = 'SELECT boundary FROM surroundings ' +
                    'WHERE boundary IS NOT NULL AND boundary != \'administrative\' AND ST_Within(' +
                    'ST_GeomFromText((\'{point}\'), 4326), ' +
                    'ST_GeomFromEWKB(wkb_geometry));';

const LEISURE_QUERY = 'SELECT leisure FROM surroundings ' +
                    'WHERE leisure IS NOT NULL AND ST_Within(' +
                    'ST_GeomFromText((\'{point}\'), 4326), ' +
                    'ST_GeomFromEWKB(wkb_geometry))';

const LANDUSE_QUERY = 'SELECT landuse FROM surroundings ' +
                    'WHERE landuse IS NOT NULL AND ST_Within(' +
                    'ST_GeomFromText((\'{point}\'), 4326), ' +
                    'ST_GeomFromEWKB(wkb_geometry));';

//TODO: 2 Abfragen daraus erstellen
const GEOADMIN_URL = 'https://api3.geo.admin.ch/rest/services/all/MapServer/identify?geometry={y},{x}' +
    '&geometryFormat=geojson&geometryType=esriGeometryPoint&imageDisplay=1,1,1&lang=de&layers=all:ch.are.bevoelkerungsdichte,' +
    'ch.are.gemeindetypen&mapExtent=0,0,1,1&returnGeometry=false&tolerance=5';

function getGeographicalSurroundings(positions, callback) {
    var middlePointQueries = prepareMiddlePointDbStatements(FIND_MIDDLE_POINT, positions);

    parallel([
            function(callback) {
                db_access.queryMultiple(db_access.getDatabase(db_access.SWITZERLAND_DB), middlePointQueries, function (result) {
                    callback(null, result);
                });
            }<commit_msg>Unnötige Prüfung aus boundary query entfernt<commit_after>var db_access= require('../../persistence/db_access_v3');
var helper = require('./helper');
var parallel = require("async/parallel");
var converter = require('./wgs84_ch1903');
var request = require('request');


//Constants for community types:
const LARGECENTRE = {
    id: 1,
    name: 'Grosszentrum',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const BESIDESCENTREOFLARGECENTRE = {
    id: 2,
    name: 'Nebenzentrum eines Grosszentrums',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const BELTOFLARGECENTRE = {
    id: 3,
    name: 'Gürtel eines Grosszentrums',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const MEDIUMCENTRE = {
    id: 4,
    name: 'Mittelzentrum',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const BELTOFMEDIUMCENTRE = {
    id: 5,
    name: 'Gürtel eines Mittelzentrums',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const SMALLCENTRE = {
    id: 6,
    name: 'Kleinzentrum',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const PERIURBAN = {
    id: 7,
    name: 'Periurbane ländliche Gemeinde',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const AGRICULTURAL = {
    id: 8,
    name: 'Agrargemeinde',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const TOURISTICAL = {
    id: 9,
    name: 'Touristische Gemeinde',
    description: 'Tag is derived from: Gemeindetypologie ARE (Bundesamt für Raumentwicklung)'
};

const OTHER = {
    id: 100,
    name:"other",
    osm_key: '',
    osm_value: '',
    description: "OSM-tag is defined, but not supported."
};

const UNKNOWN = {
    id: -1,
    name: "unknown",
    osm_key: 'unknown',
    osm_value: 'unknown',
    description: "No tagging possible."
};


const FIND_MIDDLE_POINT = "WITH middlePoint AS " +
    "(SELECT ST_Centroid(ST_GeomFromText(('MULTIPOINT ({lon1} {lat1}, {lon2} {lat2})'), 4326))) " +
    "SELECT ST_AsText(st_centroid), ST_X(st_centroid), ST_Y(st_centroid) FROM middlePoint;";



//TODO: create Table where the not null part is precalculated
const NATURAL_QUERY = 'SELECT "natural" FROM surroundings ' +
                    'WHERE "natural" IS NOT NULL AND ST_Within(' +
                    'ST_GeomFromText((\'{point}\'), 4326), ' +
                    'ST_GeomFromEWKB(wkb_geometry));';

const BOUNDARY_QUERY = 'SELECT boundary FROM surroundings ' +
                    'WHERE boundary IS NOT NULL AND ST_Within(' +
                    'ST_GeomFromText((\'{point}\'), 4326), ' +
                    'ST_GeomFromEWKB(wkb_geometry));';

const LEISURE_QUERY = 'SELECT leisure FROM surroundings ' +
                    'WHERE leisure IS NOT NULL AND ST_Within(' +
                    'ST_GeomFromText((\'{point}\'), 4326), ' +
                    'ST_GeomFromEWKB(wkb_geometry))';

const LANDUSE_QUERY = 'SELECT landuse FROM surroundings ' +
                    'WHERE landuse IS NOT NULL AND ST_Within(' +
                    'ST_GeomFromText((\'{point}\'), 4326), ' +
                    'ST_GeomFromEWKB(wkb_geometry));';

//TODO: 2 Abfragen daraus erstellen
const GEOADMIN_URL = 'https://api3.geo.admin.ch/rest/services/all/MapServer/identify?geometry={y},{x}' +
    '&geometryFormat=geojson&geometryType=esriGeometryPoint&imageDisplay=1,1,1&lang=de&layers=all:ch.are.bevoelkerungsdichte,' +
    'ch.are.gemeindetypen&mapExtent=0,0,1,1&returnGeometry=false&tolerance=5';

function getGeographicalSurroundings(positions, callback) {
    var middlePointQueries = prepareMiddlePointDbStatements(FIND_MIDDLE_POINT, positions);

    parallel([
            function(callback) {
                db_access.queryMultiple(db_access.getDatabase(db_access.SWITZERLAND_DB), middlePointQueries, function (result) {
                    callback(null, result);
                });
            }
{'fraction_non_alphanumeric': 0.12059212901672885, 'fraction_numerical': 0.012997954025755206, 'mean_word_length': 3.3439623627809723, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, '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': '5980625', 'n_tokens_mistral': 2870, 'n_tokens_neox': 2751, 'n_words': 641}