Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

readshapefile returns a multipolygon as several polygons

未关闭
#264 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python

调研方向

从 Basemap.readshapefile 入口点开始,复现提供的 Fiona 示例,并将返回的记录与源几何进行比较。当 MultiPolygon 情况保留一个源 feature 的几何和元数据,同时不破坏单独的 Polygon 情况时,即可完成。

由索引模型根据 Issue 内容生成。

描述

I wanted to draw a choropleth map using basemap. My plan was to read the polygons from the shapefile vis readshapefile and then further process them using shapely, descartes, etc.

The problem that I encountered was that readshapefile returned multiple polygons for each MultiPolygon. This causes confusion, as for the enclosed polygon we will have more than one record.

I think the fix will be to return a MultiPolygon instead of multiple polygons.

Here is an example:

from collections import OrderedDict
import fiona
from mpl_toolkits.basemap import Basemap


rec1 = dict()
rec2 = dict()

rec1['id'] = 0
rec1['type'] = 'Feature'
rec1['properties'] = OrderedDict([(u'NAME', 'outer'),(u'VALUE', 100)])
rec1['geometry'] = dict()
rec1['geometry']['type'] = 'MultiPolygon'
rec1['geometry']['coordinates'] = [[[(-50,40),(50,40),
                                    (50,-40),(-50,-40),
                                    (-50,40)
                                   ]],
                                  [[(-45,35),(45,35),
                                    (45,-35),(-45,-35),
                                    (-45,35)
                                   ]]]

rec2['id'] = 1
rec2['type'] = 'Feature'
rec2['properties'] = OrderedDict([(u'NAME', 'inner'),(u'VALUE', 1)])
rec2['geometry'] = dict()
rec2['geometry']['type'] = 'Polygon'
rec2['geometry']['coordinates'] = [[(-45,35),(45,35),
                                    (45,-35),(-45,-35),
                                    (-45,35)
                                   ]]
driver = 'ESRI Shapefile'
crs = {'no_defs': True, 'ellps': 'WGS84', 'datum': 'WGS84', 'proj': 'longlat'}
schema = {'geometry': 'Polygon',
         'properties': {'NAME': 'str',
                'VALUE': 'float:15.2'}}

with fiona.open(
     '/tmp/foo.shp',
     'w',
     driver=driver,
     crs=crs,
     schema=schema) as c:
    c.write(rec1)
    c.write(rec2)

m = Basemap()
m.readshapefile('/tmp/foo','foo')
for info,region  in zip(m.foo_info, m.foo):
    print info
    print region

for which the output is:

{'RINGNUM': 1, 'NAME': 'outer', 'VALUE': 100.0, 'SHAPENUM': 1}
[(-50.0, 40.0), (50.0, 40.0), (50.0, -40.0), (-50.0, -40.0), (-50.0, 40.0)]
{'RINGNUM': 2, 'NAME': 'outer', 'VALUE': 100.0, 'SHAPENUM': 1}
[(-45.0, 35.0), (-45.0, -35.0), (45.0, -35.0), (45.0, 35.0), (-45.0, 35.0)]
{'RINGNUM': 1, 'NAME': 'inner', 'VALUE': 1.0, 'SHAPENUM': 2}
[(-45.0, 35.0), (45.0, 35.0), (45.0, -35.0), (-45.0, -35.0), (-45.0, 35.0)]
主要语言
Python
星标
817
派生
395
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

matplotlib/basemap 的其他 Issue

查看 matplotlib/basemap 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。