3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

概要

paiza.ioでelixirやってみた。
練習問題やってみた。

練習問題

e-statのsparqlを叩いて、緯度経度から、住所を求めよ。

サンプルコード

:inets.start
:ssl.start

query = URI.encode_query(%{query: """

PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX dcterms:<http://purl.org/dc/terms/>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
select ?municipality ?area
where {
    ?s <http://www.opengis.net/ont/geosparql#hasGeometry> ?polygon ;
     rdfs:label ?area ;
     dcterms:isPartOf / rdfs:label ?municipality .
    ?polygon geo:asWKT ?geom .
    FILTER (ogcf:sfContains(?geom, "POINT(140.0 38.0)"^^geo:wktLiteral)) .
    FILTER (LANG(?municipality)='ja') .
}

"""})
#|> IO.inspect
{:ok, {{_, _, _}, _, body}} = :httpc.request(:post, {
	'https://data.e-stat.go.jp/lod/sparql/alldata/query', 
	[{'Accept', 'application/sparql-results+json'}], 
	'application/x-www-form-urlencoded', 
	query
}, [], [])
#|> IO.inspect
body = IO.iodata_to_binary(body)
IO.puts(body)


実行結果

{
  "head": {
    "vars": [ "municipality" , "area" ]
  } ,
  "results": {
    "bindings": [
      {
        "municipality": { "type": "literal" , "xml:lang": "ja" , "value": "川西町" } ,
        "area": { "type": "literal" , "xml:lang": "ja" , "value": "大字上小松" }
      }
    ]
  }
}

成果物

以上。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?