# Wolfram言語™

## 画像のメタデータで旅を分析

リスボン旅行中に撮った写真をインポートして分析する．

In[1]:=
```files = Map[ img \[Function] ExampleData[img, "FilePath"], ExampleData[{"TestImageSet", "Lisbon2016"}] ];```

In[2]:=
`labels = {"Thumbnail", "DateTime", "GeoPosition"};`
In[3]:=
```dataSet = Dataset@Map[ file \[Function] AssociationThread[ labels -> Import[file, {labels}, IncludeMetaInformation -> False]], files ]```
Out[3]=

In[4]:=
```gps = dataSet[[All, "GeoPosition"]]; GeoGraphics[GeoMarker@gps, GeoRangePadding -> Quantity[100, "Meters"]]```
Out[4]=

すべての写真を撮って帰るまでの歩行距離を計算する．

In[5]:=
`closeLoop = path \[Function] Append[path, First[path]];`
In[6]:=
```sortedGPS = closeLoop@ Normal@dataSet[SortBy["DateTime"], Take[#GeoPosition, All, 2] &]; UnitConvert[ TravelDistance[sortedGPS, TravelMethod -> "Walking"], "Kilometers"]```
Out[6]=

In[7]:=
`travel = TravelDirections[sortedGPS, TravelMethod -> "Walking"]`
Out[8]=
In[9]:=
```Animate[ GeoGraphics[{ Style[Normal@travel["Dataset"][1 ;; n, "Path"], Thick, Red], dataSet[All, GeoMarker[Take[#GeoPosition, All, 2], #Thumbnail] &]}, GeoRangePadding -> Quantity[200, "Meters"] ], {n, 1, Length[travel["Dataset"]] + 1, 1} ]```

In[10]:=
```optimalPath = FindShortestTour[Normal@sortedGPS, DistanceFunction -> (QuantityMagnitude[ TravelDistance[{#1, #2}, TravelMethod -> "Walking"], "Kilometer"] &)]```
Out[10]=
In[11]:=
`Quantity[First@optimalPath, "Kilometers"]`
Out[11]=
In[12]:=
`shortestGPS = sortedGPS[[Last@optimalPath]];`
In[13]:=
```shortestTravel = TravelDirections[shortestGPS, TravelMethod -> "Walking"]```
Out[14]=
In[15]:=
```Animate[ GeoGraphics[{ Style[Normal@shortestTravel["Dataset"][1 ;; n, "Path"], Thick, Blue], dataSet[All, GeoMarker[Take[#GeoPosition, All, 2], #Thumbnail] &]}, GeoRangePadding -> Quantity[200, "Meters"] ], {n, 1, Length[shortestTravel["Dataset"]] + 1, 1} ]```