使用gmplot和Python显示多个GeoJSON多边形

时间:2019-10-08 00:05:34

标签: python geojson

我是Python的新手,可以即时学习Python。我有一个包含多个多边形的geojson文件。我想使用gmplot将它们全部显示在Google Map上。但是,我只能显示一个多边形,而不能显示其他多边形。我不确定某个函数是否正确,但是我试图遍历并绘制每个多边形。任何指导将不胜感激!

我一直在网上研究其他技巧,但没有运气。

import json
import numpy as np
import gmplot
from itertools import groupby
import os

tstPolygon = "unit.geojson"

gmap = gmplot.GoogleMapPlotter(45.570312, -110.536931, 13)
gmap.apikey = "##############################"

def coords(newpoly):
    with open(newpoly) as f:
        js = json.load(f)
        for feature in js['features']:
            coordList = feature['geometry']['coordinates']
            name = feature['id']
            xy = coordList[0]
            xy_new = list(zip(*xy))
            x = xy_new[0]
            y = xy_new[1]
            gmap.plot(y,x,color='blue',edge_width=10)
            gmap.draw("mymap.html")

coords(tstPolygon)

我希望python脚本可以迭代并将每个多边形绘制到html文件中。我在考虑使用附加到每个多边形的唯一“ id”属性,并利用groupby()。但是不确定如何应用。

0 个答案:

没有答案
相关问题