Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

readshapefile returns a multipolygon as several polygons

Aperta
#264 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

Inizia dal punto di ingresso Basemap.readshapefile e riproduci l’esempio Fiona fornito, confrontando i record restituiti con le geometrie sorgente. Il lavoro è completato quando il caso MultiPolygon conserva la geometria e i metadati di una feature sorgente senza compromettere il caso Polygon separato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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)]
Lingua principale
Python
Stelle
817
Fork
395
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di matplotlib/basemap

Tutte le issue di matplotlib/basemap

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.