Skip to content

Commit

Permalink
Add LineString and Point drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
brycejohnston committed Jan 27, 2017
1 parent 6fe9c3e commit 802a77f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# geojson2image

Ruby library for generating images from GeoJSON.
This gem is currently is in alpha / pre-release level status (not fully functional).
This gem currently is in alpha / pre-release level status (not fully functional).

## Installation

Expand Down
20 changes: 9 additions & 11 deletions lib/geojson2image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ def transform_point(point, boundary)
return new_point
end

def draw(json, boundary, options = {})
def draw(json, boundary)
x_delta = boundary[1] - boundary[0]
y_delta = boundary[3] - boundary[2]
max_delta = [x_delta, y_delta].max

case json['type']
when 'GeometryCollection'
json['geometries'].each do |geometry|
draw(geometry, boundary, options)
draw(geometry, boundary)
end

when 'FeatureCollection'
Expand All @@ -166,19 +166,16 @@ def draw(json, boundary, options = {})
point_size = 10
point = json['coordinates']
new_point = transform_point(point, boundary)
# imagefilledellipse(gd, new_point[0], new_point[1], point_size, point_size, background_color)

border_size.times do |n|
# imageellipse(gd, new_point[0], new_point[1], point_size - 1 + n, point_size - 1 + n, border_color)
end
draw_point = "color #{new_point[0]},#{new_point[1]} point"
@convert.draw(draw_point)

when 'MultiPoint'
json['coordinates'].each do |coordinate|
point = {
"type" => "Point",
"coordinates" => coordinate
}
draw(point, boundary, options)
draw(point, boundary)
end

when 'LineString'
Expand All @@ -187,7 +184,8 @@ def draw(json, boundary, options = {})
json['coordinates'].each do |point|
new_point = transform_point(point, boundary)
if !last_point.nil?
# @png.line_xiaolin_wu(last_point[0], last_point[1], new_point[0], new_point[1], stroke_color = ChunkyPNG::Color::BLACK)
polyline = "polyline #{last_point[0]},#{last_point[1]}, #{new_point[0]},#{new_point[1]}"
@convert.draw(polyline)
end
last_point = new_point
end
Expand All @@ -198,7 +196,7 @@ def draw(json, boundary, options = {})
"type" => "LineString",
"coordinates" => coordinate
}
draw(linestring, boundary, options)
draw(linestring, boundary)
end

when 'Polygon'
Expand All @@ -223,7 +221,7 @@ def draw(json, boundary, options = {})
"type" => "Polygon",
"coordinates" => polygon
}
draw(poly, boundary, options)
draw(poly, boundary)
end

else
Expand Down

0 comments on commit 802a77f

Please sign in to comment.