Skip to content

Instantly share code, notes, and snippets.

@fujimura
Created March 2, 2018 11:30
Show Gist options
  • Save fujimura/bc238dd5d6a75aac31051d36d04a737a to your computer and use it in GitHub Desktop.
Save fujimura/bc238dd5d6a75aac31051d36d04a737a to your computer and use it in GitHub Desktop.
require 'json'
def get_lonlat_in_spiral(i)
v = Complex.polar i, i/4.9 * Math::PI/2
angle = v.angle
magnitude = v.magnitude
[magnitude * Math.cos(angle), magnitude * Math.sin(angle)]
end
r = 10.upto(30).map { |i| get_lonlat_in_spiral(i) }
coords = r.map {|x, y| [139.6 + y * 0.01, 35.7 + x * 0.01] }
puts JSON.generate(
type: "MultiPolygon",
coordinates: [coords.map {|y, x| [y.floor(5), x.floor(5)] }.map { |y, x|
[
[y, x],
[y, x + 0.01],
[y - 0.01, x + 0.01],
[y - 0.01, x],
[y, x]
]
}]
)
Display the source blob
Display the rendered blob
Raw
{
"type": "MultiPolygon",
"coordinates": [
[
[
[
139.59359,
35.6002
],
[
139.59359,
35.6102
],
[
139.58359000000002,
35.6102
],
[
139.58359000000002,
35.6002
],
[
139.59359,
35.6002
]
],
[
[
139.55872,
35.59803
],
[
139.55872,
35.60803
],
[
139.54872,
35.60803
],
[
139.54872,
35.59803
],
[
139.55872,
35.59803
]
],
[
[
139.52221,
35.60862
],
[
139.52221,
35.61862
],
[
139.51221,
35.61862
],
[
139.51221,
35.60862
],
[
139.52221,
35.60862
]
],
[
[
139.48883,
35.6326
],
[
139.48883,
35.642599999999995
],
[
139.47883000000002,
35.642599999999995
],
[
139.47883000000002,
35.6326
],
[
139.48883,
35.6326
]
],
[
[
139.46351,
35.66884
],
[
139.46351,
35.67884
],
[
139.45351000000002,
35.67884
],
[
139.45351000000002,
35.66884
],
[
139.46351,
35.66884
]
],
[
[
139.45069,
35.7144
],
[
139.45069,
35.724399999999996
],
[
139.44069000000002,
35.724399999999996
],
[
139.44069000000002,
35.7144
],
[
139.45069,
35.7144
]
],
[
[
139.45369,
35.76476
],
[
139.45369,
35.77476
],
[
139.44369,
35.77476
],
[
139.44369,
35.76476
],
[
139.45369,
35.76476
]
],
[
[
139.47415,
35.81429
],
[
139.47415,
35.82429
],
[
139.46415000000002,
35.82429
],
[
139.46415000000002,
35.81429
],
[
139.47415,
35.81429
]
],
[
[
139.51167,
35.85683
],
[
139.51167,
35.86683
],
[
139.50167000000002,
35.86683
],
[
139.50167000000002,
35.85683
],
[
139.51167,
35.85683
]
],
[
[
139.56367,
35.88649
],
[
139.56367,
35.89649
],
[
139.55367,
35.89649
],
[
139.55367,
35.88649
],
[
139.56367,
35.88649
]
],
[
[
139.62557,
35.89835
],
[
139.62557,
35.90835
],
[
139.61557000000002,
35.90835
],
[
139.61557000000002,
35.89835
],
[
139.62557,
35.89835
]
],
[
[
139.69111,
35.8892
],
[
139.69111,
35.8992
],
[
139.68111000000002,
35.8992
],
[
139.68111000000002,
35.8892
],
[
139.69111,
35.8892
]
],
[
[
139.75305,
35.85803
],
[
139.75305,
35.86803
],
[
139.74305,
35.86803
],
[
139.74305,
35.85803
],
[
139.75305,
35.85803
]
],
[
[
139.80391,
35.80638
],
[
139.80391,
35.816379999999995
],
[
139.79391,
35.816379999999995
],
[
139.79391,
35.80638
],
[
139.80391,
35.80638
]
],
[
[
139.83692,
35.7383
],
[
139.83692,
35.7483
],
[
139.82692,
35.7483
],
[
139.82692,
35.7383
],
[
139.83692,
35.7383
]
],
[
[
139.84679,
35.6601
],
[
139.84679,
35.6701
],
[
139.83679,
35.6701
],
[
139.83679,
35.6601
],
[
139.84679,
35.6601
]
],
[
[
139.83051,
35.57974
],
[
139.83051,
35.58974
],
[
139.82051,
35.58974
],
[
139.82051,
35.57974
],
[
139.83051,
35.57974
]
],
[
[
139.78783,
35.50604
],
[
139.78783,
35.51604
],
[
139.77783000000002,
35.51604
],
[
139.77783000000002,
35.50604
],
[
139.78783,
35.50604
]
],
[
[
139.72148,
35.44772
],
[
139.72148,
35.457719999999995
],
[
139.71148000000002,
35.457719999999995
],
[
139.71148000000002,
35.44772
],
[
139.72148,
35.44772
]
],
[
[
139.63708,
35.41238
],
[
139.63708,
35.42238
],
[
139.62708,
35.42238
],
[
139.62708,
35.41238
],
[
139.63708,
35.41238
]
],
[
[
139.54265,
35.40553
],
[
139.54265,
35.41553
],
[
139.53265000000002,
35.41553
],
[
139.53265000000002,
35.40553
],
[
139.54265,
35.40553
]
]
]
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment