The missing GeoJSON utilities for OpenStreetMap
Because existing tools cannot solve below problems efficiently
- Building an OSM object in GeoJSON format with sub-areas separated. osmtogeojson or polygons.openstreetmap.fr won't work because they don't include inner boundaries.
- Tags and metadata normalization
- Optional D3-compatibility. It doesn't follow common convetion like winding order from GeoJSON’s RFC 7946
These above problems keep showing up and bugging me because my work is closely related. So if you share the same concerns, this tool is for you.
The accuracy of information provided by the tool solely depends on OpenStreetMap data.
I do not accept any responsibility or liability for the accuracy, content, completeness, legality, or reliability of the information provided by the tool or contained on the website.
go version >= go1.13
GO111MODULE=on go get -u github.com/hiendv/geojson/cmd/geojson
List all New York sub-areas
geojson subarea 61320
2020-08-05T14:41:57.087+0700 INFO fetching sub-areas {"parent": 61320}
2020-08-05T14:42:06.126+0700 INFO writing {"path": "geojson/61320.geojson"}
2020-08-05T14:42:06.127+0700 INFO sub-areas handled {"total": 62}
The difference with existing tools can be demonstrated with two visualization below
(after manual correction and right-hand-rule fixing)
geojson --help
NAME:
GeoJSON - Utilities for OpenStreetMap GeoJSON
USAGE:
geojson [global options] command [command options] [arguments...]
VERSION:
0.1.1
AUTHOR:
Hien Dao <[email protected]>
COMMANDS:
serve serve the web server
subarea list all sub-areas of an OpenStreetMap object
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--out value, -o value specify the directory of outputs (default: "./geo")
--verbose enable verbose logging with DEBUG level (default: false)
--help, -h show help (default: false)
--version, -v print the version (default: false)
COPYRIGHT:
Copyright © 2020 Hien Dao. All Rights Reserved.
Notice: To print outputs to stdout, specify --out
as an empty string
geojson --out "" command [command options] [arguments...]
geojson subarea --help
NAME:
geojson subarea - list all sub-areas of an OpenStreetMap object
USAGE:
geojson subarea [command options] [arguments...]
OPTIONS:
--raw, -r leave tags in unfornalized form (UNF) (default: false)
--separated, -s leave sub-areas unmerged (default: false)
--rewind rewind the output - counter to RFC 7946 (default: false)
--help, -h show help (default: false)
geojson serve --help
NAME:
geojson serve - serve the web server
USAGE:
geojson serve [command options] [arguments...]
OPTIONS:
--address value, --addr value set the serving address (default: "127.0.0.1:8181")
--origin value set the CORS origin (default: "*")
--rate value set request-per-second for rate-limiting (default: 10)
--rate-burst value set burst size (concurrent requests) for rate-limiting (default: 5)
--rate-ttl value set the rate limit TTL for inactive sessions (default: "2m")
--prefix value set static fs handler base path (default: "/static")
--help, -h show help (default: false)
The rate-limiting will be specified by --rate
, --rtate-burst
, --rate-ttl
parameters.
Default values should be 10 requests/second with a concurrent value of 5 and time-to-live for inactive sessions of 2 minutes.
-
Parameters
- id (number, required) - ID of an OpenStreetMap relation.
- rewind (optional) - Rewinding the requested GeoJSON
-
Response 200 (application/json)
- Attributes
- code (number)
- message (string)
- data (string)
- Attributes
Example
GET /api/v1/subareas/61320?rewind HTTP/1.1
Host: localhost:8181
User-Agent: curl/7.68.0
Accept: */*
HTTP/1.1 200 OK
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Origin: *
Content-Type: application/json
X-Content-Type-Options: nosniff
Date: Wed, 19 Aug 2020 16:25:13 GMT
Content-Length: 58
{"code":0,"message":"","data":"/static/geo/61320-rewind.geojson"}
Example
GET /static/geo/61320.geojson HTTP/1.1
Host: localhost:8181
User-Agent: curl/7.68.0
Accept: */*
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 1298442
Content-Type: text/plain; charset=utf-8
Last-Modified: Wed, 19 Aug 2020 11:47:13 GMT
Date: Wed, 19 Aug 2020 16:37:00 GMT
{"type":"FeatureCollection","features":[{"id":"relation/962876","type":"Feature","geometry":{...}}]}
- go version go1.11 for modules support
go run cmd/geojson/main.go --help
go run cmd/geojson/main.go subarea --help
go run cmd/geojson/main.go serve --help
go build -o geojson cmd/geojson/main.go
### Format
gofumpt -w -s ./
### Lint
golangci-lint run ./...
go test -race ./...
Issues and PRs are welcome !
MIT © 2020 Hien Dao [email protected]