我对Geopandas有疑问。
我有一个国家的形状文件,该国家正在将其加载到Geopandas中。形状文件具有国家中所有州的形状。
我需要提取一个状态。我曾尝试探索文档和stackoverflow,但无法使我around绕于如何使用query()
方法来检索单个状态。
import geopandas as gpd
import os
# get current directory path
cur_dir = os.path.dirname(os.path.realpath(__file__))
gdf_shp_state = gpd.read_file(cur_dir + '/data/StateBoundary/StateBoundary.shp')
print(type(gdf_shp_state))
print(gdf_shp_state)
输出:
<class 'geopandas.geodataframe.GeoDataFrame'>
state geometry
0 ANDAMAN & NICOBAR (POLYGON ((10341718.474 1449533.160500001, 103...
1 CHANDIGARH POLYGON ((8546255.616099998 3606050.813100003,...
2 DADAR & NAGAR HAVELI (POLYGON ((8137193.4859 2315664.964499999, 813...
3 DAMAN & DIU (POLYGON ((8111624.4714 2328002.898499999, 811...
4 DELHI POLYGON ((8583390.569699999 3359116.190099999,...
5 HARYANA POLYGON ((8524318.5392 3516490.864500001, 8524...
6 JHARKHAND POLYGON ((9762288.284699999 2772949.712499999,...
问题是:如何查询GeoDataFrame?
有一个名为gdf_shp_state.query()
的方法,它希望我将查询作为string
进行输入。有人可以帮我提供一个示例查询字符串,我需要使用该示例查询字符串来获取单一状态的GeoDataFrame?
答案 0 :(得分:1)
地理数据帧的工作方式与常规数据帧相同,因此此处的查询可能是
[20/03/2019 16:09:14] Executed 'AnalyzeVocabulary' (Failed, Id=cb768548-dd06-4f95-b889-af244af716d1)
[20/03/2019 16:09:14] System.Private.CoreLib: Exception while executing function: AnalyzeVocabulary. icu.net: Can't load ICU library (version 0).
[20/03/2019 16:09:14] 926e7209782c408984ad827cc2744b2d: Function 'AnalyzeVocabulary (Activity)' failed with an error. Reason: System.IO.FileLoadException: Can't load ICU library (version 0)
[20/03/2019 16:09:14] File name: 'icuuc'
[20/03/2019 16:09:14] at Icu.NativeMethods.LoadIcuLibrary(String libraryName)
[20/03/2019 16:09:14] at Icu.NativeMethods.get_IcuCommonLibHandle()
[20/03/2019 16:09:14] at Icu.NativeMethods.uloc_canonicalize(String localeID, IntPtr name, Int32 nameCapacity, ErrorCode& err)
[20/03/2019 16:09:14] at Icu.Locale.<>c__DisplayClass44_0`1.<GetString>b__0(IntPtr ptr, Int32 length)
[20/03/2019 16:09:14] at Icu.NativeMethods.GetString(Func`3 lambda, Boolean isUnicodeString, Int32 initialLength)
[20/03/2019 16:09:14] at Icu.Locale.GetString[T](GetStringMethod`1 method, T localeId)
[20/03/2019 16:09:14] at Icu.Locale.Canonicalize(String localeID)
[20/03/2019 16:09:14] at Icu.Locale.op_Implicit(String localeId)
[20/03/2019 16:09:14] at DigitalLinguistics.TextAnalytics.TextSegApiTokenizer.TextTokenizer.SegmentSentences(String sentence) in E:\DigitalLinguistics\Dev\ServerlessSentinel\DigitalLinguistics.TextAnalytics\TextTokenizer.cs:line 70
[20/03/2019 16:09:14] at DigitalLinguistics.TextAnalytics.TextSegApiTokenizer.TextTokenizer.Tokenize(String sentence, String id) in E:\DigitalLinguistics\Dev\ServerlessSentinel\DigitalLinguistics.TextAnalytics\TextTokenizer.cs:line 82
[20/03/2019 16:09:14] at DigitalLinguistics.TextAnalytics.DataStructures.Sentence.LineParse(String text, String id, TokenizerOptions tokenOpts) in E:\DigitalLinguistics\Dev\ServerlessSentinel\DigitalLinguistics.TextAnalytics\Sentence.cs:line 92
要选择状态等于gdf_shp_state.query("state=='ANDAMAN & NICOBAR'")
的行
以上等同于:
'ANDAMAN & NICOBAR'