{"id":982958,"date":"2024-12-27T07:15:16","date_gmt":"2024-12-26T23:15:16","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/982958.html"},"modified":"2024-12-27T07:15:19","modified_gmt":"2024-12-26T23:15:19","slug":"python%e5%a6%82%e4%bd%95%e8%af%bb%e5%8f%96shp%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/982958.html","title":{"rendered":"python\u5982\u4f55\u8bfb\u53d6shp\u6587\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24211215\/a8a15f19-7632-48e3-b81d-80dcdeb341fb.webp\" alt=\"python\u5982\u4f55\u8bfb\u53d6shp\u6587\u4ef6\" \/><\/p>\n<p><p> <strong>Python\u8bfb\u53d6shp\u6587\u4ef6\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\uff1a\u4f7f\u7528<code>geopandas<\/code>\u5e93\u3001\u4f7f\u7528<code>pyshp<\/code>\u5e93\u3001\u4f7f\u7528<code>fiona<\/code>\u5e93\u3002<\/strong>\u5176\u4e2d\uff0c<code>geopandas<\/code>\u5e93\u662f\u6700\u5e38\u7528\u4e14\u529f\u80fd\u5f3a\u5927\u7684\u9009\u62e9\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u5bf9\u5730\u7406\u6570\u636e\u7684\u9ad8\u6548\u5904\u7406\u80fd\u529b\uff0c\u5e76\u4e14\u4e0e<code>pandas<\/code>\u5e93\u7684\u7ed3\u5408\u4f7f\u7528\u53ef\u4ee5\u8fdb\u884c\u66f4\u590d\u6742\u7684\u6570\u636e\u5206\u6790\u3002<\/p>\n<\/p>\n<p><p>\u5728\u8be6\u7ec6\u63cf\u8ff0\u4e2d\uff0c\u6211\u4eec\u5c06\u91cd\u70b9\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528<code>geopandas<\/code>\u5e93\u8bfb\u53d6\u548c\u5904\u7406shp\u6587\u4ef6\u3002<code>geopandas<\/code>\u662f\u4e00\u4e2a\u5f00\u6e90\u7684Python\u5e93\uff0c\u4e13\u4e3a\u5904\u7406\u5730\u7406\u6570\u636e\u800c\u8bbe\u8ba1\u3002\u5b83\u7684\u5f3a\u5927\u529f\u80fd\u6e90\u4e8e\u5c06<code>pandas<\/code>\u5e93\u7684\u6570\u636e\u5904\u7406\u80fd\u529b\u4e0e<code>shapely<\/code>\u3001<code>fiona<\/code>\u7b49\u5730\u7406\u5904\u7406\u5e93\u7ed3\u5408\u5728\u4e00\u8d77\u3002\u8981\u4f7f\u7528<code>geopandas<\/code>\uff0c\u9996\u5148\u9700\u8981\u786e\u4fddPython\u73af\u5883\u4e2d\u5df2\u5b89\u88c5\u8be5\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7<code>pip install geopandas<\/code>\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8bfb\u53d6shp\u6587\u4ef6\u5c31\u53d8\u5f97\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u4f7f\u7528<code>geopandas.read_file()<\/code>\u51fd\u6570\u5373\u53ef\u3002\u8be5\u51fd\u6570\u4f1a\u8fd4\u56de\u4e00\u4e2a<code>GeoDataFrame<\/code>\u5bf9\u8c61\uff0c\u4e0e<code>pandas<\/code>\u7684<code>DataFrame<\/code>\u7c7b\u4f3c\uff0c\u4f46\u589e\u52a0\u4e86\u5730\u7406\u4fe1\u606f\u7684\u5904\u7406\u80fd\u529b\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001GEOPANDAS\u5e93\u7684\u4f7f\u7528<\/p>\n<\/p>\n<p><p><code>geopandas<\/code>\u662f\u4e00\u4e2a\u4e13\u4e3a\u5730\u7406\u6570\u636e\u8bbe\u8ba1\u7684Python\u5e93\uff0c\u5b83\u57fa\u4e8e<code>pandas<\/code>\u5e93\u6784\u5efa\uff0c\u589e\u52a0\u4e86\u5bf9\u5730\u7406\u6570\u636e\u7c7b\u578b\u7684\u652f\u6301\u3002\u4f7f\u7528<code>geopandas<\/code>\u8bfb\u53d6shp\u6587\u4ef6\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u4e0e\u5bfc\u5165\u5e93<\/strong><\/p>\n<p>\u8981\u4f7f\u7528<code>geopandas<\/code>\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5b89\u88c5\u4e86\u8be5\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install geopandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import geopandas as gpd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bfb\u53d6shp\u6587\u4ef6<\/strong><\/p>\n<p>\u4f7f\u7528<code>geopandas<\/code>\u8bfb\u53d6shp\u6587\u4ef6\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8c03\u7528<code>read_file()<\/code>\u65b9\u6cd5\uff0c\u4f20\u5165shp\u6587\u4ef6\u7684\u8def\u5f84\u5373\u53ef\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">gdf = gpd.read_file(&#39;path_to_your_shapefile.shp&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u5c06shp\u6587\u4ef6\u8bfb\u53d6\u4e3a\u4e00\u4e2a<code>GeoDataFrame<\/code>\u5bf9\u8c61\uff0c<code>GeoDataFrame<\/code>\u662f<code>geopandas<\/code>\u7684\u6838\u5fc3\u6570\u636e\u7ed3\u6784\uff0c\u7c7b\u4f3c\u4e8e<code>pandas<\/code>\u7684<code>DataFrame<\/code>\uff0c\u4f46\u589e\u52a0\u4e86\u5bf9\u5730\u7406\u4fe1\u606f\u7684\u652f\u6301\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u5904\u7406\u4e0e\u5206\u6790<\/strong><\/p>\n<p>\u8bfb\u53d6shp\u6587\u4ef6\u540e\uff0c\u53ef\u4ee5\u5229\u7528<code>GeoDataFrame<\/code>\u7684\u4e30\u5bcc\u65b9\u6cd5\u8fdb\u884c\u6570\u636e\u5904\u7406\u4e0e\u5206\u6790\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>plot()<\/code>\u65b9\u6cd5\u76f4\u63a5\u53ef\u89c6\u5316\u5730\u7406\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">gdf.plot()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd8\u53ef\u4ee5\u5bf9\u5730\u7406\u6570\u636e\u8fdb\u884c\u5404\u79cd\u67e5\u8be2\u548c\u64cd\u4f5c\uff0c\u4f8b\u5982\u7b5b\u9009\u7279\u5b9a\u533a\u57df\u3001\u8ba1\u7b97\u9762\u79ef\u3001\u5408\u5e76\u6570\u636e\u7b49\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001PYSHAP\u5e93\u7684\u4f7f\u7528<\/p>\n<\/p>\n<p><p><code>pyshp<\/code>\u5e93\uff0c\u53c8\u540d<code>shapefile<\/code>\u5e93\uff0c\u662f\u4e00\u4e2a\u7eafPython\u5e93\uff0c\u7528\u4e8e\u8bfb\u53d6\u548c\u5199\u5165ESRI\u683c\u5f0f\u7684shp\u6587\u4ef6\u3002\u5c3d\u7ba1\u529f\u80fd\u4e0d\u5982<code>geopandas<\/code>\u5f3a\u5927\uff0c\u4f46\u5bf9\u4e8e\u7b80\u5355\u7684shp\u6587\u4ef6\u5904\u7406\u4efb\u52a1\u6765\u8bf4\uff0c\u5b83\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u9009\u62e9\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u4e0e\u5bfc\u5165\u5e93<\/strong><\/p>\n<p>\u540c\u6837\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5<code>pyshp<\/code>\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pyshp<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import shapefile<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bfb\u53d6shp\u6587\u4ef6<\/strong><\/p>\n<p>\u4f7f\u7528<code>pyshp<\/code>\u8bfb\u53d6shp\u6587\u4ef6\u9700\u8981\u5148\u521b\u5efa\u4e00\u4e2a<code>Reader<\/code>\u5bf9\u8c61\uff0c\u7136\u540e\u901a\u8fc7\u8be5\u5bf9\u8c61\u8bbf\u95eeshp\u6587\u4ef6\u4e2d\u7684\u8bb0\u5f55\u548c\u5f62\u72b6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sf = shapefile.Reader(&#39;path_to_your_shapefile.shp&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>Reader<\/code>\u5bf9\u8c61\u63d0\u4f9b\u4e86\u8bbf\u95eeshp\u6587\u4ef6\u4e2d\u8bb0\u5f55\u548c\u5f62\u72b6\u7684\u63a5\u53e3\uff0c\u53ef\u4ee5\u901a\u8fc7<code>shape()<\/code>\u65b9\u6cd5\u548c<code>record()<\/code>\u65b9\u6cd5\u5206\u522b\u83b7\u53d6\u5f62\u72b6\u548c\u5c5e\u6027\u6570\u636e\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bbf\u95ee\u6570\u636e<\/strong><\/p>\n<p><code>pyshp<\/code>\u8bfb\u53d6\u7684\u6570\u636e\u4fdd\u5b58\u5728\u5217\u8868\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5faa\u73af\u8bbf\u95ee\u6bcf\u4e2a\u5f62\u72b6\u53ca\u5176\u76f8\u5173\u7684\u5c5e\u6027\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for shapeRecord in sf.shapeRecords():<\/p>\n<p>    print(shapeRecord.shape.points)  # \u6253\u5370\u5f62\u72b6\u7684\u70b9\u5750\u6807<\/p>\n<p>    print(shapeRecord.record)        # \u6253\u5370\u5c5e\u6027\u6570\u636e<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001FIONA\u5e93\u7684\u4f7f\u7528<\/p>\n<\/p>\n<p><p><code>fiona<\/code>\u5e93\u662f\u53e6\u4e00\u4e2a\u7528\u4e8e\u8bfb\u53d6\u548c\u5199\u5165\u5730\u7406\u6570\u636e\u7684Python\u5e93\uff0c\u5b83\u662f<code>geopandas<\/code>\u5e93\u5e95\u5c42\u4f7f\u7528\u7684\u4e00\u4e2a\u91cd\u8981\u7ec4\u6210\u90e8\u5206\u3002\u4e0e<code>geopandas<\/code>\u4e0d\u540c\uff0c<code>fiona<\/code>\u76f4\u63a5\u63d0\u4f9b\u4e86\u5bf9\u5730\u7406\u6587\u4ef6\u7684\u8bfb\u53d6\u548c\u5199\u5165\u529f\u80fd\uff0c\u800c\u4e0d\u8fdb\u884c\u6570\u636e\u7684\u8fdb\u4e00\u6b65\u5904\u7406\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u4e0e\u5bfc\u5165\u5e93<\/strong><\/p>\n<p>\u9996\u5148\u5b89\u88c5<code>fiona<\/code>\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install fiona<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import fiona<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bfb\u53d6shp\u6587\u4ef6<\/strong><\/p>\n<p>\u4f7f\u7528<code>fiona<\/code>\u8bfb\u53d6shp\u6587\u4ef6\u9700\u8981\u6253\u5f00\u6587\u4ef6\uff0c\u5e76\u901a\u8fc7\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\u8bbf\u95ee\u5176\u4e2d\u7684\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">with fiona.open(&#39;path_to_your_shapefile.shp&#39;) as shp:<\/p>\n<p>    for feature in shp:<\/p>\n<p>        print(feature[&#39;geometry&#39;])  # \u6253\u5370\u51e0\u4f55\u4fe1\u606f<\/p>\n<p>        print(feature[&#39;properties&#39;])  # \u6253\u5370\u5c5e\u6027\u4fe1\u606f<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u5904\u7406<\/strong><\/p>\n<p><code>fiona<\/code>\u8bfb\u53d6\u7684\u6570\u636e\u662f\u539f\u59cb\u7684\u5730\u7406JSON\u683c\u5f0f\uff0c\u53ef\u4ee5\u7ed3\u5408\u5176\u4ed6\u5e93\u8fdb\u884c\u8fdb\u4e00\u6b65\u5904\u7406\u3002\u5c3d\u7ba1<code>fiona<\/code>\u672c\u8eab\u4e0d\u63d0\u4f9b\u590d\u6742\u7684\u5730\u7406\u6570\u636e\u5904\u7406\u529f\u80fd\uff0c\u4f46\u5b83\u4e0e\u5176\u4ed6\u5730\u7406\u6570\u636e\u5904\u7406\u5e93\uff08\u5982<code>shapely<\/code>\u3001<code>pyproj<\/code>\u7b49\uff09\u4e00\u8d77\u4f7f\u7528\u65f6\uff0c\u53ef\u4ee5\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u5730\u7406\u6570\u636e\u5206\u6790\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001SHAPELY\u5e93\u7684\u7ed3\u5408\u4f7f\u7528<\/p>\n<\/p>\n<p><p><code>shapely<\/code>\u662f\u4e00\u4e2a\u4e13\u95e8\u7528\u4e8e\u64cd\u4f5c\u548c\u5206\u6790\u5e73\u9762\u51e0\u4f55\u5bf9\u8c61\u7684\u5e93\uff0c\u4e0e<code>geopandas<\/code>\u3001<code>fiona<\/code>\u7ed3\u5408\u4f7f\u7528\u53ef\u4ee5\u589e\u5f3a\u5730\u7406\u6570\u636e\u5904\u7406\u7684\u80fd\u529b\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u4e0e\u5bfc\u5165\u5e93<\/strong><\/p>\n<p>\u5b89\u88c5<code>shapely<\/code>\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install shapely<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5bfc\u5165<code>shapely<\/code>\u5e93\u7684\u4e00\u4e9b\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from shapely.geometry import shape<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u51e0\u4f55\u64cd\u4f5c<\/strong><\/p>\n<p>\u4f7f\u7528<code>shapely<\/code>\u53ef\u4ee5\u5bf9\u51e0\u4f55\u5bf9\u8c61\u8fdb\u884c\u5404\u79cd\u64cd\u4f5c\uff0c\u5982\u8ba1\u7b97\u9762\u79ef\u3001\u5468\u957f\u3001\u7f13\u51b2\u533a\u7b49\u3002\u4f8b\u5982\uff0c\u7ed3\u5408<code>fiona<\/code>\u8bfb\u53d6\u7684\u51e0\u4f55\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>shape()<\/code>\u65b9\u6cd5\u5c06\u5176\u8f6c\u5316\u4e3a<code>shapely<\/code>\u7684\u51e0\u4f55\u5bf9\u8c61\uff0c\u7136\u540e\u8fdb\u884c\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">with fiona.open(&#39;path_to_your_shapefile.shp&#39;) as shp:<\/p>\n<p>    for feature in shp:<\/p>\n<p>        geom = shape(feature[&#39;geometry&#39;])<\/p>\n<p>        print(geom.area)  # \u6253\u5370\u51e0\u4f55\u5bf9\u8c61\u7684\u9762\u79ef<\/p>\n<p>        print(geom.length)  # \u6253\u5370\u51e0\u4f55\u5bf9\u8c61\u7684\u5468\u957f<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u8bfb\u53d6\u548c\u5904\u7406shp\u6587\u4ef6\u5728\u5730\u7406\u6570\u636e\u5206\u6790\u4e2d\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u4efb\u52a1\u3002Python\u63d0\u4f9b\u4e86\u591a\u79cd\u5e93\u6765\u5904\u7406shp\u6587\u4ef6\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f<code>geopandas<\/code>\u5e93\uff0c\u5b83\u7ed3\u5408\u4e86<code>pandas<\/code>\u7684\u6613\u7528\u6027\u4e0e\u5730\u7406\u6570\u636e\u5904\u7406\u7684\u5f3a\u5927\u529f\u80fd\uff0c\u662f\u8fdb\u884c\u5730\u7406\u6570\u636e\u5206\u6790\u7684\u9996\u9009\u5de5\u5177\u3002\u6b64\u5916\uff0c<code>pyshp<\/code>\u548c<code>fiona<\/code>\u5e93\u4e5f\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684shp\u6587\u4ef6\u8bfb\u53d6\u4e0e\u5199\u5165\u529f\u80fd\uff0c\u9002\u5408\u4e0d\u540c\u7684\u4f7f\u7528\u573a\u666f\u3002\u5728\u5904\u7406shp\u6587\u4ef6\u65f6\uff0c\u901a\u5e38\u9700\u8981\u7ed3\u5408\u5176\u4ed6\u5730\u7406\u6570\u636e\u5904\u7406\u5e93\uff08\u5982<code>shapely<\/code>\uff09\u4ee5\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u5206\u6790\u548c\u64cd\u4f5c\u3002\u901a\u8fc7\u5408\u7406\u5730\u9009\u62e9\u548c\u7ec4\u5408\u8fd9\u4e9b\u5e93\uff0c\u53ef\u4ee5\u5728Python\u4e2d\u9ad8\u6548\u5730\u5904\u7406\u548c\u5206\u6790\u5730\u7406\u6570\u636e\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bfb\u53d6shp\u6587\u4ef6\uff1f<\/strong><br \/>\u5728Python\u4e2d\u8bfb\u53d6shp\u6587\u4ef6\u901a\u5e38\u4f7f\u7528GeoPandas\u5e93\u3002GeoPandas\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5730\u7406\u6570\u636e\u5904\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406\u5730\u7406\u4fe1\u606f\u7cfb\u7edf\uff08GIS\uff09\u4e2d\u7684\u77e2\u91cf\u6570\u636e\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u6765\u8bfb\u53d6shp\u6587\u4ef6\uff1a<\/p>\n<ol>\n<li>\u786e\u4fdd\u60a8\u5df2\u5b89\u88c5GeoPandas\u5e93\uff0c\u4f7f\u7528\u547d\u4ee4<code>pip install geopandas<\/code>\u8fdb\u884c\u5b89\u88c5\u3002<\/li>\n<li>\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bfb\u53d6shp\u6587\u4ef6\uff1a\n<pre><code class=\"language-python\">import geopandas as gpd\ndata = gpd.read_file(&#39;path\/to\/your\/file.shp&#39;)\nprint(data.head())\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>\u8fd9\u5c06\u52a0\u8f7dshp\u6587\u4ef6\u5e76\u663e\u793a\u6570\u636e\u7684\u524d\u51e0\u884c\u3002<\/p>\n<p><strong>\u9664\u4e86GeoPandas\uff0c\u8fd8\u6709\u54ea\u4e9b\u5e93\u53ef\u4ee5\u8bfb\u53d6shp\u6587\u4ef6\uff1f<\/strong><br \/>\u9664\u4e86GeoPandas\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u5e93\u6765\u8bfb\u53d6shp\u6587\u4ef6\uff0c\u4f8b\u5982Fiona\u548cPyShp\u3002Fiona\u662f\u4e00\u4e2a\u4e13\u95e8\u7528\u4e8e\u8bfb\u53d6\u548c\u5199\u5165\u77e2\u91cf\u6570\u636e\u7684\u5e93\uff0c\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import fiona\nwith fiona.open(&#39;path\/to\/your\/file.shp&#39;) as shp:\n    for feature in shp:\n        print(feature)\n<\/code><\/pre>\n<p>PyShp\u4e5f\u662f\u4e00\u4e2a\u6d41\u884c\u7684\u5e93\uff0c\u4e13\u6ce8\u4e8e\u5904\u7406shp\u6587\u4ef6\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7<code>pip install pyshp<\/code>\u5b89\u88c5\u5b83\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u8bfb\u53d6shp\u6587\u4ef6\u540e\u7684\u6570\u636e\uff1f<\/strong><br \/>\u8bfb\u53d6shp\u6587\u4ef6\u540e\uff0c\u901a\u5e38\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u8fdb\u4e00\u6b65\u5206\u6790\u6216\u53ef\u89c6\u5316\u3002\u4f7f\u7528GeoPandas\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u8fdb\u884c\u7a7a\u95f4\u5206\u6790\uff0c\u4f8b\u5982\u8fc7\u6ee4\u7279\u5b9a\u533a\u57df\u3001\u8ba1\u7b97\u51e0\u4f55\u5c5e\u6027\u6216\u5408\u5e76\u4e0d\u540c\u7684\u5730\u7406\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u64cd\u4f5c\u7684\u793a\u4f8b\uff1a<\/p>\n<ul>\n<li>\u8fc7\u6ee4\u7279\u5b9a\u5c5e\u6027\uff1a\n<pre><code class=\"language-python\">filtered_data = data[data[&#39;column_name&#39;] == &#39;value&#39;]\n<\/code><\/pre>\n<\/li>\n<li>\u7ed8\u5236\u5730\u56fe\uff1a\n<pre><code class=\"language-python\">data.plot()\nimport matplotlib.pyplot as plt\nplt.show()\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u64cd\u4f5c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5bf9\u5730\u7406\u6570\u636e\u8fdb\u884c\u6df1\u5165\u5206\u6790\u548c\u5c55\u793a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u8bfb\u53d6shp\u6587\u4ef6\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\uff1a\u4f7f\u7528geopandas\u5e93\u3001\u4f7f\u7528pyshp\u5e93\u3001\u4f7f\u7528fiona\u5e93\u3002\u5176\u4e2d\uff0cg [&hellip;]","protected":false},"author":3,"featured_media":982963,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/982958"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=982958"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/982958\/revisions"}],"predecessor-version":[{"id":982966,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/982958\/revisions\/982966"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/982963"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=982958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=982958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=982958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}