Commit 9fa8695f authored by Michael Auer's avatar Michael Auer
Browse files

changed ohsomeQueryConfig type should always use full ohsomeApi path. For...

changed ohsomeQueryConfig type should always use full ohsomeApi path. For backward compatibility /groupBy/boundary will be appended, if missing
parent 904ec8b2
import {Ohsome2XConfig, OhsomeQueryConfig, PostgisFeatureTypeConfig} from './config_types_interfaces';
import {
Ohsome2XConfig,
OhsomeQueryConfig,
TargetPostgisFeatureTypeConfig
} from './config_types_interfaces';
import normalizeUrl from 'normalize-url';
import {GeoJsonFeatureType} from './GeoJsonFeatureType';
import {PgFeatureType} from './PgFeatureType';
......@@ -27,49 +31,10 @@ class Ohsome2X {
constructor(config: Ohsome2XConfig) {
// let ohsomeQuery = {
// queryType: 'elements/count',
// keys: ['natural'].join(),
// values: ['tree'].join(),
// @types: ['node'],
// time: '2014-01-01/2017-01-01/P1Y'
// }
//
// let store = {
// type: 'postgis', //postgis,
// host: 'example.com',
// port: 5432,
// user: 'foo',
// password: '*****',
// database: 'your-db-name',
// //schema:
// }
//
// let sourceFeatureType = {
// name:'isea3h_nepal_res10_verkl', //postgis: tableName, geojson: optional name
// geometryId: 'id', //postgisOnly //unique not null, will be sorted when using fetchSize
// geometryColumn: 'geom', //postgisOnly //must be in EPSG:4326
// store: store, //store eg. postgis, geoJSON<FeatureCollection>,...
// fetchSize: 0 //postgisOnly
// }
//
// let targetFeatureType = {
// name: ohsomeQuery.keys[0] + '_' +ohsomeQuery.values[0],
// store: store,
// horizontalTimestampColumns: false,
// createGeometry: false, //TODO default should be true
// }
//
//
// //let
// config = {
// source: sourceFeatureType,
// target: targetFeatureType,
// ohsomeQuery: ohsomeQuery
// }
this.config = config;
this.cursor = this.config.source.cursor;
if ('cursor' in this.config.source) {
this.cursor = this.config.source.cursor;
}
// @ts-ignore fetchSize only available for PostgisStoreConfig
this.fetchSize = (!!this.config.source.fetchSize) ? parseInt(this.config.source.fetchSize) : null;
this.storeZeroValues = (!('storeZeroValues' in this.config.target)) ? true : !!this.config.target.storeZeroValues;
......@@ -109,7 +74,7 @@ class Ohsome2X {
}
//createGeometryOnTarget? default is true
const shouldCreateGeometry = (this.config.target.createGeometry == null) ? true : !!this.config.target.createGeometry;
const shouldCreateGeometry = (this.config.target.createGeometry == null) ? true : this.config.target.createGeometry;
// default is false
const transformToWebmercator = (shouldCreateGeometry && !!this.config.target.transformToWebmercator);
......@@ -316,7 +281,7 @@ class Ohsome2X {
// if(this.targetFeatureType.store.type == 'postgis' && !!this.config.target.createIndexes){
if (this.targetFeatureType instanceof PgFeatureType) {
this.targetFeatureType = <PgFeatureType>this.targetFeatureType;
let pgTarget = <PostgisFeatureTypeConfig>this.config.target;
let pgTarget = <TargetPostgisFeatureTypeConfig>this.config.target;
if (!!pgTarget.createIndexes) {
await this.targetFeatureType.createIndex('id');
if (!!this.config.target.horizontalTimestampColumns) {
......@@ -386,7 +351,7 @@ class Ohsome2X {
// });
const keys = ohsomeQuery.keys || '';
const values = ohsomeQuery.values || '';
const format = ohsomeQuery.format || 'json';
const format = ohsomeQuery.format || 'csv';
try {
console.log('----------------------------------');
console.log('Stringify Cells');
......@@ -410,9 +375,14 @@ class Ohsome2X {
});
console.timeEnd('querystring');
console.log('----------------------------------');
console.log(`Querying ohsome-API: ${this.ohsomeApiUrl}/${ohsomeQuery.queryType}/groupBy/boundary`);
// always make a group by boundary query for backward compatibility
// complete ohsomeAPI resource path should be used
let queryType = ohsomeQuery.queryType.replace(/(.*)(\/)?(\/groupBy\/boundary)(\/)?/, "$1");
console.log(`Querying ohsome-API: ${this.ohsomeApiUrl}/${queryType}/groupBy/boundary`);
const stats = await axios(<AxiosRequestConfig>{
url: `${this.ohsomeApiUrl}/${ohsomeQuery.queryType}/groupBy/boundary`,
url: `${this.ohsomeApiUrl}/${queryType}/groupBy/boundary`,
method: 'post',
header: {'content-type': 'application/x-www-form-urlencoded'},
maxContentLength: 1024 * 1024 * 1024 * 1024,
......@@ -489,4 +459,5 @@ class Ohsome2X {
}
export = Ohsome2X;
\ No newline at end of file
export = Ohsome2X;
// export * from './config_types_interfaces';
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment