Skip to content

Instantly share code, notes, and snippets.

@niku
Last active December 8, 2015 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niku/f57ca5a52303a42360dd to your computer and use it in GitHub Desktop.
Save niku/f57ca5a52303a42360dd to your computer and use it in GitHub Desktop.
コンサドーレ札幌サポートシップパートナー様の住所をマッピングしてみた

地図は下にあります

これは何ですか

北海道コンサドーレ札幌 Advent Calendar 2015の企画で「コンサドーレ札幌サポートシップパートナー様」の住所をマッピングしてみたものです.

情報はどこから集めましたか

サポートシップパートナー | コンサドーレ札幌 オフィシャルサイトから集めました.

他のパートナー(オフィシャル/クラブ/夢プラン/北海道リラ・コンサドーレ)が載っていません

住所が集めるのが困難で断念しました.すみません……

サポートシップパートナーなのに載っていません

  • 住所が登録されていない
  • 住所から緯度経度が引けなかった

これらの方について,今回は載せられませんでした. 上記の条件で載せられていないのは以下のサポートシップパートナー様になります.

村上 アシシ:住所が登録されていませんでした
たこ焼きの移動販売 ほっと12:住所が登録されていませんでした
医療法人 札幌大庭眼科:住所から緯度経度が取得できませんでした
焼き鳥ダイニング いただきコッコちゃん:住所から緯度経度が取得できませんでした
こだわりやま札幌:住所から緯度経度が取得できませんでした
株式会社 ジャパンインシュアランスエージェント 札幌支店:住所から緯度経度が取得できませんでした
有限会社 大熊事務所:住所から緯度経度が取得できませんでした
岩橋印刷株式会社:住所から緯度経度が取得できませんでした
株式会社 エフエムなかそらち:住所から緯度経度が取得できませんでした
株式会社サイバードメイン:住所から緯度経度が取得できませんでした
てっちゃん福祉タクシー:住所から緯度経度が取得できませんでした
医療法人社団北楡会 ファミリー歯科クリニック:住所から緯度経度が取得できませんでした
Cafe Pan gi (カフェ パンジ):住所から緯度経度が取得できませんでした
ビストロ・ブルータス:住所から緯度経度が取得できませんでした
なべ居酒屋 大番:住所から緯度経度が取得できませんでした
らっきょ大サーカス:住所から緯度経度が取得できませんでした
株式会社 ウェルネスプランニング札幌:住所から緯度経度が取得できませんでした
北笑 Dining:住所から緯度経度が取得できませんでした
美食ダイニング四季舞札幌駅前店:住所から緯度経度が取得できませんでした
トムス株式会社:住所から緯度経度が取得できませんでした
株式会社 標津羊羹本舗:住所から緯度経度が取得できませんでした
JAPANESEDINING 和民 十勝帯広店:住所から緯度経度が取得できませんでした
十勝信用組合:住所から緯度経度が取得できませんでした
土橋水産:住所から緯度経度が取得できませんでした
髙橋建設 株式会社:住所から緯度経度が取得できませんでした
第一工業株式会社:住所から緯度経度が取得できませんでした
ハマト商店:住所から緯度経度が取得できませんでした
有限会社 船田アーキテクツ:住所から緯度経度が取得できませんでした
株式会社 LED・TopJapan:住所から緯度経度が取得できませんでした

緯度経度はどうやって取得しましたか

住所を元にYahoo!ジオコーダAPIを利用して取得しました.

作者に連絡したい

niku_nameや メールアドレス niku at niku.name (at をアットマークに変えてください)へご連絡ください.

# 公式サイトからデータを集めてきてgeojsonを作るRubyスクリプト
require "net/http"
require "nokogiri"
require "json"
YAHOO_APPLICATION_ID = "" # YAHOOIDをここに設定する
NEXT_PAGE_XPATH = "//div[@class='wp-pagenavi'][1]/span[@class='current']/following-sibling::a[contains(@class,'page')][1]/@href"
SPONSOR_XPATH = "//article"
Address = Struct.new(:value, :latitude, :longitude) do
def initialize(value)
self.value = value || ""
end
def empty?
value.empty?
end
def geocoding!
if !empty? && longitude.nil?
encoded = URI.encode(value)
uri = URI.parse("http://geo.search.olp.yahooapis.jp/OpenLocalPlatform/V1/geoCoder?appid=#{YAHOO_APPLICATION_ID}&query=#{encoded}&output=json")
response = JSON.parse(Net::HTTP.get(uri))
if response["Feature"]
lng, lat = response["Feature"][0]["Geometry"]["Coordinates"].split(",")
self.longitude = lng.to_f
self.latitude = lat.to_f
[latitude, longitude]
end
end
end
end
Sponsor = Struct.new(:name, :grade, :duration, :job_type, :address, :phone_number, :web_address, :prize, :comment) do
def self.parse(element)
name = element.at("./h3//child::node()").text.tr(" ", "")
grade, duration = *element.at("./h3//span").text.split(/(\d+)年$/)
job_type, address, phone_number, web_address, prize, comment = *element.search("./table/tr/td").map(&:text).map(&:chomp)
new(name, grade, duration, job_type, address, phone_number, web_address, prize, comment)
end
def initialize(name, grade, duration, job_type, address, phone_number, web_address, prize, comment)
self.name = name || ""
self.grade = grade || ""
self.duration = duration.chomp.to_i
self.job_type = job_type || ""
self.address = Address.new(address.tr(" ", ""))
self.phone_number = phone_number || ""
self.web_address = web_address || ""
self.prize = prize || ""
self.comment = comment || ""
end
def to_h
hashmap = super()
hashmap[:address] = address.value
hashmap
end
end
def get_page(url, pages=[])
puts "スポンサー一覧取得:#{url}"
doc = Net::HTTP.get(url)
doc.force_encoding("UTF-8")
page = Nokogiri::HTML.parse(doc)
new_pages = pages + [page]
if next_url = page.at(NEXT_PAGE_XPATH)
sleep 1
get_page(URI.parse(next_url), new_pages)
else
new_pages
end
end
pages = [
"http://www.consadole-sapporo.jp/partner/support/center/",
"http://www.consadole-sapporo.jp/partner/support/east/",
"http://www.consadole-sapporo.jp/partner/support/north/",
"http://www.consadole-sapporo.jp/partner/support/south/",
"http://www.consadole-sapporo.jp/partner/support/other/"
].flat_map { |e| get_page(URI.parse(e)) }
sponsors = pages.flat_map { |page| page.search(SPONSOR_XPATH) }
parsed_sponsors = sponsors.map { |e| Sponsor.parse(e) }
# 緯度経度取得
parsed_sponsors.reject { |s| s.address.empty? }.each { |s| puts "緯度経度を取得:#{s.name}"; s.address.geocoding!; sleep 1 }
# 緯度経度が取得できなかったデータ
parsed_sponsors.select { |s| s.address.empty? }.each { |s| puts "#{s.name}:住所が登録されていませんでした" }
parsed_sponsors.reject { |s| s.address.empty? }.reject { |s| s.address.latitude }.each { |s| puts "#{s.name}:住所から緯度経度が取得できませんでした" }
features = parsed_sponsors.reject {|s| s.address.empty? }.select { |s| s.address.latitude }.map { |s|
{
type: "Feature",
properties: s.to_h,
geometry: {
type: "Point",
coordinates: [s.address.longitude, s.address.latitude]
}
}
}
geojson = {
type: "FeatureCollection",
features: features
}.to_json
File.write("supportship-partner.geojson", geojson)
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment