日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

mac os 安装 s2geometry + pywarps2

發布時間:2024/3/13 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mac os 安装 s2geometry + pywarps2 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄

  • mac os 安裝 s2geometry + pywarps2
    • 1. 安裝s2geometry
      • 1.1 安裝gtest
      • 1.2 安裝swig
      • 1.3 安裝s2geometry
    • 2. 安裝python相關依賴
    • 3. 代碼測試
    • 4. 相關參考

mac os 安裝 s2geometry + pywarps2

因python項目需要使用s2geometry,安裝遇到一些問題與解決的記錄。

1. 安裝s2geometry

如果沒有cmake需要先安裝cmake

brew install cmake

1.1 安裝gtest

安裝之前需要先安裝gtest

git clone https://github.com/google/googletest.git cd googletest mkdir build cd build cmake -DCMAKE_CXX_COMPILER="c++" -DCMAKE_CXX_FLAGS="-std=c++11 -stdlib=libc++" -DCMAKE_INSTALL_PREFIX=/usr .. make sudo make install

1.2 安裝swig

brew install swig

先安裝swig后,下一步安裝s2geometry會自動將pywraps2的module裝到python site-package里。

1.3 安裝s2geometry

安裝前檢查一下python3版本號,現在測試python3.7可以成功,但python3.8會提示"Undefined symbols for architecture x86_64"錯誤。

git clone https://github.com/google/s2geometry.git cd s2geometry mkdir build cd build ## -D 參數根據自己系統安裝的相關路進行定義 cmake -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl@1.1/1.1.1g -DGTEST_ROOT=/usr/src/googletest/googletest -DCMAKE_INSTALL_PREFIX=/usr .. make sudo make install

OPENSSL_ROOT_DIR 和 GTEST_ROOT 可以根據自己的安裝路徑修改。

另外需要注意看見以下兩條輸出日志確認pywraps2安裝成功:

-- Installing: /usr/lib/python3.7/site-packages/_pywraps2.so -- Installing: /usr/lib/python3.7/site-packages/pywraps2.py

2. 安裝python相關依賴

## 先通過brew安裝相關依賴 brew install proj geospip install jupyter pip install cython pip install numpy## 安裝Cartopy不能直接安裝,會報錯找不到proj_api.h ## 解決方法參考自:https://github.com/SciTools/cartopy/issues/1288 export CFLAGS="-I/usr/local/include" export LDFLAGS="-L/usr/local/lib" pip install git+https://github.com/snowman2/cartopy.git pip install matplotlib scikit-learn scipy Shapely folium geojson

3. 代碼測試

import folium import pywraps2 as s2# create a rect in s2 region_rect = s2.S2LatLngRect(s2.S2LatLng.FromDegrees(48.831776, 2.222639),s2.S2LatLng.FromDegrees(48.902839, 2.406))# ask s2 to create a cover of this rect coverer = s2.S2RegionCoverer() coverer.set_min_level(10) coverer.set_max_level(30) coverer.set_max_cells(60) covering = coverer.GetCovering(region_rect) print([c.ToToken() for c in covering])# create a map map_osm = folium.Map(location=[48.86, 2.3],zoom_start=12, tiles='Stamen Toner')# get vertices from rect to draw them on map rect_vertices = [] for i in [0, 1, 2, 3, 0]:vertex = region_rect.GetVertex(i)rect_vertices.append([vertex.lat().degrees(), vertex.lng().degrees()])# draw the cells style_function = lambda x: {'weight': 1, 'fillColor':'#eea500'} for cellid in covering:cell = s2.S2Cell(cellid)vertices = []for i in range(0, 4):vertex = cell.GetVertex(i)latlng = s2.S2LatLng(vertex)vertices.append([latlng.lng().degrees(),latlng.lat().degrees()])gj = folium.GeoJson({ "type": "Polygon", "coordinates": [vertices]}, style_function=style_function)gj.add_children(folium.Popup(cellid.ToToken()))gj.add_to(map_osm)# warning PolyLine is lat,lng based while GeoJSON is not ls = folium.PolyLine(rect_vertices, color='red', weight=2) ls.add_children(folium.Popup("shape")) ls.add_to(map_osm)map_osm

4. 相關參考

S2 Geometry Library building
Google S2 with Python & Jupyter
How to install GTest on Mac OS X with homebrew?
S2 compatible with python3?

總結

以上是生活随笔為你收集整理的mac os 安装 s2geometry + pywarps2的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。