> ## Content Index
> Fetch the complete content index at: https://blog.anthea.day/llms.txt
> Use this file to discover other available public pages before exploring further.

# 歡迎來到 GIS 的世界－Day 22：旅遊規劃小專案的資料準備
- URL: https://blog.anthea.day/series-2022-ithome-22/
- Published: 2022-10-05T16:02:31.000Z
- Updated: 2026-11-06T19:34:14.000Z
- Author: Anthea / 芫荽
- Tags: #Migrated-1792241843742, #Import 2026-10-17 12:57, Coding, 2022 iThome 鐵人賽：歡迎來到 GIS 的世界

前幾篇簡單講解了幾個套件對 Shapefile 的操作之後，接下來要進入到 Shapefile 的實作了。第一個練習，我們要使用的是[政府資料開放平臺](https://data.gov.tw/?ref=blog.anthea.day)中，休閒旅遊分類裡面所提供的資料，包含[景點](https://data.gov.tw/dataset/7777?ref=blog.anthea.day)、[民宿旅館](https://data.gov.tw/dataset/7780?ref=blog.anthea.day)、[餐飲](https://data.gov.tw/dataset/7779?ref=blog.anthea.day)、[活動](https://data.gov.tw/dataset/7778?ref=blog.anthea.day)四個部分，以及[鄉鎮市區界線](https://data.gov.tw/dataset/7441?ref=blog.anthea.day)，來做出一個簡單的網頁，可以利用縣市鄉鎮搜尋對應的景點、查詢景點附近的住宿和餐廳等等。由於我擅長的並不是前端，所以文章內容會比較多著墨在後端和資料庫的處理上。

### 將 Shapefile 資料儲存到資料庫

我們現有的資料來源都是實體檔案，如果每發送一次 API 就要讀取一次檔案是一個很不實用的作法，除了速度較慢之外，還有可能造成檔案被其他個 request 咬住。因此，我提供的解決辦法是寫一個 Console App，把檔案的內容存到資料庫，如果有需要的話也能調整成排程，彈性較大。

#### 套件版本

以下是將匯入資料這支 Console App 會需要用到的套件清單，如果有遇到其他問題，也有可能是套件更新過，可以先試著把版本調降看看。

![](https://cdn-images-1.medium.com/max/800/1*Gss1aba5Hq5Q9SICDZJ42A.png)

### 先別急著存到資料庫裡

還記得我們之前所說的座標系統嗎？PostgreSQL 裡面可以存 Geometry 的格式，自然也就會存到座標系統的值。因此，在我們把檔案放入資料庫之前，先檢查一下五個檔案的座標格式。

前端套件會選用 Leaflet，工作上也都是接觸這個套件，而他在官方文件中的範例，底圖都是 OSM OpenStreeMap，所以需要先研究一下 OSM 所使用的座標系統是甚麼。

而根據[這篇文章](https://gis.stackexchange.com/questions/48949/epsg-3857-or-4326-for-googlemaps-openstreetmap-and-leaflet?ref=blog.anthea.day)的說明：

- `EPSG:4326`：大地基準
- `EPSG:3857`：以 WGS84 大地基準為底的投影座標系統

因為是平面的地圖所以必須經過投影，因此 OSM 使用的是 `EPSG:3857`，但根據 3857 的數值較大，所佔用的儲存空間也是，所以基本上會存 4326，再轉換成 3857 進行操作。

不過從[這篇文章](https://stackoverflow.com/questions/47529832/leafletjs-how-to-project-epsg4326-points-to-the-leaflet-default?ref=blog.anthea.day)的回答中可以看出，Leaflet 很貼心的會幫你做轉換，預設只要輸入經緯度座標即可，所以下載回來的檔案都不需要進行座標轉換喔。

#### References

- [政府資料開放平臺](https://data.gov.tw/?ref=blog.anthea.day)
- [交通部 — 觀光資訊標準格式 v1.0](https://media.taiwan.net.tw/Upload/%E8%A7%80%E5%85%89%E8%B3%87%E8%A8%8A%E6%A8%99%E6%BA%96%E6%A0%BC%E5%BC%8FV1.0.pdf?ref=blog.anthea.day)
- [epsg-3857-or-4326-for-googlemaps-openstreetmap-and-leaflet](https://gis.stackexchange.com/questions/48949/epsg-3857-or-4326-for-googlemaps-openstreetmap-and-leaflet?ref=blog.anthea.day)
- [leafletjs-how-to-project-epsg4326-points-to-the-leaflet-default](https://stackoverflow.com/questions/47529832/leafletjs-how-to-project-epsg4326-points-to-the-leaflet-default?ref=blog.anthea.day)
- [openlayers6【十】EPSG:3857和EPSG:4326区别详解](https://blog.csdn.net/qq%5F36410795/article/details/106429109?ref=blog.anthea.day)