Class: Sogoumap2pdf::SogouMapImage
- Inherits:
-
Object
- Object
- Sogoumap2pdf::SogouMapImage
- Defined in:
- lib/sogoumap2pdf/sogou_map_image.rb
Instance Attribute Summary collapse
-
#area_height ⇒ Object
readonly
Returns the value of attribute area_height.
-
#area_width ⇒ Object
readonly
Returns the value of attribute area_width.
-
#link_end ⇒ Object
readonly
Returns the value of attribute link_end.
-
#npx ⇒ Object
readonly
Returns the value of attribute npx.
-
#npy ⇒ Object
readonly
Returns the value of attribute npy.
-
#path_directory_name ⇒ Object
readonly
Returns the value of attribute path_directory_name.
-
#picture_directory_name ⇒ Object
readonly
Returns the value of attribute picture_directory_name.
-
#resource_extension ⇒ Object
readonly
Returns the value of attribute resource_extension.
-
#resource_level ⇒ Object
readonly
Returns the value of attribute resource_level.
-
#resource_type ⇒ Object
readonly
Returns the value of attribute resource_type.
-
#satellite_path ⇒ Object
readonly
Returns the value of attribute satellite_path.
-
#start_link_x ⇒ Object
readonly
Returns the value of attribute start_link_x.
-
#start_link_y ⇒ Object
readonly
Returns the value of attribute start_link_y.
Instance Method Summary collapse
-
#fill_map(rx, ry) ⇒ Object
creates map of given size (in pixels), returns Image object.
-
#fill_map2 ⇒ Object
end patch epx=npx+spx-1 epy=npy+spy-1 for i in 0…npx for j in 0…npy self.only_save_image(i+spx,j+spy) end end.
-
#get_or_read_picture(link_name, dir_name, file_name) ⇒ Object
get a patch of map from google maps the initial link is the patch 0,0.
-
#initialize(sogou_link, option) ⇒ SogouMapImage
constructor
A new instance of SogouMapImage.
- #only_save_image(x, y) ⇒ Object
Constructor Details
#initialize(sogou_link, option) ⇒ SogouMapImage
Returns a new instance of SogouMapImage.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 19 def initialize(sogou_link,option) @link_beginning, @link_end = sogou_link.split(/\d+_\d+/) @sogou_link=sogou_link resource_head,resource_parameters= sogou_link.split(/\/0\//) @resource_head = resource_head+"/0/" @resource_type,@resource_level,@resource_x200,@resource_y200,@resource_x,@resource_y,@resource_extension=resource_parameters.split(/\/|_|\./) @link_x=@resource_x.to_i @link_y=@resource_y.to_i @satellite_only=true if option=="s" @satellite_path=true if option=="sp" @map=true if option=="m" @patch_size_x=256 @patch_size_y=256 #for sogou map #@link_beginning="http://hbpic2.go2map.com/seamless/0/180/792/504/105/" #@link_end=".JPG" #@link_x=100960 #@link_y=21035 end |
Instance Attribute Details
#area_height ⇒ Object (readonly)
Returns the value of attribute area_height.
18 19 20 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 18 def area_height @area_height end |
#area_width ⇒ Object (readonly)
Returns the value of attribute area_width.
18 19 20 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 18 def area_width @area_width end |
#link_end ⇒ Object (readonly)
Returns the value of attribute link_end.
18 19 20 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 18 def link_end @link_end end |
#npx ⇒ Object (readonly)
Returns the value of attribute npx.
18 19 20 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 18 def npx @npx end |
#npy ⇒ Object (readonly)
Returns the value of attribute npy.
18 19 20 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 18 def npy @npy end |
#path_directory_name ⇒ Object (readonly)
Returns the value of attribute path_directory_name.
18 19 20 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 18 def path_directory_name @path_directory_name end |
#picture_directory_name ⇒ Object (readonly)
Returns the value of attribute picture_directory_name.
18 19 20 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 18 def picture_directory_name @picture_directory_name end |
#resource_extension ⇒ Object (readonly)
Returns the value of attribute resource_extension.
18 19 20 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 18 def resource_extension @resource_extension end |
#resource_level ⇒ Object (readonly)
Returns the value of attribute resource_level.
18 19 20 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 18 def resource_level @resource_level end |
#resource_type ⇒ Object (readonly)
Returns the value of attribute resource_type.
18 19 20 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 18 def resource_type @resource_type end |
#satellite_path ⇒ Object (readonly)
Returns the value of attribute satellite_path.
18 19 20 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 18 def satellite_path @satellite_path end |
#start_link_x ⇒ Object (readonly)
Returns the value of attribute start_link_x.
18 19 20 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 18 def start_link_x @start_link_x end |
#start_link_y ⇒ Object (readonly)
Returns the value of attribute start_link_y.
18 19 20 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 18 def start_link_y @start_link_y end |
Instance Method Details
#fill_map(rx, ry) ⇒ Object
creates map of given size (in pixels), returns Image object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 97 def fill_map(rx,ry) @npx=npx=rx/@patch_size_x+1 @npy=npy=ry/@patch_size_y+1 @spacex=spacex=npx*@patch_size_x-rx @spacey=spacey=npy*@patch_size_y-ry # starting patch @spx=spx=-(npx/2) @spy=spy=-(npy/2) @start_link_x=spx+@link_x @start_link_y=spy+@link_y @area_height=npy*@patch_size_y @area_width=npx*@patch_size_x # end patch # epx=npx+spx-1 # epy=npy+spy-1 # for i in 0...npx # for j in 0...npy # self.only_save_image(i+spx,j+spy) # end # end end |
#fill_map2 ⇒ Object
end patch epx=npx+spx-1 epy=npy+spy-1 for i in 0…npx
for j in 0...npy
self.only_save_image(i+spx,j+spy)
end
end
118 119 120 121 122 123 124 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 118 def fill_map2 for i in 0...@npx for j in 0...@npy self.only_save_image(i+@spx,j+@spy) end end end |
#get_or_read_picture(link_name, dir_name, file_name) ⇒ Object
get a patch of map from google maps the initial link is the patch 0,0
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 41 def get_or_read_picture(link_name,dir_name,file_name) file_name=File.(file_name) if File.exist? file_name then #if File.size(file_name) !=0 then # picture_block=File.read file_name #else # picture_block = File.read("empty.jpg") if link_name =~ /(JPG|GIF)$/ # picture_block = File.read("empty.png") if link_name =~ /PNG$/ #end else picture_data=Net::HTTP.get_response(URI.parse(link_name)) p picture_data.code if picture_data.code == "200" then picture_block = picture_data.body unless File.exist? dir_name then #Dir.mkdir dir_name `mkdir -p #{dir_name}` end tmp_file=File.new(file_name,"w") tmp_file.binmode tmp_file.write(picture_data.body) tmp_file.close else unless File.exist? dir_name then #Dir.mkdir dir_name `mkdir -p #{dir_name}` end `touch #{file_name}` #temp_blob = ImageList.new.read("NULL:white") { self.size = "256x256"} #picture_block = temp_blob.to_blob #picture_block = File.read("empty.jpg") if link_name =~ /(JPG|GIF)$/ #picture_block = File.read("empty.png") if link_name =~ /PNG$/ end end return picture_block end |
#only_save_image(x, y) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/sogoumap2pdf/sogou_map_image.rb', line 77 def only_save_image(x,y) http_get_picture = false http_get_path = false @resource_x200=((@link_x+x)/200).to_s @resource_y200=((@link_y+y)/200).to_s picture_link=@resource_head+[@resource_type,@resource_level,@resource_x200,@resource_y200].join("/")+"/"+(@link_x+x).to_s+"_"+(@link_y+y).to_s+"."+@resource_extension p "getting #{x-@spx}/#{@npx-1}, #{y-@spy}/#{@npy-1} #{picture_link}" picture_directory_name = "~/.sogoumap/0/"+ [@resource_type,@resource_level,@resource_x200,@resource_y200].join("/") picture_file_name = picture_directory_name +"/"+ (@link_x+x).to_s+"_"+(@link_y+y).to_s+"."+@resource_extension get_or_read_picture(picture_link,picture_directory_name,picture_file_name) if @satellite_path then path_link=@resource_head+["179",@resource_level,@resource_x200,@resource_y200].join("/")+"/"+(@link_x+x).to_s+"_"+(@link_y+y).to_s+"."+"PNG" p "getting #{x-@spx}/#{@npx-1}, #{y-@spy}/#{@npy-1} #{path_link}" path_data=Net::HTTP.get_response(URI.parse(path_link)) path_directory_name = "~/.sogoumap/0/"+ ["179",@resource_level,@resource_x200,@resource_y200].join("/") path_file_name = path_directory_name + "/" +(@link_x+x).to_s+"_"+(@link_y+y).to_s+".PNG" get_or_read_picture(path_link,path_directory_name, path_file_name) end end |