geo_faker 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +76 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/demo/demo.rb +54 -0
- data/demo/public/index.html +18 -0
- data/demo/public/index.js +62 -0
- data/geo_faker.gemspec +44 -0
- data/lib/geo_faker.rb +123 -0
- data/lib/geo_faker/geo_transform.rb +14 -0
- data/lib/geo_faker/point.rb +17 -0
- data/lib/geo_faker/version.rb +3 -0
- metadata +181 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c7d1d4f7353f87f97cee1d9e547b75599f35cfb5246e69008062b0d682a027a0
|
4
|
+
data.tar.gz: 8567fe428d3f10f5411d913334e09a525be71a728ff32dc8e938e6a316fbb951
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ace71954bff6a4194a3136961b7bdca2a303c219de3e384cf11d45ed87a002d8bf2c4dd628131359eacd9b203d6d8e4cb79c5c2814caac2b20dd757f18649027
|
7
|
+
data.tar.gz: c3cec9712b365497e72931396e77ef80222923b1161566e50e9ed580b8371d36d6e409078967b892c263ef3b58629acbf6afd52247421d69e8ce7a00f1e74c9f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.3
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at tim.landwerth@posteo.de. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
geo_faker (0.1.0)
|
5
|
+
rest-client
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.5.2)
|
11
|
+
public_suffix (>= 2.0.2, < 4.0)
|
12
|
+
coderay (1.1.2)
|
13
|
+
crack (0.4.3)
|
14
|
+
safe_yaml (~> 1.0.0)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
domain_name (0.5.20180417)
|
17
|
+
unf (>= 0.0.5, < 1.0.0)
|
18
|
+
hashdiff (0.3.7)
|
19
|
+
http-cookie (1.0.3)
|
20
|
+
domain_name (~> 0.5)
|
21
|
+
method_source (0.9.0)
|
22
|
+
mime-types (3.2.2)
|
23
|
+
mime-types-data (~> 3.2015)
|
24
|
+
mime-types-data (3.2018.0812)
|
25
|
+
mustermann (1.0.3)
|
26
|
+
netrc (0.11.0)
|
27
|
+
pry (0.11.3)
|
28
|
+
coderay (~> 1.1.0)
|
29
|
+
method_source (~> 0.9.0)
|
30
|
+
public_suffix (3.0.3)
|
31
|
+
rack (2.0.5)
|
32
|
+
rack-protection (2.0.4)
|
33
|
+
rack
|
34
|
+
rake (12.3.1)
|
35
|
+
rest-client (2.0.2)
|
36
|
+
http-cookie (>= 1.0.2, < 2.0)
|
37
|
+
mime-types (>= 1.16, < 4.0)
|
38
|
+
netrc (~> 0.8)
|
39
|
+
rspec (3.8.0)
|
40
|
+
rspec-core (~> 3.8.0)
|
41
|
+
rspec-expectations (~> 3.8.0)
|
42
|
+
rspec-mocks (~> 3.8.0)
|
43
|
+
rspec-core (3.8.0)
|
44
|
+
rspec-support (~> 3.8.0)
|
45
|
+
rspec-expectations (3.8.2)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.8.0)
|
48
|
+
rspec-mocks (3.8.0)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.8.0)
|
51
|
+
rspec-support (3.8.0)
|
52
|
+
safe_yaml (1.0.4)
|
53
|
+
sinatra (2.0.4)
|
54
|
+
mustermann (~> 1.0)
|
55
|
+
rack (~> 2.0)
|
56
|
+
rack-protection (= 2.0.4)
|
57
|
+
tilt (~> 2.0)
|
58
|
+
tilt (2.0.8)
|
59
|
+
unf (0.1.4)
|
60
|
+
unf_ext
|
61
|
+
unf_ext (0.0.7.5)
|
62
|
+
vcr (4.0.0)
|
63
|
+
webmock (3.4.2)
|
64
|
+
addressable (>= 2.3.6)
|
65
|
+
crack (>= 0.3.2)
|
66
|
+
hashdiff
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
ruby
|
70
|
+
|
71
|
+
DEPENDENCIES
|
72
|
+
bundler
|
73
|
+
geo_faker!
|
74
|
+
pry
|
75
|
+
rake
|
76
|
+
rspec
|
77
|
+
sinatra
|
78
|
+
vcr
|
79
|
+
webmock
|
80
|
+
|
81
|
+
BUNDLED WITH
|
82
|
+
1.17.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Zweitag GmbH
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# GeoFaker
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'geo_faker'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install geo_faker
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Around
|
22
|
+
Pick a random point around the center of the given location.
|
23
|
+
The distance of these points to the center follows a normal distribution with the given radius *r* as standard deviation σ.
|
24
|
+
To avoid extreme outliers, we do not allow any points with a distance greater than *3r*.
|
25
|
+
This means roughly 68% of points will be inside of the given radius and roughly 95% of points will be within a *2r*.
|
26
|
+
```ruby
|
27
|
+
require 'geo_faker'
|
28
|
+
|
29
|
+
point = GeoFaker.around('Alter Fischmarkt 12, Münster', radius_in_km: 1)
|
30
|
+
=> #<Point:0x000055b93554c4c0 @lat=51.96598262572216, @lon=7.630330692658974>
|
31
|
+
point.lat
|
32
|
+
=> 51.96598262572216
|
33
|
+
point.lon
|
34
|
+
=> 7.630330692658974
|
35
|
+
```
|
36
|
+
|
37
|
+
### Within
|
38
|
+
Pick a random, uniformly distributed point within the boundary polygon reported by the Nominatim API.
|
39
|
+
Currently this only works for places with exactly one boundary polygon. This means, it does not work for countries with exclaves or islands for now.
|
40
|
+
```ruby
|
41
|
+
GeoFaker.within('Allwetterzoo')
|
42
|
+
=> #<Point:0x000055b9354e8c90 @lat=51.94596285994424, @lon=7.591793493383972>
|
43
|
+
```
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
50
|
+
|
51
|
+
### Running the demo
|
52
|
+
|
53
|
+
This repository includes a demo server which helps visualizing the results of the different actions provided by GeoFaker.
|
54
|
+
|
55
|
+
After installing all the dependencies, run
|
56
|
+
|
57
|
+
$ bundle exec ruby demo/demo.rb
|
58
|
+
|
59
|
+
This will start a sinatra server locally on port 4567.
|
60
|
+
You can now visit URLs like http://localhost:4567/around?q=Paris.
|
61
|
+
|
62
|
+
See `demo/demo.rb` for available methods.
|
63
|
+
They generally correspond to one public `GeoFaker` method and pass the query parameters along to that method.
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/zweitag/GeoFaker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
68
|
+
|
69
|
+
## License
|
70
|
+
|
71
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
72
|
+
|
73
|
+
## Code of Conduct
|
74
|
+
|
75
|
+
Everyone interacting in the GeoFaker project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/geo_faker/blob/master/CODE_OF_CONDUCT.md).
|
76
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "geo_faker"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/demo/demo.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'geo_faker'
|
3
|
+
|
4
|
+
set :public_folder, File.dirname(__FILE__) + '/public'
|
5
|
+
|
6
|
+
get '/api/within' do
|
7
|
+
content_type :json
|
8
|
+
|
9
|
+
query = params[:q]
|
10
|
+
|
11
|
+
data = GeoFaker.geo_data(query, with_polygon: true)
|
12
|
+
count = (params[:count] || 100).to_i
|
13
|
+
|
14
|
+
return {
|
15
|
+
geojson: data['geojson'],
|
16
|
+
points: (1..count).map {|_| GeoFaker.within(query) },
|
17
|
+
}.to_json
|
18
|
+
end
|
19
|
+
|
20
|
+
get '/api/within_bounds' do
|
21
|
+
content_type :json
|
22
|
+
|
23
|
+
query = params[:q]
|
24
|
+
count = (params[:count] || 100).to_i
|
25
|
+
|
26
|
+
return {
|
27
|
+
bounds: GeoFaker.geo_data(query)['boundingbox'],
|
28
|
+
points: (1..count).map {|_| GeoFaker.within_bounds(query) },
|
29
|
+
}.to_json
|
30
|
+
end
|
31
|
+
|
32
|
+
get '/api/around' do
|
33
|
+
content_type :json
|
34
|
+
|
35
|
+
query = params[:q]
|
36
|
+
radius = (params[:radius] || 10).to_f
|
37
|
+
count = (params[:count] || 100).to_i
|
38
|
+
|
39
|
+
return {
|
40
|
+
points: (1..count).map {|_| GeoFaker.around(query, radius_in_km: radius) },
|
41
|
+
circle: {
|
42
|
+
center: GeoFaker.geo_data(query).slice('lat', 'lon'),
|
43
|
+
radius: radius,
|
44
|
+
},
|
45
|
+
}.to_json
|
46
|
+
end
|
47
|
+
|
48
|
+
# Allow calling api methods without the /api, to render a map in which the
|
49
|
+
# result of the respective api call will be visualised
|
50
|
+
get '/*' do
|
51
|
+
pass if request.path_info.start_with?('/api')
|
52
|
+
content_type :html
|
53
|
+
send_file(File.dirname(__FILE__) + '/public/index.html')
|
54
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>GeoFaker Demo</title>
|
4
|
+
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7
|
+
|
8
|
+
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
|
9
|
+
|
10
|
+
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css" integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==" crossorigin=""/>
|
11
|
+
<script src="https://unpkg.com/leaflet@1.3.4/dist/leaflet.js" integrity="sha512-nMMmRyTVoLYqjP9hrbed9S+FzjZHW5gY1TWCHA5ckwXZBadntCNs8kEqAWdrb9O7rxbCaA4lKTIWjDXZxflOcA==" crossorigin=""></script>
|
12
|
+
</head>
|
13
|
+
<body>
|
14
|
+
<div id="mapid" style="width: 100%; height: 100%;"></div>
|
15
|
+
<script src="/index.js"></script>
|
16
|
+
</body>
|
17
|
+
</html>
|
18
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
var map = L.map('mapid').setView([51.505, -0.09], 13);
|
2
|
+
|
3
|
+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
4
|
+
maxZoom: 18,
|
5
|
+
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
6
|
+
}).addTo(map);
|
7
|
+
|
8
|
+
function loadData(data) {
|
9
|
+
const group = L.featureGroup();
|
10
|
+
group.addTo(map);
|
11
|
+
|
12
|
+
data.points.forEach(({lat, lon}) => {
|
13
|
+
L.marker([lat, lon]).addTo(group)
|
14
|
+
});
|
15
|
+
|
16
|
+
if (data.bounds) {
|
17
|
+
const bounds = data.bounds;
|
18
|
+
L.rectangle([
|
19
|
+
[bounds[0], bounds[2]],
|
20
|
+
[bounds[1], bounds[3]],
|
21
|
+
]).addTo(group);
|
22
|
+
}
|
23
|
+
|
24
|
+
if (data.geojson) {
|
25
|
+
L.geoJSON(data.geojson).addTo(group);
|
26
|
+
}
|
27
|
+
|
28
|
+
if (data.circle) {
|
29
|
+
L.circle(
|
30
|
+
[
|
31
|
+
data.circle.center.lat,
|
32
|
+
data.circle.center.lon,
|
33
|
+
],
|
34
|
+
data.circle.radius * 1000,
|
35
|
+
).addTo(group);
|
36
|
+
|
37
|
+
L.circle(
|
38
|
+
[
|
39
|
+
data.circle.center.lat,
|
40
|
+
data.circle.center.lon,
|
41
|
+
],
|
42
|
+
data.circle.radius * 1000 * 2,
|
43
|
+
{ opacity: 0.4 },
|
44
|
+
).addTo(group);
|
45
|
+
|
46
|
+
L.circle(
|
47
|
+
[
|
48
|
+
data.circle.center.lat,
|
49
|
+
data.circle.center.lon,
|
50
|
+
],
|
51
|
+
data.circle.radius * 1000 * 3,
|
52
|
+
{ opacity: 0.2 },
|
53
|
+
).addTo(group);
|
54
|
+
}
|
55
|
+
|
56
|
+
map.fitBounds(group.getBounds().pad(0.5));
|
57
|
+
}
|
58
|
+
|
59
|
+
window.onload = () => {
|
60
|
+
// Call the api indicated in the URL along with the query parameters and display the result.
|
61
|
+
fetch(`/api${location.pathname}${location.search}`).then(resp => resp.json()).then(loadData);
|
62
|
+
};
|
data/geo_faker.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "geo_faker/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "geo_faker"
|
7
|
+
spec.version = GeoFaker::VERSION
|
8
|
+
spec.authors = ['Simon Bungartz', 'Tim Landwerth']
|
9
|
+
spec.email = ['simon.bungartz@zweitag.de', 'tim.landwerth@zweitag.de']
|
10
|
+
spec.summary = 'Improve your test and demo data by generating realistically distributed geo-coordinates '
|
11
|
+
spec.description = 'Improve your test and demo data by generating realistically distributed geo-coordinates '
|
12
|
+
spec.homepage = 'https://github.com/zweitag/GeoFaker'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
16
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = 'https://github.com/zweitag/GeoFaker'
|
21
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
22
|
+
else
|
23
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
24
|
+
end
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_dependency 'rest-client'
|
36
|
+
|
37
|
+
spec.add_development_dependency 'bundler'
|
38
|
+
spec.add_development_dependency 'rake'
|
39
|
+
spec.add_development_dependency 'rspec'
|
40
|
+
spec.add_development_dependency 'pry'
|
41
|
+
spec.add_development_dependency 'sinatra'
|
42
|
+
spec.add_development_dependency 'vcr'
|
43
|
+
spec.add_development_dependency 'webmock'
|
44
|
+
end
|
data/lib/geo_faker.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'geo_faker/version'
|
2
|
+
require 'geo_faker/geo_transform'
|
3
|
+
require 'geo_faker/point'
|
4
|
+
require 'rest-client'
|
5
|
+
require 'json'
|
6
|
+
require 'pry'
|
7
|
+
|
8
|
+
module GeoFaker
|
9
|
+
BASE_URL = 'https://nominatim.openstreetmap.org/search'
|
10
|
+
|
11
|
+
@@geo_data = {}
|
12
|
+
|
13
|
+
def self.geo_data(query, with_polygon: false)
|
14
|
+
@@geo_data[query] ||= load_geo_data(query, with_polygon: with_polygon)
|
15
|
+
if with_polygon && !@@geo_data[query].key?('geojson')
|
16
|
+
@@geo_data[query] = load_geo_data(query, with_polygon: with_polygon)
|
17
|
+
end
|
18
|
+
@@geo_data[query]
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.load_geo_data(query, with_polygon: false)
|
22
|
+
response = RestClient.get(BASE_URL, params: {
|
23
|
+
q: query,
|
24
|
+
format: 'json',
|
25
|
+
limit: 1,
|
26
|
+
polygon_geojson: with_polygon ? '1' : '0',
|
27
|
+
})
|
28
|
+
|
29
|
+
raise "API error: #{response.code}" unless response.code == 200
|
30
|
+
|
31
|
+
data = JSON.parse(response.body)
|
32
|
+
raise "No matching result." if data.empty?
|
33
|
+
data.first
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.around(query, radius_in_km:)
|
37
|
+
data = geo_data(query)
|
38
|
+
lat = data['lat'].to_f
|
39
|
+
lon = data['lon'].to_f
|
40
|
+
|
41
|
+
angle = 2 * Math::PI * rand()
|
42
|
+
distance = nil
|
43
|
+
loop do
|
44
|
+
distance = radius_in_km * gaussian_rand()
|
45
|
+
break if distance.abs < 3 * radius_in_km
|
46
|
+
end
|
47
|
+
|
48
|
+
delta_lat = GeoTransform.km_to_degree_lat(distance * Math.cos(angle))
|
49
|
+
delta_lon = GeoTransform.km_to_degree_lon(distance * Math.sin(angle), lat)
|
50
|
+
|
51
|
+
Point.new(
|
52
|
+
lat: lat + delta_lat,
|
53
|
+
lon: lon + delta_lon,
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.gaussian_rand
|
58
|
+
theta = 2 * Math::PI * rand
|
59
|
+
rho = Math.sqrt(-2 * Math.log(1 - rand))
|
60
|
+
x = rho * Math.cos(theta)
|
61
|
+
#y = rho * Math.sin(theta)
|
62
|
+
x
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.within_bounds(query)
|
66
|
+
data = geo_data(query)
|
67
|
+
bounds = data['boundingbox'].map(&:to_f)
|
68
|
+
|
69
|
+
south = bounds[0]
|
70
|
+
north = bounds[1]
|
71
|
+
west = bounds[2]
|
72
|
+
east = bounds[3]
|
73
|
+
|
74
|
+
Point.new(
|
75
|
+
lat: rand(south..north),
|
76
|
+
lon: rand(west..east),
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.within(query)
|
81
|
+
data = geo_data(query, with_polygon: true)
|
82
|
+
|
83
|
+
bounds = data['boundingbox'].map(&:to_f)
|
84
|
+
south = bounds[0]
|
85
|
+
north = bounds[1]
|
86
|
+
west = bounds[2]
|
87
|
+
east = bounds[3]
|
88
|
+
|
89
|
+
geojson = data['geojson']
|
90
|
+
raise 'geojson is not Polygon' unless geojson['type'] == 'Polygon'
|
91
|
+
outer_poly = geojson['coordinates'][0]
|
92
|
+
|
93
|
+
loop do
|
94
|
+
point = Point.new(
|
95
|
+
lat: rand(south..north),
|
96
|
+
lon: rand(west..east),
|
97
|
+
)
|
98
|
+
|
99
|
+
return point if point_in_poly(outer_poly, point)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.point_in_poly(poly, point)
|
104
|
+
last_point = poly[-1]
|
105
|
+
oddNodes = false
|
106
|
+
y = point.lon
|
107
|
+
x = point.lat
|
108
|
+
|
109
|
+
poly.each do |p|
|
110
|
+
yi = p[0]
|
111
|
+
xi = p[1]
|
112
|
+
yj = last_point[0]
|
113
|
+
xj = last_point[1]
|
114
|
+
if yi < y && yj >= y ||
|
115
|
+
yj < y && yi >= y
|
116
|
+
oddNodes = !oddNodes if xi + (y - yi) / (yj - yi) * (xj - xi) < x
|
117
|
+
end
|
118
|
+
last_point = p
|
119
|
+
end
|
120
|
+
|
121
|
+
oddNodes
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module GeoFaker
|
2
|
+
class GeoTransform
|
3
|
+
KM_PER_DEGREE_LAT = 110.574
|
4
|
+
KM_PER_DEGREE_LON_AT_EQUATOR = 111.320
|
5
|
+
|
6
|
+
def self.km_to_degree_lat(delta_km)
|
7
|
+
delta_km / KM_PER_DEGREE_LAT
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.km_to_degree_lon(delta_km, lat)
|
11
|
+
delta_km / (KM_PER_DEGREE_LON_AT_EQUATOR * Math.cos(lat * Math::PI / 180))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geo_faker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simon Bungartz
|
8
|
+
- Tim Landwerth
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-11-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: pry
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: sinatra
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: vcr
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: webmock
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: 'Improve your test and demo data by generating realistically distributed
|
127
|
+
geo-coordinates '
|
128
|
+
email:
|
129
|
+
- simon.bungartz@zweitag.de
|
130
|
+
- tim.landwerth@zweitag.de
|
131
|
+
executables: []
|
132
|
+
extensions: []
|
133
|
+
extra_rdoc_files: []
|
134
|
+
files:
|
135
|
+
- ".gitignore"
|
136
|
+
- ".rspec"
|
137
|
+
- ".ruby-version"
|
138
|
+
- ".travis.yml"
|
139
|
+
- CODE_OF_CONDUCT.md
|
140
|
+
- Gemfile
|
141
|
+
- Gemfile.lock
|
142
|
+
- LICENSE.txt
|
143
|
+
- README.md
|
144
|
+
- Rakefile
|
145
|
+
- bin/console
|
146
|
+
- bin/setup
|
147
|
+
- demo/demo.rb
|
148
|
+
- demo/public/index.html
|
149
|
+
- demo/public/index.js
|
150
|
+
- geo_faker.gemspec
|
151
|
+
- lib/geo_faker.rb
|
152
|
+
- lib/geo_faker/geo_transform.rb
|
153
|
+
- lib/geo_faker/point.rb
|
154
|
+
- lib/geo_faker/version.rb
|
155
|
+
homepage: https://github.com/zweitag/GeoFaker
|
156
|
+
licenses:
|
157
|
+
- MIT
|
158
|
+
metadata:
|
159
|
+
homepage_uri: https://github.com/zweitag/GeoFaker
|
160
|
+
source_code_uri: https://github.com/zweitag/GeoFaker
|
161
|
+
post_install_message:
|
162
|
+
rdoc_options: []
|
163
|
+
require_paths:
|
164
|
+
- lib
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
requirements: []
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 2.7.6
|
178
|
+
signing_key:
|
179
|
+
specification_version: 4
|
180
|
+
summary: Improve your test and demo data by generating realistically distributed geo-coordinates
|
181
|
+
test_files: []
|