シェープファイルへの書き出し
今回は作成した world を書き出す
これは GeodataFlameになっていれば簡単にできる
保存するときにはto_file を使う
シェープファイルで保存するなら
world.to_file(driver='ESRI Shapefile',filename='test_shape_world.shp')
というように
driverへ ESRI Shapefileを指定すればいい
でも
/Users/snowpool/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pyogrio/raw.py:723: RuntimeWarning: Value 328239523 of field POP_EST of feature 4 not successfully written. Possibly due to too larger number with respect to field width ogr_write( /Users/snowpool/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pyogrio/raw.py:723: RuntimeWarning: Value 270625568 of field POP_EST of feature 8 not successfully written. Possibly due to too larger number with respect to field width ogr_write( /Users/snowpool/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pyogrio/raw.py:723: RuntimeWarning: Value 144373535 of field POP_EST of feature 18 not successfully written. Possibly due to too larger number with respect to field width ogr_write( /Users/snowpool/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pyogrio/raw.py:723: RuntimeWarning: Value 127575529 of field POP_EST of feature 27 not successfully written. Possibly due to too larger number with respect to field width ogr_write( /Users/snowpool/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pyogrio/raw.py:723: RuntimeWarning: Value 211049527 of field POP_EST of feature 29 not successfully written. Possibly due to too larger number with respect to field width ogr_write( /Users/snowpool/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pyogrio/raw.py:723: RuntimeWarning: Value 200963599 of field POP_EST of feature 56 not successfully written. Possibly due to too larger number with respect to field width ogr_write( /Users/snowpool/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pyogrio/raw.py:723: RuntimeWarning: Value 1366417754 of field POP_EST of feature 98 not successfully written. Possibly due to too larger number with respect to field width ogr_write( /Users/snowpool/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pyogrio/raw.py:723: RuntimeWarning: Value 163046161 of field POP_EST of feature 99 not successfully written. Possibly due to too larger number with respect to field width ogr_write( /Users/snowpool/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pyogrio/raw.py:723: RuntimeWarning: Value 216565318 of field POP_EST of feature 102 not successfully written. Possibly due to too larger number with respect to field width ogr_write( /Users/snowpool/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pyogrio/raw.py:723: RuntimeWarning: Value 1397715000 of field POP_EST of feature 139 not successfully written. Possibly due to too larger number with respect to field width ogr_write( /Users/snowpool/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pyogrio/raw.py:723: RuntimeWarning: Value 108116615 of field POP_EST of feature 147 not successfully written. Possibly due to too larger number with respect to field width ogr_write( /Users/snowpool/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pyogrio/raw.py:723: RuntimeWarning: Value 126264931 of field POP_EST of feature 155 not successfully written. Possibly due to too larger number with respect to field width ogr_write( /Users/snowpool/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pyogrio/raw.py:723: RuntimeWarning: Value 100388073 of field POP_EST of feature 163 not successfully written. Possibly due to too larger number with respect to field width ogr_write( /Users/snowpool/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pyogrio/raw.py:723: RuntimeWarning: Value 112078730 of field POP_EST of feature 165 not successfully written. Possibly due to too larger number with respect to field width ogr_write(
となる
GPTによれば
併せて知っておくと良い Shapefile の制約
* フィールド名は最大 10 文字(長い列名は切られる)
* 文字列の最大長、数値の幅と小数点以下桁を持つ
* 64bit 整数を正式には持てない
* 複数のファイル(.shp/.shx/.dbf …)が必要
警告は Shapefile のフィールド幅不足。
ベストは GeoPackage/GeoJSON へ保存。
Shapefile が必須なら layer_options で幅指定を。
これは Shapefile(.shp)側の制約で数値フィールドの桁数が足りないために出る警告です。
Shapefile は属性を dBase(DBF) で持ちますが、各数値フィールドには「幅(桁数)と小数桁」を設定する必要があり、デフォルト推定だと POP_EST のような 10桁超え(例: 1,306,370,000) が収まりきらずに “not successfully written / too large for field width” になります。
Shapefile は古く、制限が多いです。GeoPackageやGeoJSONなら桁数制限に悩まされません。
このためGeoJSONでj保存する
world.to_file(driver='GeoJSON',filename='test_shape_world.geojson')
driverにGeoJSON ファイル拡張子を .geojsonにすればOK