lib/geojson2image.rb in geojson2image-0.1.0 vs lib/geojson2image.rb in geojson2image-0.1.1
- old
+ new
@@ -82,20 +82,20 @@
end
end
end
else
- puts "get_boundary invalid GeoJSON parse error"
+ puts "get_points - invalid GeoJSON parse error"
end
end
def get_boundary
quarter_pi = Math::PI / 4.0
@coordinates.each_with_index do |point,i|
- lon = @coordinates[i][0].to_f * Math::PI / 180
- lat = @coordinates[i][1].to_f * Math::PI / 180
+ lon = @coordinates[i][0] * Math::PI / 180
+ lat = @coordinates[i][1] * Math::PI / 180
@coordinates[i][0] = lon
@coordinates[i][1] = Math.log(Math.tan(quarter_pi + 0.5 * lat))
@min_xy[0] = (min_xy[0] == -1 ? @coordinates[i][0] : [min_xy[0], @coordinates[i][0]].min)
@@ -126,11 +126,11 @@
xy[1] = (@height - @height_padding - (xy[1] * @global_ratio)).to_i
return xy
end
- def draw(json)
+ def draw(json, properties = nil)
case json['type']
when 'GeometryCollection'
json['geometries'].each do |geometry|
draw(geometry)
end
@@ -140,11 +140,15 @@
json['features'].each do |feature|
draw(feature)
end
when 'Feature'
- draw(json['geometry'])
+ if json.key?('properties')
+ draw(json['geometry'], json['properties'])
+ else
+ draw(json['geometry'])
+ end
when 'Point'
point = json['coordinates']
new_point = transform_point(point)
draw_point = "color #{new_point[0]},#{new_point[1]} point"
@@ -158,10 +162,22 @@
}
draw(point)
end
when 'LineString'
+ if !properties.nil?
+ if properties.key?('fill_color')
+ @convert.fill(properties['fill_color'])
+ end
+ if properties.key?('stroke_color')
+ @convert.stroke(properties['stroke_color'])
+ end
+ if properties.key?('stroke_width')
+ @convert.strokewidth(properties['stroke_width'])
+ end
+ end
+
last_point = null
json['coordinates'].each do |point|
new_point = transform_point(point)
if !last_point.nil?
@@ -179,10 +195,22 @@
}
draw(linestring)
end
when 'Polygon'
+ if !properties.nil?
+ if properties.key?('fill_color')
+ @convert.fill(properties['fill_color'])
+ end
+ if properties.key?('stroke_color')
+ @convert.stroke(properties['stroke_color'])
+ end
+ if properties.key?('stroke_width')
+ @convert.strokewidth(properties['stroke_width'])
+ end
+ end
+
json['coordinates'].each do |linestrings|
border_points = []
if linestrings[0] != linestrings[linestrings.count - 1]
linestrings << linestrings[0]
end
@@ -204,11 +232,11 @@
}
draw(poly)
end
else
- puts "draw invalid GeoJSON parse error - #{json['type']}"
+ puts "draw - invalid GeoJSON parse error - #{json['type']}"
end
end
def to_image
@convert = MiniMagick::Tool::Convert.new
@@ -234,10 +262,10 @@
@height_padding = (@height - (@global_ratio * @max_xy[1])) / 2
draw(@parsed_json)
@convert << @output
- cmd_string = @convert.call
+ @convert.call
end
end
end