README.md 4.81 KB
Newer Older
Lukas Loos's avatar
Lukas Loos committed
1
2
# ohsome2X

3
4
5
> Query OSM History Data (count, length, area) about specific OSM Features or OSM User activity (user-count) for your areas of interest.

> Input: Accepts GeoJSON or PostgreSQL/PostGIS as input source.
Michael Auer's avatar
Michael Auer committed
6

7
> Output: Creates a GeoJSON File or new result table in your PostgreSQL/PostGIS database. 
8

9
The package includes a library with a single class to run. 
Michael Auer's avatar
Michael Auer committed
10

11
Additionally it includes `ohsome2x-cli`, a command-line tool with a configuration wizard to create and run a query-configuration-JSON.
Michael Auer's avatar
Michael Auer committed
12

13
This library/tool makes use of the ohsome API (https://api.ohsome.org) as data backend and many other great open-source libraries.
Michael Auer's avatar
Michael Auer committed
14

15
This software is developed by [HeiGIT](https://heigit.org):
Michael Auer's avatar
Michael Auer committed
16

17
18
<img src="https://heigit.org/wp-content/uploads/2018/01/HeiGIT_Logo_cut-505x100@2x.png" alt="HeiGIT Logo" height="80px" width="404px">

19
20
21
22
23
24
## Usage
There are two ways how you can use ohsome2x.

### 1. Without installation using the npm package runner `npx`

> Info: The `npx` command comes with the installation of `npm`.
Michael Auer's avatar
Michael Auer committed
25

26
To run the command-line wizard:
27
```sh
28
29
30
31
32
33
34
35
36
37
38
Syntax info:
$ npx @giscience/ohsome2x
-------------------------
USAGE:
with 'npx'
npx @giscience/ohsome2x createconfig [(-o|--out) path]
npx @giscience/ohsome2x run (-c|--conf) fullConfig.json
as local command
node ohsome2x-cli.js createconfig [(-o|--out) path]
node ohsome2x-cli.js run (-c|--conf) fullConfig.json
-------------------------
Michael Auer's avatar
Michael Auer committed
39
40
```

41
### 2. With installation as library to use it in your Node.js script
42

43
44
45
46
47
48
49
1. For use as library in Node.js install the package:

    ```sh
    $ npm install @giscience/ohsome2x
    ```

2. You find the built library in the `/dist` folder after executing:
Michael Auer's avatar
Michael Auer committed
50

51
52
53
    ```
    $ npm run build
    ```
54

55
56
57
58
59
3. Write your own JavaScript or TypeScript file:

    ```
    See Examples and API section to learn how to do it. Enjoy!
    ```
60
61
62
63
64
65
   
## Example

### Query the number of buildings in a bbox around Heidelberg in a yearly resolution from 2008 to 2020

##### Step 1. You need some input (one or many polygons): heidelberg.geojson
66
```json
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {"id": "Heidelberg"},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [ [8.625984191894531, 49.38527827629032],
            [8.735504150390625, 49.38527827629032],
            [8.735504150390625, 49.433975502014675],
            [8.625984191894531, 49.433975502014675],
            [8.625984191894531, 49.38527827629032]
          ]]}}]}
```

84
85
86
87
##### Step 2. Specify your query as JSON-file (you can use the commandline wizard to create this): myquery.json

> Info: for the filter Syntax see: https://docs.ohsome.org/ohsome-api/stable/filter.html

88
```json
89
{
90
91
  "ohsomeQuery": {
    "queryType": "elements/count/groupBy/boundary",
92
    "filter": "building=* and building!=no and geometry:polygon",
93
    "time": "2008/2020/P1Y"
94
  },
95
96
97
98
  "source": {
    "geometryId": "id",
    "name": "heidelberg.geojson",
    "store": { "path": "heidelberg.geojson", "type": "geojson" }
99
  },
100
101
102
103
104
105
106
107
  "target": {
    "horizontalTimestampColumns": false,
    "createGeometry": true,
    "transformToWebmercator": false,
    "storeZeroValues": true,
    "computeValuePerArea": true,
    "name": "heidelberg_buildings_count.geojson",
    "store": { "path": "heidelberg_buildings_count.geojson", "type": "geojson" }
108
109
110
111
112
113
  }
}
```

##### Step 3. Run the Query
```bash
114
$ npx @giscience/ohsome2x run --conf myquery.json
115
116
117
118
119
120
121
```



## API

Node:
122
```js
Michael Auer's avatar
Michael Auer committed
123
const Ohsome2X = require('@giscience/ohsome2x');
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

// you can create this config using the command-line wizard, run: npx ohsome2x-cli
const config = {
                ohsomeQuery: {...},
                source: {...},
                target: {...}
}                               

const ohsome2x = new Ohsome2X(config);

// This will return a Promise
ohsome2x.run().catch(console.log);
```

TypeScript:
```typescript
Michael Auer's avatar
Michael Auer committed
140
import Ohsome2X = require('@giscience/ohsome2x'); 
141
import {Ohsome2XConfig} from '@giscience/ohsome2x/dist/config_types_interfaces';
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

// you can create this config using the command-line wizard, run: npx ohsome2x-cli
const config: Ohsome2XConfig = {
                ohsomeQuery: {...},
                source: {...},
                target: {...}
}                               

const ohsome2x = new Ohsome2X(config);

// This will return a Promise
ohsome2x.run().catch(console.log);
```

### Related

- [OhsomeHeX](https://ohsome.org/apps/osm-history-explorer) - The OSM History Explorer: Uses this library as backend
159
- [ohsome API](https://api.ohsome.org) - WebAPI to query OSM History Data
160
- [OSHDB](https://github.com/GIScience/oshdb) - The OpenStreetMap History Database: Query OSM History Data with Java
161
- [ohsome.org](https://ohsome.org) - Get information about all these technologies and more
162
- [heigit.org](https://heigit.org) - The Heidelberg Institute for Geoinformation Technology: The non-profit company behind all those useful tools.