libgd-gis 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +127 -0
- data/examples/argentina.png +0 -0
- data/examples/argentina.rb +82 -0
- data/examples/argentina_con_localidades.rb +89 -0
- data/examples/argentina_museos.rb +70 -0
- data/examples/flag.png +0 -0
- data/examples/hydro.png +0 -0
- data/examples/hydro_plants.geojson +25 -0
- data/examples/localidades.json +1 -0
- data/examples/museos.png +0 -0
- data/examples/museos_datosabiertos.csv +1183 -0
- data/examples/output/argentina.png +0 -0
- data/examples/output/argentina_localidades.png +0 -0
- data/examples/output/argentina_museos.png +0 -0
- data/examples/output/tanzania_hydro.png +0 -0
- data/examples/render_tile.rb +31 -0
- data/examples/tanzania.rb +32 -0
- data/examples/target.rb +19 -0
- data/examples/tmp/tiles/7_27_43.png +0 -0
- data/examples/tmp/tiles/7_27_44.png +0 -0
- data/examples/tmp/tiles/7_27_45.png +0 -0
- data/examples/tmp/tiles/7_27_46.png +0 -0
- data/examples/tmp/tiles/7_27_47.png +0 -0
- data/examples/tmp/tiles/7_27_48.png +0 -0
- data/examples/tmp/tiles/7_27_49.png +0 -0
- data/examples/tmp/tiles/7_27_50.png +0 -0
- data/examples/tmp/tiles/7_28_43.png +0 -0
- data/examples/tmp/tiles/7_28_44.png +0 -0
- data/examples/tmp/tiles/7_28_45.png +0 -0
- data/examples/tmp/tiles/7_28_46.png +0 -0
- data/examples/tmp/tiles/7_28_47.png +0 -0
- data/examples/tmp/tiles/7_28_48.png +0 -0
- data/examples/tmp/tiles/7_28_49.png +0 -0
- data/examples/tmp/tiles/7_28_50.png +0 -0
- data/examples/tmp/tiles/7_29_43.png +0 -0
- data/examples/tmp/tiles/7_29_44.png +0 -0
- data/examples/tmp/tiles/7_29_45.png +0 -0
- data/examples/tmp/tiles/7_29_46.png +0 -0
- data/examples/tmp/tiles/7_29_47.png +0 -0
- data/examples/tmp/tiles/7_29_48.png +0 -0
- data/examples/tmp/tiles/7_29_49.png +0 -0
- data/examples/tmp/tiles/7_29_50.png +0 -0
- data/examples/tmp/tiles/7_30_43.png +0 -0
- data/examples/tmp/tiles/7_30_44.png +0 -0
- data/examples/tmp/tiles/7_30_45.png +0 -0
- data/examples/tmp/tiles/7_30_46.png +0 -0
- data/examples/tmp/tiles/7_30_47.png +0 -0
- data/examples/tmp/tiles/7_30_48.png +0 -0
- data/examples/tmp/tiles/7_30_49.png +0 -0
- data/examples/tmp/tiles/7_30_50.png +0 -0
- data/examples/tmp/tiles/7_31_43.png +0 -0
- data/examples/tmp/tiles/7_31_44.png +0 -0
- data/examples/tmp/tiles/7_31_45.png +0 -0
- data/examples/tmp/tiles/7_31_46.png +0 -0
- data/examples/tmp/tiles/7_31_47.png +0 -0
- data/examples/tmp/tiles/7_31_48.png +0 -0
- data/examples/tmp/tiles/7_31_49.png +0 -0
- data/examples/tmp/tiles/7_31_50.png +0 -0
- data/examples/tmp/tiles/7_32_43.png +0 -0
- data/examples/tmp/tiles/7_32_44.png +0 -0
- data/examples/tmp/tiles/7_32_45.png +0 -0
- data/examples/tmp/tiles/7_32_46.png +0 -0
- data/examples/tmp/tiles/7_32_47.png +0 -0
- data/examples/tmp/tiles/7_32_48.png +0 -0
- data/examples/tmp/tiles/7_32_49.png +0 -0
- data/examples/tmp/tiles/7_32_50.png +0 -0
- data/examples/tmp/tiles/7_37_71.png +0 -0
- data/examples/tmp/tiles/7_37_72.png +0 -0
- data/examples/tmp/tiles/7_37_73.png +0 -0
- data/examples/tmp/tiles/7_37_74.png +0 -0
- data/examples/tmp/tiles/7_37_75.png +0 -0
- data/examples/tmp/tiles/7_37_76.png +0 -0
- data/examples/tmp/tiles/7_37_77.png +0 -0
- data/examples/tmp/tiles/7_37_78.png +0 -0
- data/examples/tmp/tiles/7_37_79.png +0 -0
- data/examples/tmp/tiles/7_37_80.png +0 -0
- data/examples/tmp/tiles/7_37_81.png +0 -0
- data/examples/tmp/tiles/7_37_82.png +0 -0
- data/examples/tmp/tiles/7_37_83.png +0 -0
- data/examples/tmp/tiles/7_37_84.png +0 -0
- data/examples/tmp/tiles/7_37_85.png +0 -0
- data/examples/tmp/tiles/7_37_86.png +0 -0
- data/examples/tmp/tiles/7_37_87.png +0 -0
- data/examples/tmp/tiles/7_38_71.png +0 -0
- data/examples/tmp/tiles/7_38_72.png +0 -0
- data/examples/tmp/tiles/7_38_73.png +0 -0
- data/examples/tmp/tiles/7_38_74.png +0 -0
- data/examples/tmp/tiles/7_38_75.png +0 -0
- data/examples/tmp/tiles/7_38_76.png +0 -0
- data/examples/tmp/tiles/7_38_77.png +0 -0
- data/examples/tmp/tiles/7_38_78.png +0 -0
- data/examples/tmp/tiles/7_38_79.png +0 -0
- data/examples/tmp/tiles/7_38_80.png +0 -0
- data/examples/tmp/tiles/7_38_81.png +0 -0
- data/examples/tmp/tiles/7_38_82.png +0 -0
- data/examples/tmp/tiles/7_38_83.png +0 -0
- data/examples/tmp/tiles/7_38_84.png +0 -0
- data/examples/tmp/tiles/7_38_85.png +0 -0
- data/examples/tmp/tiles/7_38_86.png +0 -0
- data/examples/tmp/tiles/7_38_87.png +0 -0
- data/examples/tmp/tiles/7_39_71.png +0 -0
- data/examples/tmp/tiles/7_39_72.png +0 -0
- data/examples/tmp/tiles/7_39_73.png +0 -0
- data/examples/tmp/tiles/7_39_74.png +0 -0
- data/examples/tmp/tiles/7_39_75.png +0 -0
- data/examples/tmp/tiles/7_39_76.png +0 -0
- data/examples/tmp/tiles/7_39_77.png +0 -0
- data/examples/tmp/tiles/7_39_78.png +0 -0
- data/examples/tmp/tiles/7_39_79.png +0 -0
- data/examples/tmp/tiles/7_39_80.png +0 -0
- data/examples/tmp/tiles/7_39_81.png +0 -0
- data/examples/tmp/tiles/7_39_82.png +0 -0
- data/examples/tmp/tiles/7_39_83.png +0 -0
- data/examples/tmp/tiles/7_39_84.png +0 -0
- data/examples/tmp/tiles/7_39_85.png +0 -0
- data/examples/tmp/tiles/7_39_86.png +0 -0
- data/examples/tmp/tiles/7_39_87.png +0 -0
- data/examples/tmp/tiles/7_40_71.png +0 -0
- data/examples/tmp/tiles/7_40_72.png +0 -0
- data/examples/tmp/tiles/7_40_73.png +0 -0
- data/examples/tmp/tiles/7_40_74.png +0 -0
- data/examples/tmp/tiles/7_40_75.png +0 -0
- data/examples/tmp/tiles/7_40_76.png +0 -0
- data/examples/tmp/tiles/7_40_77.png +0 -0
- data/examples/tmp/tiles/7_40_78.png +0 -0
- data/examples/tmp/tiles/7_40_79.png +0 -0
- data/examples/tmp/tiles/7_40_80.png +0 -0
- data/examples/tmp/tiles/7_40_81.png +0 -0
- data/examples/tmp/tiles/7_40_82.png +0 -0
- data/examples/tmp/tiles/7_40_83.png +0 -0
- data/examples/tmp/tiles/7_40_84.png +0 -0
- data/examples/tmp/tiles/7_40_85.png +0 -0
- data/examples/tmp/tiles/7_40_86.png +0 -0
- data/examples/tmp/tiles/7_40_87.png +0 -0
- data/examples/tmp/tiles/7_41_71.png +0 -0
- data/examples/tmp/tiles/7_41_72.png +0 -0
- data/examples/tmp/tiles/7_41_73.png +0 -0
- data/examples/tmp/tiles/7_41_74.png +0 -0
- data/examples/tmp/tiles/7_41_75.png +0 -0
- data/examples/tmp/tiles/7_41_76.png +0 -0
- data/examples/tmp/tiles/7_41_77.png +0 -0
- data/examples/tmp/tiles/7_41_78.png +0 -0
- data/examples/tmp/tiles/7_41_79.png +0 -0
- data/examples/tmp/tiles/7_41_80.png +0 -0
- data/examples/tmp/tiles/7_41_81.png +0 -0
- data/examples/tmp/tiles/7_41_82.png +0 -0
- data/examples/tmp/tiles/7_41_83.png +0 -0
- data/examples/tmp/tiles/7_41_84.png +0 -0
- data/examples/tmp/tiles/7_41_85.png +0 -0
- data/examples/tmp/tiles/7_41_86.png +0 -0
- data/examples/tmp/tiles/7_41_87.png +0 -0
- data/examples/tmp/tiles/7_42_71.png +0 -0
- data/examples/tmp/tiles/7_42_72.png +0 -0
- data/examples/tmp/tiles/7_42_73.png +0 -0
- data/examples/tmp/tiles/7_42_74.png +0 -0
- data/examples/tmp/tiles/7_42_75.png +0 -0
- data/examples/tmp/tiles/7_42_76.png +0 -0
- data/examples/tmp/tiles/7_42_77.png +0 -0
- data/examples/tmp/tiles/7_42_78.png +0 -0
- data/examples/tmp/tiles/7_42_79.png +0 -0
- data/examples/tmp/tiles/7_42_80.png +0 -0
- data/examples/tmp/tiles/7_42_81.png +0 -0
- data/examples/tmp/tiles/7_42_82.png +0 -0
- data/examples/tmp/tiles/7_42_83.png +0 -0
- data/examples/tmp/tiles/7_42_84.png +0 -0
- data/examples/tmp/tiles/7_42_85.png +0 -0
- data/examples/tmp/tiles/7_42_86.png +0 -0
- data/examples/tmp/tiles/7_42_87.png +0 -0
- data/examples/tmp/tiles/7_43_71.png +0 -0
- data/examples/tmp/tiles/7_43_72.png +0 -0
- data/examples/tmp/tiles/7_43_73.png +0 -0
- data/examples/tmp/tiles/7_43_74.png +0 -0
- data/examples/tmp/tiles/7_43_75.png +0 -0
- data/examples/tmp/tiles/7_43_76.png +0 -0
- data/examples/tmp/tiles/7_43_77.png +0 -0
- data/examples/tmp/tiles/7_43_78.png +0 -0
- data/examples/tmp/tiles/7_43_79.png +0 -0
- data/examples/tmp/tiles/7_43_80.png +0 -0
- data/examples/tmp/tiles/7_43_81.png +0 -0
- data/examples/tmp/tiles/7_43_82.png +0 -0
- data/examples/tmp/tiles/7_43_83.png +0 -0
- data/examples/tmp/tiles/7_43_84.png +0 -0
- data/examples/tmp/tiles/7_43_85.png +0 -0
- data/examples/tmp/tiles/7_43_86.png +0 -0
- data/examples/tmp/tiles/7_43_87.png +0 -0
- data/examples/tmp/tiles/7_44_71.png +0 -0
- data/examples/tmp/tiles/7_44_72.png +0 -0
- data/examples/tmp/tiles/7_44_73.png +0 -0
- data/examples/tmp/tiles/7_44_74.png +0 -0
- data/examples/tmp/tiles/7_44_75.png +0 -0
- data/examples/tmp/tiles/7_44_76.png +0 -0
- data/examples/tmp/tiles/7_44_77.png +0 -0
- data/examples/tmp/tiles/7_44_78.png +0 -0
- data/examples/tmp/tiles/7_44_79.png +0 -0
- data/examples/tmp/tiles/7_44_80.png +0 -0
- data/examples/tmp/tiles/7_44_81.png +0 -0
- data/examples/tmp/tiles/7_44_82.png +0 -0
- data/examples/tmp/tiles/7_44_83.png +0 -0
- data/examples/tmp/tiles/7_44_84.png +0 -0
- data/examples/tmp/tiles/7_44_85.png +0 -0
- data/examples/tmp/tiles/7_44_86.png +0 -0
- data/examples/tmp/tiles/7_44_87.png +0 -0
- data/examples/tmp/tiles/7_75_64.png +0 -0
- data/examples/tmp/tiles/7_75_65.png +0 -0
- data/examples/tmp/tiles/7_75_66.png +0 -0
- data/examples/tmp/tiles/7_75_67.png +0 -0
- data/examples/tmp/tiles/7_75_68.png +0 -0
- data/examples/tmp/tiles/7_76_64.png +0 -0
- data/examples/tmp/tiles/7_76_65.png +0 -0
- data/examples/tmp/tiles/7_76_66.png +0 -0
- data/examples/tmp/tiles/7_76_67.png +0 -0
- data/examples/tmp/tiles/7_76_68.png +0 -0
- data/examples/tmp/tiles/7_77_64.png +0 -0
- data/examples/tmp/tiles/7_77_65.png +0 -0
- data/examples/tmp/tiles/7_77_66.png +0 -0
- data/examples/tmp/tiles/7_77_67.png +0 -0
- data/examples/tmp/tiles/7_77_68.png +0 -0
- data/lib/gd/gis/basemap.rb +61 -0
- data/lib/gd/gis/layer_points.rb +25 -0
- data/lib/gd/gis/map.rb +108 -0
- data/lib/gd/gis/projection.rb +25 -0
- data/lib/gd/gis.rb +3 -0
- data/lib/libgd_gis.rb +44 -0
- metadata +281 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require "net/http"
|
|
2
|
+
require "fileutils"
|
|
3
|
+
|
|
4
|
+
module GD
|
|
5
|
+
module GIS
|
|
6
|
+
class Basemap
|
|
7
|
+
TILE_SIZE = 256
|
|
8
|
+
|
|
9
|
+
def initialize(zoom, bbox, provider=:carto_light)
|
|
10
|
+
@zoom = zoom
|
|
11
|
+
@bbox = bbox
|
|
12
|
+
@provider = provider
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def url(z,x,y)
|
|
16
|
+
"https://basemaps.cartocdn.com/light_all/#{z}/#{x}/#{y}.png"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def lon2tile(lon)
|
|
20
|
+
((lon + 180.0) / 360.0 * (2 ** @zoom)).floor
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def lat2tile(lat)
|
|
24
|
+
rad = lat * Math::PI / 180
|
|
25
|
+
((1 - Math.log(Math.tan(rad) + 1 / Math.cos(rad)) / Math::PI) / 2 * (2 ** @zoom)).floor
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def fetch_tiles
|
|
29
|
+
west, south, east, north = @bbox
|
|
30
|
+
|
|
31
|
+
x_min = lon2tile(west)
|
|
32
|
+
x_max = lon2tile(east)
|
|
33
|
+
y_min = lat2tile(north)
|
|
34
|
+
y_max = lat2tile(south)
|
|
35
|
+
|
|
36
|
+
@x_min = x_min
|
|
37
|
+
@y_min = y_min
|
|
38
|
+
|
|
39
|
+
FileUtils.mkdir_p("tmp/tiles")
|
|
40
|
+
|
|
41
|
+
tiles = []
|
|
42
|
+
|
|
43
|
+
(x_min..x_max).each do |x|
|
|
44
|
+
(y_min..y_max).each do |y|
|
|
45
|
+
path = "tmp/tiles/#{@zoom}_#{x}_#{y}.png"
|
|
46
|
+
unless File.exist?(path)
|
|
47
|
+
uri = URI(url(@zoom,x,y))
|
|
48
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
|
49
|
+
res = http.get(uri.path)
|
|
50
|
+
File.binwrite(path, res.body)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
tiles << [x,y,path]
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
[tiles, x_min, y_min]
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module GD
|
|
2
|
+
module GIS
|
|
3
|
+
class PointsLayer
|
|
4
|
+
def initialize(data, lon:, lat:, icon:)
|
|
5
|
+
@data = data
|
|
6
|
+
@lon = lon
|
|
7
|
+
@lat = lat
|
|
8
|
+
@icon = GD::Image.open(icon)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def render!(img, projection)
|
|
12
|
+
w = @icon.width
|
|
13
|
+
h = @icon.height
|
|
14
|
+
|
|
15
|
+
@data.each do |row|
|
|
16
|
+
lon = @lon.call(row)
|
|
17
|
+
lat = @lat.call(row)
|
|
18
|
+
|
|
19
|
+
x,y = projection.call(lon,lat)
|
|
20
|
+
img.copy(@icon, x - w/2, y - h/2, 0,0,w,h)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/gd/gis/map.rb
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require "gd"
|
|
2
|
+
require_relative "basemap"
|
|
3
|
+
require_relative "projection"
|
|
4
|
+
require_relative "layer_points"
|
|
5
|
+
|
|
6
|
+
module GD
|
|
7
|
+
module GIS
|
|
8
|
+
class Map
|
|
9
|
+
def initialize(bbox:, zoom:, basemap:)
|
|
10
|
+
@bbox = bbox
|
|
11
|
+
@zoom = zoom
|
|
12
|
+
@basemap = Basemap.new(zoom, bbox, basemap)
|
|
13
|
+
@layers = []
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def add_points(data, lon:, lat:, icon:)
|
|
17
|
+
@layers << PointsLayer.new(data, lon: lon, lat: lat, icon: icon)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def render
|
|
21
|
+
tiles, x_min, y_min = @basemap.fetch_tiles
|
|
22
|
+
|
|
23
|
+
cols = tiles.map{|t| t[0]}.uniq.size
|
|
24
|
+
rows = tiles.map{|t| t[1]}.uniq.size
|
|
25
|
+
|
|
26
|
+
width = cols * 256
|
|
27
|
+
height = rows * 256
|
|
28
|
+
|
|
29
|
+
@img = GD::Image.new(width,height)
|
|
30
|
+
|
|
31
|
+
tiles.each do |x,y,path|
|
|
32
|
+
tile = GD::Image.open(path)
|
|
33
|
+
cx = x - x_min
|
|
34
|
+
cy = y - y_min
|
|
35
|
+
@img.copy(tile, cx*256, cy*256, 0,0,256,256)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# projection bbox
|
|
39
|
+
min_x = Projection.mercator_x(@bbox[0])
|
|
40
|
+
max_x = Projection.mercator_x(@bbox[2])
|
|
41
|
+
min_y = Projection.mercator_y(@bbox[1])
|
|
42
|
+
max_y = Projection.mercator_y(@bbox[3])
|
|
43
|
+
|
|
44
|
+
projector = ->(lon,lat) {
|
|
45
|
+
Projection.lonlat_to_pixel(lon,lat,min_x,max_x,min_y,max_y,width,height)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@layers.each { |l| l.render!(@img, projector) }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def tile2lon(x, z)
|
|
52
|
+
x.to_f / (2**z) * 360.0 - 180.0
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def tile2lat(y, z)
|
|
56
|
+
n = Math::PI - (2.0 * Math::PI * y.to_f) / (2**z)
|
|
57
|
+
180.0 / Math::PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)))
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def tile_bbox(z,x,y)
|
|
61
|
+
west = tile2lon(x, z)
|
|
62
|
+
east = tile2lon(x+1, z)
|
|
63
|
+
north = tile2lat(y, z)
|
|
64
|
+
south = tile2lat(y+1, z)
|
|
65
|
+
[west, south, east, north]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def intersect_bbox(a,b)
|
|
69
|
+
[
|
|
70
|
+
[a[0], b[0]].max,
|
|
71
|
+
[a[1], b[1]].max,
|
|
72
|
+
[a[2], b[2]].min,
|
|
73
|
+
[a[3], b[3]].min
|
|
74
|
+
]
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def tile(z,x,y)
|
|
78
|
+
tb = tile_bbox(z,x,y)
|
|
79
|
+
ib = intersect_bbox(@bbox, tb)
|
|
80
|
+
|
|
81
|
+
# Si no hay intersección, devolvemos tile vacío
|
|
82
|
+
if ib[0] >= ib[2] || ib[1] >= ib[3]
|
|
83
|
+
return GD::Image.new(256,256)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
submap = GD::GIS::Map.new(
|
|
87
|
+
bbox: ib,
|
|
88
|
+
zoom: z,
|
|
89
|
+
basemap: :carto_light
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
# copiar capas
|
|
93
|
+
@layers.each { |l| submap.instance_variable_get(:@layers) << l }
|
|
94
|
+
|
|
95
|
+
submap.render
|
|
96
|
+
|
|
97
|
+
# recortar al tamaño exacto del tile
|
|
98
|
+
img = GD::Image.new(256,256)
|
|
99
|
+
img.copy(submap.instance_variable_get(:@img), 0,0,0,0,256,256)
|
|
100
|
+
img
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def save(path)
|
|
104
|
+
@img.save(path)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module GD
|
|
2
|
+
module GIS
|
|
3
|
+
module Projection
|
|
4
|
+
R = 6378137.0
|
|
5
|
+
|
|
6
|
+
def self.mercator_x(lon)
|
|
7
|
+
lon * Math::PI / 180.0 * R
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.mercator_y(lat)
|
|
11
|
+
Math.log(Math.tan(Math::PI/4 + lat * Math::PI / 360.0)) * R
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.lonlat_to_pixel(lon, lat, min_x, max_x, min_y, max_y, width, height)
|
|
15
|
+
x = mercator_x(lon)
|
|
16
|
+
y = mercator_y(lat)
|
|
17
|
+
|
|
18
|
+
px = (x - min_x) / (max_x - min_x) * width
|
|
19
|
+
py = height - (y - min_y) / (max_y - min_y) * height
|
|
20
|
+
|
|
21
|
+
[px.to_i, py.to_i]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/gd/gis.rb
ADDED
data/lib/libgd_gis.rb
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require "libgd_gis"
|
|
2
|
+
|
|
3
|
+
require "open-uri"
|
|
4
|
+
require "tempfile"
|
|
5
|
+
require "gd"
|
|
6
|
+
|
|
7
|
+
module LibGD
|
|
8
|
+
module GIS
|
|
9
|
+
class Tile
|
|
10
|
+
attr_reader :z, :x, :y, :image
|
|
11
|
+
|
|
12
|
+
def self.osm(z:, x:, y:)
|
|
13
|
+
new(
|
|
14
|
+
z: z,
|
|
15
|
+
x: x,
|
|
16
|
+
y: y,
|
|
17
|
+
source: "https://api.maptiler.com/maps/basic/#{z}/#{x}/#{y}.png?key=GetYourOwnKey"
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def initialize(z:, x:, y:, source:)
|
|
22
|
+
@z = z
|
|
23
|
+
@x = x
|
|
24
|
+
@y = y
|
|
25
|
+
@source = source
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def render
|
|
29
|
+
tmp = Tempfile.new(["tile", ".png"])
|
|
30
|
+
tmp.binmode
|
|
31
|
+
tmp.write URI.open(@source).read
|
|
32
|
+
tmp.flush
|
|
33
|
+
|
|
34
|
+
@image = GD::Image.open(tmp.path)
|
|
35
|
+
ensure
|
|
36
|
+
tmp.close
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def save(path)
|
|
40
|
+
@image.save(path)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: libgd-gis
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Germán Alberto Giménez Silva
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-01-06 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: ruby-libgd
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
description: A native GIS raster engine for Ruby built on libgd. Render maps, GeoJSON,
|
|
28
|
+
heatmaps and tiles.
|
|
29
|
+
email:
|
|
30
|
+
- ggerman@gmail.com
|
|
31
|
+
executables: []
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- README.md
|
|
36
|
+
- examples/argentina.png
|
|
37
|
+
- examples/argentina.rb
|
|
38
|
+
- examples/argentina_con_localidades.rb
|
|
39
|
+
- examples/argentina_museos.rb
|
|
40
|
+
- examples/flag.png
|
|
41
|
+
- examples/hydro.png
|
|
42
|
+
- examples/hydro_plants.geojson
|
|
43
|
+
- examples/localidades.json
|
|
44
|
+
- examples/museos.png
|
|
45
|
+
- examples/museos_datosabiertos.csv
|
|
46
|
+
- examples/output/argentina.png
|
|
47
|
+
- examples/output/argentina_localidades.png
|
|
48
|
+
- examples/output/argentina_museos.png
|
|
49
|
+
- examples/output/tanzania_hydro.png
|
|
50
|
+
- examples/render_tile.rb
|
|
51
|
+
- examples/tanzania.rb
|
|
52
|
+
- examples/target.rb
|
|
53
|
+
- examples/tmp/tiles/7_27_43.png
|
|
54
|
+
- examples/tmp/tiles/7_27_44.png
|
|
55
|
+
- examples/tmp/tiles/7_27_45.png
|
|
56
|
+
- examples/tmp/tiles/7_27_46.png
|
|
57
|
+
- examples/tmp/tiles/7_27_47.png
|
|
58
|
+
- examples/tmp/tiles/7_27_48.png
|
|
59
|
+
- examples/tmp/tiles/7_27_49.png
|
|
60
|
+
- examples/tmp/tiles/7_27_50.png
|
|
61
|
+
- examples/tmp/tiles/7_28_43.png
|
|
62
|
+
- examples/tmp/tiles/7_28_44.png
|
|
63
|
+
- examples/tmp/tiles/7_28_45.png
|
|
64
|
+
- examples/tmp/tiles/7_28_46.png
|
|
65
|
+
- examples/tmp/tiles/7_28_47.png
|
|
66
|
+
- examples/tmp/tiles/7_28_48.png
|
|
67
|
+
- examples/tmp/tiles/7_28_49.png
|
|
68
|
+
- examples/tmp/tiles/7_28_50.png
|
|
69
|
+
- examples/tmp/tiles/7_29_43.png
|
|
70
|
+
- examples/tmp/tiles/7_29_44.png
|
|
71
|
+
- examples/tmp/tiles/7_29_45.png
|
|
72
|
+
- examples/tmp/tiles/7_29_46.png
|
|
73
|
+
- examples/tmp/tiles/7_29_47.png
|
|
74
|
+
- examples/tmp/tiles/7_29_48.png
|
|
75
|
+
- examples/tmp/tiles/7_29_49.png
|
|
76
|
+
- examples/tmp/tiles/7_29_50.png
|
|
77
|
+
- examples/tmp/tiles/7_30_43.png
|
|
78
|
+
- examples/tmp/tiles/7_30_44.png
|
|
79
|
+
- examples/tmp/tiles/7_30_45.png
|
|
80
|
+
- examples/tmp/tiles/7_30_46.png
|
|
81
|
+
- examples/tmp/tiles/7_30_47.png
|
|
82
|
+
- examples/tmp/tiles/7_30_48.png
|
|
83
|
+
- examples/tmp/tiles/7_30_49.png
|
|
84
|
+
- examples/tmp/tiles/7_30_50.png
|
|
85
|
+
- examples/tmp/tiles/7_31_43.png
|
|
86
|
+
- examples/tmp/tiles/7_31_44.png
|
|
87
|
+
- examples/tmp/tiles/7_31_45.png
|
|
88
|
+
- examples/tmp/tiles/7_31_46.png
|
|
89
|
+
- examples/tmp/tiles/7_31_47.png
|
|
90
|
+
- examples/tmp/tiles/7_31_48.png
|
|
91
|
+
- examples/tmp/tiles/7_31_49.png
|
|
92
|
+
- examples/tmp/tiles/7_31_50.png
|
|
93
|
+
- examples/tmp/tiles/7_32_43.png
|
|
94
|
+
- examples/tmp/tiles/7_32_44.png
|
|
95
|
+
- examples/tmp/tiles/7_32_45.png
|
|
96
|
+
- examples/tmp/tiles/7_32_46.png
|
|
97
|
+
- examples/tmp/tiles/7_32_47.png
|
|
98
|
+
- examples/tmp/tiles/7_32_48.png
|
|
99
|
+
- examples/tmp/tiles/7_32_49.png
|
|
100
|
+
- examples/tmp/tiles/7_32_50.png
|
|
101
|
+
- examples/tmp/tiles/7_37_71.png
|
|
102
|
+
- examples/tmp/tiles/7_37_72.png
|
|
103
|
+
- examples/tmp/tiles/7_37_73.png
|
|
104
|
+
- examples/tmp/tiles/7_37_74.png
|
|
105
|
+
- examples/tmp/tiles/7_37_75.png
|
|
106
|
+
- examples/tmp/tiles/7_37_76.png
|
|
107
|
+
- examples/tmp/tiles/7_37_77.png
|
|
108
|
+
- examples/tmp/tiles/7_37_78.png
|
|
109
|
+
- examples/tmp/tiles/7_37_79.png
|
|
110
|
+
- examples/tmp/tiles/7_37_80.png
|
|
111
|
+
- examples/tmp/tiles/7_37_81.png
|
|
112
|
+
- examples/tmp/tiles/7_37_82.png
|
|
113
|
+
- examples/tmp/tiles/7_37_83.png
|
|
114
|
+
- examples/tmp/tiles/7_37_84.png
|
|
115
|
+
- examples/tmp/tiles/7_37_85.png
|
|
116
|
+
- examples/tmp/tiles/7_37_86.png
|
|
117
|
+
- examples/tmp/tiles/7_37_87.png
|
|
118
|
+
- examples/tmp/tiles/7_38_71.png
|
|
119
|
+
- examples/tmp/tiles/7_38_72.png
|
|
120
|
+
- examples/tmp/tiles/7_38_73.png
|
|
121
|
+
- examples/tmp/tiles/7_38_74.png
|
|
122
|
+
- examples/tmp/tiles/7_38_75.png
|
|
123
|
+
- examples/tmp/tiles/7_38_76.png
|
|
124
|
+
- examples/tmp/tiles/7_38_77.png
|
|
125
|
+
- examples/tmp/tiles/7_38_78.png
|
|
126
|
+
- examples/tmp/tiles/7_38_79.png
|
|
127
|
+
- examples/tmp/tiles/7_38_80.png
|
|
128
|
+
- examples/tmp/tiles/7_38_81.png
|
|
129
|
+
- examples/tmp/tiles/7_38_82.png
|
|
130
|
+
- examples/tmp/tiles/7_38_83.png
|
|
131
|
+
- examples/tmp/tiles/7_38_84.png
|
|
132
|
+
- examples/tmp/tiles/7_38_85.png
|
|
133
|
+
- examples/tmp/tiles/7_38_86.png
|
|
134
|
+
- examples/tmp/tiles/7_38_87.png
|
|
135
|
+
- examples/tmp/tiles/7_39_71.png
|
|
136
|
+
- examples/tmp/tiles/7_39_72.png
|
|
137
|
+
- examples/tmp/tiles/7_39_73.png
|
|
138
|
+
- examples/tmp/tiles/7_39_74.png
|
|
139
|
+
- examples/tmp/tiles/7_39_75.png
|
|
140
|
+
- examples/tmp/tiles/7_39_76.png
|
|
141
|
+
- examples/tmp/tiles/7_39_77.png
|
|
142
|
+
- examples/tmp/tiles/7_39_78.png
|
|
143
|
+
- examples/tmp/tiles/7_39_79.png
|
|
144
|
+
- examples/tmp/tiles/7_39_80.png
|
|
145
|
+
- examples/tmp/tiles/7_39_81.png
|
|
146
|
+
- examples/tmp/tiles/7_39_82.png
|
|
147
|
+
- examples/tmp/tiles/7_39_83.png
|
|
148
|
+
- examples/tmp/tiles/7_39_84.png
|
|
149
|
+
- examples/tmp/tiles/7_39_85.png
|
|
150
|
+
- examples/tmp/tiles/7_39_86.png
|
|
151
|
+
- examples/tmp/tiles/7_39_87.png
|
|
152
|
+
- examples/tmp/tiles/7_40_71.png
|
|
153
|
+
- examples/tmp/tiles/7_40_72.png
|
|
154
|
+
- examples/tmp/tiles/7_40_73.png
|
|
155
|
+
- examples/tmp/tiles/7_40_74.png
|
|
156
|
+
- examples/tmp/tiles/7_40_75.png
|
|
157
|
+
- examples/tmp/tiles/7_40_76.png
|
|
158
|
+
- examples/tmp/tiles/7_40_77.png
|
|
159
|
+
- examples/tmp/tiles/7_40_78.png
|
|
160
|
+
- examples/tmp/tiles/7_40_79.png
|
|
161
|
+
- examples/tmp/tiles/7_40_80.png
|
|
162
|
+
- examples/tmp/tiles/7_40_81.png
|
|
163
|
+
- examples/tmp/tiles/7_40_82.png
|
|
164
|
+
- examples/tmp/tiles/7_40_83.png
|
|
165
|
+
- examples/tmp/tiles/7_40_84.png
|
|
166
|
+
- examples/tmp/tiles/7_40_85.png
|
|
167
|
+
- examples/tmp/tiles/7_40_86.png
|
|
168
|
+
- examples/tmp/tiles/7_40_87.png
|
|
169
|
+
- examples/tmp/tiles/7_41_71.png
|
|
170
|
+
- examples/tmp/tiles/7_41_72.png
|
|
171
|
+
- examples/tmp/tiles/7_41_73.png
|
|
172
|
+
- examples/tmp/tiles/7_41_74.png
|
|
173
|
+
- examples/tmp/tiles/7_41_75.png
|
|
174
|
+
- examples/tmp/tiles/7_41_76.png
|
|
175
|
+
- examples/tmp/tiles/7_41_77.png
|
|
176
|
+
- examples/tmp/tiles/7_41_78.png
|
|
177
|
+
- examples/tmp/tiles/7_41_79.png
|
|
178
|
+
- examples/tmp/tiles/7_41_80.png
|
|
179
|
+
- examples/tmp/tiles/7_41_81.png
|
|
180
|
+
- examples/tmp/tiles/7_41_82.png
|
|
181
|
+
- examples/tmp/tiles/7_41_83.png
|
|
182
|
+
- examples/tmp/tiles/7_41_84.png
|
|
183
|
+
- examples/tmp/tiles/7_41_85.png
|
|
184
|
+
- examples/tmp/tiles/7_41_86.png
|
|
185
|
+
- examples/tmp/tiles/7_41_87.png
|
|
186
|
+
- examples/tmp/tiles/7_42_71.png
|
|
187
|
+
- examples/tmp/tiles/7_42_72.png
|
|
188
|
+
- examples/tmp/tiles/7_42_73.png
|
|
189
|
+
- examples/tmp/tiles/7_42_74.png
|
|
190
|
+
- examples/tmp/tiles/7_42_75.png
|
|
191
|
+
- examples/tmp/tiles/7_42_76.png
|
|
192
|
+
- examples/tmp/tiles/7_42_77.png
|
|
193
|
+
- examples/tmp/tiles/7_42_78.png
|
|
194
|
+
- examples/tmp/tiles/7_42_79.png
|
|
195
|
+
- examples/tmp/tiles/7_42_80.png
|
|
196
|
+
- examples/tmp/tiles/7_42_81.png
|
|
197
|
+
- examples/tmp/tiles/7_42_82.png
|
|
198
|
+
- examples/tmp/tiles/7_42_83.png
|
|
199
|
+
- examples/tmp/tiles/7_42_84.png
|
|
200
|
+
- examples/tmp/tiles/7_42_85.png
|
|
201
|
+
- examples/tmp/tiles/7_42_86.png
|
|
202
|
+
- examples/tmp/tiles/7_42_87.png
|
|
203
|
+
- examples/tmp/tiles/7_43_71.png
|
|
204
|
+
- examples/tmp/tiles/7_43_72.png
|
|
205
|
+
- examples/tmp/tiles/7_43_73.png
|
|
206
|
+
- examples/tmp/tiles/7_43_74.png
|
|
207
|
+
- examples/tmp/tiles/7_43_75.png
|
|
208
|
+
- examples/tmp/tiles/7_43_76.png
|
|
209
|
+
- examples/tmp/tiles/7_43_77.png
|
|
210
|
+
- examples/tmp/tiles/7_43_78.png
|
|
211
|
+
- examples/tmp/tiles/7_43_79.png
|
|
212
|
+
- examples/tmp/tiles/7_43_80.png
|
|
213
|
+
- examples/tmp/tiles/7_43_81.png
|
|
214
|
+
- examples/tmp/tiles/7_43_82.png
|
|
215
|
+
- examples/tmp/tiles/7_43_83.png
|
|
216
|
+
- examples/tmp/tiles/7_43_84.png
|
|
217
|
+
- examples/tmp/tiles/7_43_85.png
|
|
218
|
+
- examples/tmp/tiles/7_43_86.png
|
|
219
|
+
- examples/tmp/tiles/7_43_87.png
|
|
220
|
+
- examples/tmp/tiles/7_44_71.png
|
|
221
|
+
- examples/tmp/tiles/7_44_72.png
|
|
222
|
+
- examples/tmp/tiles/7_44_73.png
|
|
223
|
+
- examples/tmp/tiles/7_44_74.png
|
|
224
|
+
- examples/tmp/tiles/7_44_75.png
|
|
225
|
+
- examples/tmp/tiles/7_44_76.png
|
|
226
|
+
- examples/tmp/tiles/7_44_77.png
|
|
227
|
+
- examples/tmp/tiles/7_44_78.png
|
|
228
|
+
- examples/tmp/tiles/7_44_79.png
|
|
229
|
+
- examples/tmp/tiles/7_44_80.png
|
|
230
|
+
- examples/tmp/tiles/7_44_81.png
|
|
231
|
+
- examples/tmp/tiles/7_44_82.png
|
|
232
|
+
- examples/tmp/tiles/7_44_83.png
|
|
233
|
+
- examples/tmp/tiles/7_44_84.png
|
|
234
|
+
- examples/tmp/tiles/7_44_85.png
|
|
235
|
+
- examples/tmp/tiles/7_44_86.png
|
|
236
|
+
- examples/tmp/tiles/7_44_87.png
|
|
237
|
+
- examples/tmp/tiles/7_75_64.png
|
|
238
|
+
- examples/tmp/tiles/7_75_65.png
|
|
239
|
+
- examples/tmp/tiles/7_75_66.png
|
|
240
|
+
- examples/tmp/tiles/7_75_67.png
|
|
241
|
+
- examples/tmp/tiles/7_75_68.png
|
|
242
|
+
- examples/tmp/tiles/7_76_64.png
|
|
243
|
+
- examples/tmp/tiles/7_76_65.png
|
|
244
|
+
- examples/tmp/tiles/7_76_66.png
|
|
245
|
+
- examples/tmp/tiles/7_76_67.png
|
|
246
|
+
- examples/tmp/tiles/7_76_68.png
|
|
247
|
+
- examples/tmp/tiles/7_77_64.png
|
|
248
|
+
- examples/tmp/tiles/7_77_65.png
|
|
249
|
+
- examples/tmp/tiles/7_77_66.png
|
|
250
|
+
- examples/tmp/tiles/7_77_67.png
|
|
251
|
+
- examples/tmp/tiles/7_77_68.png
|
|
252
|
+
- lib/gd/gis.rb
|
|
253
|
+
- lib/gd/gis/basemap.rb
|
|
254
|
+
- lib/gd/gis/layer_points.rb
|
|
255
|
+
- lib/gd/gis/map.rb
|
|
256
|
+
- lib/gd/gis/projection.rb
|
|
257
|
+
- lib/libgd_gis.rb
|
|
258
|
+
homepage: https://github.com/ggerman/libgd-gis
|
|
259
|
+
licenses:
|
|
260
|
+
- MIT
|
|
261
|
+
metadata: {}
|
|
262
|
+
post_install_message:
|
|
263
|
+
rdoc_options: []
|
|
264
|
+
require_paths:
|
|
265
|
+
- lib
|
|
266
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
267
|
+
requirements:
|
|
268
|
+
- - ">="
|
|
269
|
+
- !ruby/object:Gem::Version
|
|
270
|
+
version: '0'
|
|
271
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
272
|
+
requirements:
|
|
273
|
+
- - ">="
|
|
274
|
+
- !ruby/object:Gem::Version
|
|
275
|
+
version: '0'
|
|
276
|
+
requirements: []
|
|
277
|
+
rubygems_version: 3.5.22
|
|
278
|
+
signing_key:
|
|
279
|
+
specification_version: 4
|
|
280
|
+
summary: Geospatial raster rendering for Ruby using libgd
|
|
281
|
+
test_files: []
|