0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Shapefileから面積を求める

Posted at

はじめに

Shapefileを扱う機会があったので、操作と面積計算の方法の記録。

環境

pip install geopandas

基本操作

1. Shapefileを読み込む

import geopandas as gpd

# Shapefileを読み込み
gdf = gpd.read_file("your_shapefile.shp", encoding='cp932')

# 確認
gdf.head()

2. ジオメトリタイプを調べる

# ジオメトリタイプを確認
gdf.geometry.type

出力例:

0      Polygon
1      Polygon
2      Polygon
...
dtype: object
  • 面積を計算できるのは PolygonMultiPolygon のみ

3. 座標系(CRS)を調べる

# 座標系を確認
gdf.crs

出力例:

<Projected CRS: EPSG:6671>
Name: JGD2011 / Japan Plane Rectangular CS III

面積を計算する

投影座標系に変換

# 投影座標系に変換
# 例えば広島県の平面直角座標系(EPSG:6671など)
gdf_proj = gdf.to_crs(epsg=6671)

面積の計算

# 面積(平方メートル)
gdf_proj['area_m2'] = gdf_proj.geometry.area

# ヘクタール
gdf_proj['area_ha'] = gdf_proj['area_m2'] / 10_000

まとめ

Shapefileから面積を計算する時のフロー:

  1. gpd.read_file() でShapefileを読み込み
  2. .geometry.type でジオメトリタイプを確認
  3. .crs で座標系を確認
  4. 必要に応じて .to_crs() で投影座標系に変換
  5. .geometry.area で面積を計算
  6. 必要な単位に変換(haなど)

参考

Shapefileについて

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?