填充以圆锥为界的多边形

时间:2019-05-21 15:03:20

标签: python matplotlib imagemagick

我正在寻找使用matplotlib和gdal填充使用python生成的图像的不同锥部。每次半径扫描都以不同的颜色勾勒出轮廓。有没有办法填补每个部门?我将通过imagemagick命令行附加我想拥有的东西以及我想要的东西,或者类似的东西来填充这些区域。

我用ImageMagick尝试了不同的-draw命令,但似乎基于像素位置。该图像中圆锥形扇形的位置将定期更改。

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt 
import math
from osgeo import ogr, osr
import matplotlib.cm as cmx
import matplotlib.colors as colors

# Reverse Haversine functions
def createCircleAroundWithRadius(lat, lon, radiusMiles):
    ring = ogr.Geometry(ogr.wkbLinearRing)
    latArray = []
    lonArray = []
    lonpoint1 = []
    lonpoint2 = []
    latpoint1 = []
    latpoint2 = []

    for brng in range(0, 90):
        lat2, lon2 = getLocation(lat, lon, brng, radiusMiles)
        latArray.append(lat2)
        lonArray.append(lon2)
        if (radiusMiles == windDistance[2] and brng == 0):
            lonpoint1, latpoint1 = lonArray[0], latArray[0]
        if (radiusMiles == windDistance[2] and brng == 89):
            lonpoint2, latpoint2 = lonArray[89], latArray[89]
    return lonArray, latArray, lonpoint1, latpoint1, lonpoint2, latpoint2

def getLocation(lat1, lon1, brng, distanceMiles):
    lat1 = lat1 * math.pi / 180.0
    lon1 = lon1 * math.pi / 180.0
    R = 3959 # earth radius in miles
    distanceMiles = distanceMiles / R
    # = (brng / 90) * math.pi / 2
    brng = brng * math.pi / 180.0`


   lat2 = math.asin(math.sin(lat1) * math.cos(distanceMiles) + math.cos(lat1) * math.sin(distanceMiles) * math.cos(brng))
   lon2 = lon1 + math.atan2(math.sin(brng) * math.sin(distanceMiles) * math.cos(lat1), math.cos(distanceMiles) - math.sin(lat2) * math.sin(lat2))
   lon2 = 180.0 * lon2 / math.pi
   lat2 = 180.0 * lat2 / math.pi

   return lat2 , lon2

# Coordinates
westbounds = -85
eastbounds = -65
northbounds = 45
southbounds = 30`
#fig = plt.figure(1)

mp = Basemap(projection = 'merc', resolution = 'h', area_thresh = 0.1,       llcrnrlon = westbounds, llcrnrlat = southbounds, urcrnrlon = eastbounds, urcrnrlat = northbounds)
mp.drawstates()
mp.drawcountries()
mp.drawcoastlines()

# Storm Coordinates
stormCenterLat = 35
stormCenterLon = -75

# Draw quadrant arcs based on distance in miles. This example will do the NE quadrant.
windDistance = [35, 75, 240]
colors = ['r', 'y', 'g']
for i,b in zip(windDistance, colors):
    distanceMiles = i
    X,Y,Lon1,Lat1,Lon2,Lat2 =     createCircleAroundWithRadius(stormCenterLat, stormCenterLon, distanceMiles)
    X,Y = mp(X,Y)
    plt.fill(X,Y, color = b)
    mp.plot(X,Y,marker = None, color = b, linewidth = 3)

xs1 = []
ys1 = []

xs2 = []
ys2 = []

# Vertical line drawn.
xpt1, ypt1 = mp(stormCenterLon, stormCenterLat)
xs1.append(xpt1)
ys1.append(ypt1)

xpt1, ypt1 = mp(Lon1, Lat1)
xs1.append(xpt1)
ys1.append(ypt1)
mp.plot(xs1,ys1, color = 'black', linewidth = 1)

#Horizontal line drawn.
xpt2, ypt2 = mp(stormCenterLon, stormCenterLat)
xs2.append(xpt2)
ys2.append(ypt2)

xpt2, ypt2 = mp(Lon2, Lat2)
xs2.append(xpt2)
ys2.append(ypt2)
mp.plot(xs2,ys2, color = 'black', linewidth = 1)

# Draw storm location point
x,y = mp(stormCenterLon, stormCenterLat)
mp.plot(x,y,marker = 'D', color = 'b', markersize = 2)
plt.show()

https://i.imgur.com/vCYIXGH.png https://i.imgur.com/rwJTDP3.png

0 个答案:

没有答案