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

都市モデルのprebuild時にGeoDataFrameのcrsプロパティへのアクセスでAttributeErrorとなる #1

Closed
s3works opened this issue Mar 5, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@s3works
Copy link

s3works commented Mar 5, 2024

東京都23区データ(plateau-tokyo23ku-2022)のインストール時にエラーとなります。すべての都市モデルを調べたわけではありませんが、東村山市(plateau-13213-higashimurayama-shi-2020)、川崎市(plateau-14130-kawasaki-shi-2022)、横浜市(plateau-14100-yokohama-shi-2022)では出ていません。

データのダウンロードはうまくいっているようです。そこでローカルのデータに対してprebuildしてみました。

from plateaukit.prebuild import prebuild
dataset_id = "plateau-tokyo23ku-2022"
prebuild(dataset_id, split=1, simple_output=False)

すると、下記のエラーが発生します。

AttributeError Traceback (most recent call last)
Cell In[32], line 3
1 from plateaukit.prebuild import prebuild
2 dataset_id = "plateau-tokyo23ku-2022"
----> 3 prebuild(dataset_id, split=1, simple_output=False)

File /opt/conda/lib/python3.11/site-packages/plateaukit/prebuild.py:64, in prebuild(dataset_id, split, simple_output)
61 df = pd.concat([df, subdf])
63 # TODO: Use more accurate CRS
---> 64 centroid = df.to_crs(3857).centroid.to_crs(4326)
66 df["longitude"] = centroid.x
67 df["latitude"] = centroid.y

File /opt/conda/lib/python3.11/site-packages/geopandas/geodataframe.py:1407, in GeoDataFrame.to_crs(self, crs, epsg, inplace)
1405 else:
1406 df = self.copy()
-> 1407 geom = df.geometry.to_crs(crs=crs, epsg=epsg)
1408 df.geometry = geom
1409 if not inplace:

File /opt/conda/lib/python3.11/site-packages/pandas/core/generic.py:6204, in NDFrame.getattr(self, name)
6197 if (
6198 name not in self._internal_names_set
6199 and name not in self._metadata
6200 and name not in self._accessors
6201 and self._info_axis._can_hold_identifiers_and_holds_name(name)
6202 ):
6203 return self[name]
-> 6204 return object.getattribute(self, name)

File /opt/conda/lib/python3.11/site-packages/geopandas/geodataframe.py:236, in GeoDataFrame._get_geometry(self)
229 else:
230 msg += (
231 "\nThere are no existing columns with geometry data type. You can "
232 "add a geometry column as the active geometry column with "
233 "df.set_geometry. "
234 )
--> 236 raise AttributeError(msg)
237 return self[self._geometry_column_name]

AttributeError: You are calling a geospatial method on the GeoDataFrame, but the active geometry column to use has not been set.
There are no existing columns with geometry data type. You can add a geometry column as the active geometry column with df.set_geometry.

これは、GeoPandas v0.12で変更された下記が影響しているようです。

Accessing the crs of a GeoDataFrame without active geometry column was deprecated and this now raises an AttributeError (#2578).

こちらの実行環境です。

Ubuntu 22.04.3 LTS
Python 3.11.6
pip 24.0
jupyterlab 4.0.7
geopandas 0.14.3

@ozekik ozekik added bug Something isn't working just a moment labels Mar 5, 2024
@ozekik ozekik mentioned this issue Mar 5, 2024
@ozekik ozekik closed this as completed in 1912c6a Mar 5, 2024
@ozekik
Copy link
Owner

ozekik commented Mar 5, 2024

ご報告ありがとうございます!直近の変更に起因して prebuild 時のXML (CityGML) の処理に不具合が生じていたようです。修正版をv0.11.2としてリリースしました。

@s3works
Copy link
Author

s3works commented Mar 5, 2024

早速のご対応ありがとうございます。修正版v0.11.2で東京都23区データ(plateau-tokyo23ku-2022)をprebuildしてみましたが、AttributeErrorが出ています。

AttributeError Traceback (most recent call last)
Cell In[1], line 3
1 from plateaukit.prebuild import prebuild
2 dataset_id = "plateau-tokyo23ku-2022"
----> 3 prebuild(dataset_id, split=1, simple_output=False)

File /opt/conda/lib/python3.11/site-packages/plateaukit/prebuild.py:64, in prebuild(dataset_id, split, simple_output)
61 df = pd.concat([df, subdf])
63 # TODO: Use more accurate CRS
---> 64 centroid = df.to_crs(3857).centroid.to_crs(4326)
66 df["longitude"] = centroid.x
67 df["latitude"] = centroid.y

File /opt/conda/lib/python3.11/site-packages/geopandas/geodataframe.py:1407, in GeoDataFrame.to_crs(self, crs, epsg, inplace)
1405 else:
1406 df = self.copy()
-> 1407 geom = df.geometry.to_crs(crs=crs, epsg=epsg)
1408 df.geometry = geom
1409 if not inplace:

File /opt/conda/lib/python3.11/site-packages/pandas/core/generic.py:6296, in NDFrame.getattr(self, name)
6289 if (
6290 name not in self._internal_names_set
6291 and name not in self._metadata
6292 and name not in self._accessors
6293 and self._info_axis._can_hold_identifiers_and_holds_name(name)
6294 ):
6295 return self[name]
-> 6296 return object.getattribute(self, name)

File /opt/conda/lib/python3.11/site-packages/geopandas/geodataframe.py:236, in GeoDataFrame._get_geometry(self)
229 else:
230 msg += (
231 "\nThere are no existing columns with geometry data type. You can "
232 "add a geometry column as the active geometry column with "
233 "df.set_geometry. "
234 )
--> 236 raise AttributeError(msg)
237 return self[self._geometry_column_name]

AttributeError: You are calling a geospatial method on the GeoDataFrame, but the active geometry column to use has not been set.
There are no existing columns with geometry data type. You can add a geometry column as the active geometry column with df.set_geometry.

@ozekik ozekik reopened this Mar 6, 2024
@ozekik
Copy link
Owner

ozekik commented Mar 6, 2024

すみません、再報告ありがとうございます。
いくつか環境を変えて試してみているのですが、v0.11.2ではまだエラーが再現できていません。
もう少し調査してみます。

@s3works
Copy link
Author

s3works commented Mar 7, 2024

こちらの環境の問題かもしれません。引き続き、調べてみます。

@s3works
Copy link
Author

s3works commented Mar 30, 2024

前回報告から少しあいてしましましたが、まっさらな環境に再度インストールしたところ、無事に東京都23区データをprebuildできました。最新のv0.14.2で試しています。原因は分からずじまいですが、ひとまず解決しましたのでcloseしていただければと思います。お騒がせしてすみませんでした。
なお、2023年度モデルが昨日公開されましたので、都市モデル一覧にIDを追加していただけますでしょうか。

@ozekik
Copy link
Owner

ozekik commented Apr 1, 2024

前回報告から少しあいてしましましたが、まっさらな環境に再度インストールしたところ、無事に東京都23区データをprebuildできました。最新のv0.14.2で試しています。原因は分からずじまいですが、ひとまず解決しましたのでcloseしていただければと思います。お騒がせしてすみませんでした。

フォローアップありがとうございます。引き続きいろいろ修正してみます。
テストも増やしていきたいと思いますが、また何かお気づきのことがあればお知らせいただけましたら大変助かります。

なお、2023年度モデルが昨日公開されましたので、都市モデル一覧にIDを追加していただけますでしょうか。

情報ありがとうございます!数日中にリリースできればと思います。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants