Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.8.1 林班地資料 endpoint #45

Closed
6 tasks done
ghost opened this issue Nov 25, 2018 · 23 comments
Closed
6 tasks done

2.8.1 林班地資料 endpoint #45

ghost opened this issue Nov 25, 2018 · 23 comments
Assignees
Labels
previous 上一版的問題

Comments

@ghost
Copy link

ghost commented Nov 25, 2018

TaiBIF/camera-trap-webapp#18 相關
需要送出林班地 JSON 供前端套疊

  • 取得林班地資料 in KMZ
  • 轉換 KMZ to GeoJSON
  • normalize GeoJSON 減少體積
  • 按事業處分檔
  • 寫入資料庫 db.createCollection("ForestCompartmentBoundary", options)
  • 建立 API 接口 /forest-compartment-boundary (with user verification)

Expected POST application/json object:

{
  "decimalLatitude": "24.564853",
  "decimalLongitude": "120.991452"
}

Expected response application/json

{ 
  "query": {
    "decimalLatitude": "24.2849853",
    "decimalLongitude": "120.7340352"
  },
  "results": [
    {
      "type": "Feature",
      "properties": {
        "Name": "東勢處",
        "description": null,
        "altitudeMode": "clampToGround",
        "CMPT": "3",
        "AREA": "790277.780053",
        "WKNG": "8",
        "FID": "1",
        "DIST_C": "東勢處",
        "DIST": "03",
        "Field_1": "東勢處",
        "WKNG_C": "八仙山" },
      "geometry": {
        "type": "MultiPolygon",
        "coordinates": [ [ [ [ 120.734243717809093, 24.284491143322999 ], [ 120.734545820319696, 24.284567597614569 ], [ 120.734410083969905, 24.285020350672809 ], [ 120.734291023148501, 24.285417040780661 ], [ 120.734284836437496, 24.285437653505401 ], [ 120.734278135904702, 24.28547086374072 ], [ 120.734195237479099, 24.285748970890761 ], [ 120.734065208922004, 24.285852237639141 ], [ 120.734057016677795, 24.285836377101269 ], [ 120.734056278880601, 24.28583495100635 ], [ 120.734056250359899, 24.285823104678268 ], [ 120.733962132776696, 24.285516133988011 ], [ 120.733744241223306, 24.284804710222581 ], [ 120.733844003884897, 24.284739381894511 ], [ 120.7338193504401, 24.2846068229106 ], [ 120.733756587505795, 24.28427007817363 ], [ 120.733906834895095, 24.284234843986361 ], [ 120.734354091737401, 24.284129957898259 ], [ 120.734243717809093, 24.284491143322999 ] ] ] ]        }
    }
  ]
}

When no intersect:

{
  "message": "No compartment found.",
  "coordinate": {
    "decimalLatitude": "24.564853",
    "decimalLongitude": "120.991452"
  }
}

As this is an independent service endpoint, two files are expected in /common/models/

  1. forest-compartment-boundary.js
  2. forest-compartment-boundary.json

Model name would be: ForestCompartmentBoundary

參考

  1. MongoDB Geospatial Queries
  2. StrongLoop example

不過應該是不會需要 loopback 特別的支援,這裡是需要 point-in-polygon 的 mongo query 再把 GeoJSON object 送出來即可。

@ghost ghost added this to the 計畫資料管理及更新 W1 WF2 WF3 milestone Nov 25, 2018
@ghost ghost added this to To do in API v0 development via automation Nov 25, 2018
@ghost ghost self-assigned this Nov 25, 2018
@ghost ghost moved this from To do to In progress in API v0 development Nov 25, 2018
@ghost
Copy link
Author

ghost commented Nov 28, 2018

This imports geojson to mongodb:

jq --compact-output ".features" 1051.geojson > extracted1051.geojson
mongoimport --db ctp -c ForestCompartmentBoundary --file "extracted1051.geojson" --jsonArray

@rwu823 rwu823 self-assigned this Nov 28, 2018
@ghost
Copy link
Author

ghost commented Nov 30, 2018

前端會使用的狀況請見 WF 2.8

/forest-compartment-boundary/overall
這個 endpoint 沒有要列出所有的樣區喔,這樣 API 的內容會很長

請只做 POST /forest-compartment-boundary 就好,如果沒有送出 query 座標就報錯

這裡預期前端是就地圖的中心位置來抓取林班地 polygon 來套疊

@rwu823 rwu823 mentioned this issue Nov 30, 2018
@rwu823
Copy link
Contributor

rwu823 commented Nov 30, 2018

@cjk-halodule
wf 不是有一個全台灣的 overall 嗎 ?

@oahehc
Copy link

oahehc commented Nov 30, 2018

POST /forest-compartment-boundary
這個可否協助加上API文件, thanks

@cjk-halodule
這裡預期前端是就地圖的中心位置來抓取林班地 polygon 來套疊

  1. 所以前端只送中心點不考慮zoom size嗎?
  2. 只有移動地圖時才需要重call API對嗎?

@ghost
Copy link
Author

ghost commented Dec 1, 2018

  1. leaflet 的 map.setZoom(9) // 9 以上才顯示
  2. yes

@rwu823
Copy link
Contributor

rwu823 commented Dec 1, 2018

@oahehc

目前 API 用法就是送經緯度即可。

POST /forest-compartment-boundary

{
  "decimalLatitude": "24.564853",
  "decimalLongitude": "120.991452"
}

有 match 到就會回 MultiPolygon 的坐標,沒有就是空的

@oahehc
Copy link

oahehc commented Dec 1, 2018

@rwu823
能否協助提供一組不會回空的座標供測試, thanks~

@ghost
Copy link
Author

ghost commented Dec 1, 2018

{
  "decimalLatitude": "24.277863",
  "decimalLongitude": "121.151822"
}

不過目前應該會超大超慢。請確認有 geoJSON 丟出來就好。我還得轉 TopoJSON 才能供 Leaflet 套疊。

@oahehc
Copy link

oahehc commented Dec 2, 2018

對於 response 的結構有點不太懂,
coordinates 的部分是三層的 array, 請問是有什麼原因嗎?

[
        {
            "_id": "5bfe9e866efcfc940977f5da",
			...
            "geometry": {
                "type": "MultiPolygon",
                "coordinates": [
                    [
                        [
                            [
                                121.1690969809685,
                                24.29407719915862
                            ],
                            [
                                121.1690788508802,
                                24.29407442028118
                            ],
							...
                        ]
                    ]
                ]
            }
        }
]

@ghost
Copy link
Author

ghost commented Dec 2, 2018

表示多邊形的關係。請先別處理呈現,我還在試 topojson.

Sent with GitHawk

@oahehc
Copy link

oahehc commented Dec 2, 2018

有考慮 center 變動範圍在某個幅度下就不要重送 api 嗎?
目前 map zoom-in/out 有時也會導致 center 小幅變動, 怕會對 server 負擔太大

@ghost
Copy link
Author

ghost commented Dec 2, 2018

同意,請你設定一個合理的範圍,例如在目前的 zoom level 原中心移到 x 軸或 y軸的 1/3 以上?

@ghost
Copy link
Author

ghost commented Dec 2, 2018

這兩天的研究下來,瞭解到將個別的 feature 轉成 topojson 對於體積並沒有多大幫助;純粹就體積來說,features 整個一起轉才能看到顯著差別。經過幾個程序得到目前已匯入 db 的 geojson:

# Reduce precision of the decimal value, limited to 5 places
# https://www.npmjs.com/package/geojson-precision
geojson-precision -p 5 1051.geojson rp-1051.geojson  // 176M to 83M

# https://mapshaper.org/ to reduce points to 23.5%
mapshaper rp-1051.geojson\
  -simplify percentage=23.5% visvalingam weighted keep-shapes stats\
  -o format=geojson ms-rp-1051.geojson // 83M to 20M

# Produce newline-delimited JSON with each feature as a line.
cat ms-rp-1051.geojson | jq -c '.features | .[]' > ms-rp-1051.jsonld

# Import to MongoDB
mongoimport --db ctp -c ForestCompartmentBoundary --file "ms-rp-1051.jsonld"

如此將原本 176M 的 geojson 縮到 20M, 3699 個 features 平均每個約 5.4K.

@oahehc
Copy link

oahehc commented Dec 2, 2018

請你設定一個合理的範圍,例如在目前的 zoom level 原中心移到 x 軸或 y軸的 1/3 以上?
我覺得要看BE的計算邏輯, 目前FE只送中心座標並沒有送zoom size,
表示會撈多遠的範圍應該是BE決定的, 可能要看在目前撈取範圍下, 經緯度移動多少沒有必要重送API

@ghost
Copy link
Author

ghost commented Dec 2, 2018

我是這樣想,後端只做 point-in-polygon 的計算,丟出目前中心點所在林班地的 geojson 多邊形供套疊。
後端其實沒有決定會撈多遠,如果送出的點剛好是一個超小的林班地,目前就只送那一個,所以不用考慮撈取範圍。zoom level 及前端地圖被使用者拖移了多少,我沒記錯的話 leaflet 應該知道,所以可以就如我說在目前的 zoom level 下中心移超過 1/3 再重送。

這個功能沒給使用者測試過,有回應了再看看是否細部調整。如何?

@oahehc
Copy link

oahehc commented Dec 3, 2018

後端只做 point-in-polygon 的計算,丟出目前中心點所在林班地的 geojson 多邊形供套疊
所以只有目前中心點剛好落在林班地內才有資料對嗎?
如果是這樣當zoom level超過一定大小是否就沒必要再call API
(因為剛好落在林班地內的機會很低, 即便剛好打中顯示在地圖也是一個小點而已)

目前的 zoom level 下中心移超過 1/3 再重送
這部分要配合zoom level & 地圖大小來計算經緯度, 我先找一下合適的做法再update出來

@ghost
Copy link
Author

ghost commented Dec 3, 2018

所以只有目前中心點剛好落在林班地內才有資料對嗎?
Yes
如果是這樣當zoom level超過一定大小是否就沒必要再call API
如前所說,超過9才call
這部分要配合zoom level & 地圖大小來計算經緯度, 我先找一下合適的做法再update出來
看來有點複雜,或是移動 0.05 度再送即可?

@oahehc
Copy link

oahehc commented Dec 3, 2018

已補上 zoom level & 經緯度移動範圍判斷
TaiBIF/camera-trap-webapp#101

@oahehc
Copy link

oahehc commented Dec 3, 2018

有遇到另一個問題, 這筆資料的 coordinates 內有多組 element,
想確認前端要怎麼顯示才是正確的 (我原本以為只會有一組資料)

_id: "5c03a64c6efcfc9409780666"
image

@ghost ghost added this to To do in API v1 via automation Apr 25, 2019
@kelp404 kelp404 added the previous 上一版的問題 label Apr 28, 2019
@ghost ghost unassigned rwu823 May 2, 2019
@ghost
Copy link
Author

ghost commented May 6, 2019

@kelp404 我把林班地資料直接複製到目前的資料庫中?

@ghost
Copy link
Author

ghost commented May 15, 2019

目前這個 endpoint 由 @moogoo78 接手,做法是:

  • 將 DB ctp 中 forestCompartmentBoundary 的資料複製到 cameraTrap
  • 將 Rocky 在 master-2018 branch 中的實作,按 v1 版實作在本版
  • 其餘 spec 同此一討論串

@moogoo78 moogoo78 moved this from To do to In progress in API v1 May 15, 2019
@moogoo78 moogoo78 moved this from In progress to Done in API v1 May 16, 2019
@ghost
Copy link
Author

ghost commented May 16, 2019

@moogoo78

curl -v --cookie "" \
  --header "Content-Type: application/json" \
  --request GET \
  --data '{"decimalLatitude":24.564853,"decimalLongitude":120.991452}' \
  https://api-dev.camera-trap.tw/api/v1/forest-compartment-boundary | jq`

得到

{
  "message": "decimalLongitude: This field is required.\ndecimalLatitude: This field is required."
}

另外也缺文件喔。

@ghost
Copy link
Author

ghost commented May 17, 2019

Verified. Document to clarify usage: http://bit.ly/2VKfuhb.

@ghost ghost closed this as completed May 17, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
previous 上一版的問題
Projects
API v1
  
Done
API v0 development
  
In progress
Development

No branches or pull requests

4 participants