Skip to content

Commit b117831

Browse files
rootroot
root
authored and
root
committed
update overpass
1 parent be575d6 commit b117831

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

.vscode/extensions.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"svelte.svelte-vscode"
4+
]
5+
}

src/lib/util/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { default as exportToGeoJsonFile } from './exportToGeoJsonFile';
2+
export { default as fileToGeoJSON } from './fileToGeoJSON';
3+
export { default as geoJsonToPolygon } from './geoJsonToPolygon';

src/lib/util/fetchOverpass.ts src/lib/util/overpass/fetchOverpass.ts

+5
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ export default async (query) => {
99
}
1010
);
1111

12+
if (!result.ok) {
13+
const message = `An error has occured: ${result.status}`;
14+
throw new Error(message);
15+
}
16+
1217
return await result.json();
1318
};

src/lib/util/overpass/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export { default as config } from './config.json';
2+
export { default as fetchOverpass } from './fetchOverpass';
3+
export { default as queryAndDownload } from './queryAndDownload';

src/lib/util/queryAndDownload.ts src/lib/util/overpass/queryAndDownload.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import exportToGeoJsonFile from '$lib/util/exportToGeoJsonFile';
2-
import fetchOverpass from '$lib/util/fetchOverpass';
3-
import fileToGeoJSON from '$lib/util/fileToGeoJson';
4-
import geoJSONToPolygon from '$lib/util/geoJsonToPolygon';
5-
import { AllGeoJSON, feature, featureCollection, geometry, point, simplify } from '@turf/turf';
1+
import { AllGeoJSON, simplify } from '@turf/turf';
62
import osmtogeojson from 'osmtogeojson';
3+
import { exportToGeoJsonFile, fileToGeoJSON, geoJsonToPolygon } from '$lib/util';
4+
import fetchOverpass from '$lib/util/overpass/fetchOverpass';
75

86
export default async (file, overpassQuery: Array<any>, filename, radius = 1) => {
97
let createdGeoJson: AllGeoJSON = await fileToGeoJSON(file);
108

11-
let polygon = geoJSONToPolygon(createdGeoJson, radius);
9+
let polygon = geoJsonToPolygon(createdGeoJson, radius);
1210
console.log(polygon);
1311

1412
let simplifiedPolygon = simplify(polygon, { highQuality: true, mutate: false, tolerance: 0.05 });
@@ -24,11 +22,12 @@ export default async (file, overpassQuery: Array<any>, filename, radius = 1) =>
2422

2523
overpassQuery.map(
2624
(overpassQueryObject) =>
27-
(middleQuery += `way["${Object.keys(overpassQueryObject)[0]}"="${
25+
(middleQuery += `nwr["${Object.keys(overpassQueryObject)[0]}"="${
2826
overpassQueryObject[Object.keys(overpassQueryObject)[0]]
2927
}"](poly:"${polygonstring}");`)
3028
);
31-
const query = `[out:json][timeout:150];(${middleQuery});(._;>;);out meta;`;
29+
30+
const query = `[out:json][timeout:150];(${middleQuery});(._;>;);out center;`;
3231

3332
const data = await fetchOverpass(query);
3433
console.log(data);

src/routes/index.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { FileInput, DownloadButton } from '$lib/components/index';
3-
import queryAndDownload from '$lib/util/queryAndDownload';
3+
import { queryAndDownload } from '$lib/util/overpass';
44
import { config } from '$lib/util/overpass';
55
import { fetchWikidata } from '$lib/util/wikidata';
66
import exportToGeoJSONFile from '$lib/util/exportToGeoJsonFile';
@@ -54,7 +54,7 @@
5454
queryAndDownload(
5555
files[0],
5656
configuration.query,
57-
files[0].name + ' --- ' + configuration.name,
57+
`${removeFilenameExtention(files[0].name)}---${configuration.name}`,
5858
radiusInKm
5959
)}
6060
name={configuration.name}

0 commit comments

Comments
 (0)