Seite 1 von 1

Projektion auf Globus

Verfasst: Donnerstag 1. Februar 2018, 11:54
von Samoth
Hallo,
Ich habe mir für ein geografisches Gebiet eine Karte erstellt.

nun möchte ich, dass ich für Darstellungszwecke das Viereck auf ein Globus ziehen.

Das klappt aber nicht ganz richtig. Gibt es da eine andere Möglichkeit?

Code: Alles auswählen

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import cartopy
import matplotlib.patches as mpatches

#Geostationär 
plt.figure(figsize=(4, 4))
ax = plt.axes(projection=ccrs.Geostationary())
ax.coastlines(resolution='110m')
ax.gridlines()
ax.stock_img()
ax.add_feature(cartopy.feature.BORDERS, linestyle='-', alpha=.5)

ax.add_patch(mpatches.Rectangle(xy=[-29, 1], width=58, height=38,
                                    facecolor='blue',
                                    alpha=0.2,
                                    transform=ccrs.PlateCarree()))

plt.show()

Re: Projektion auf Globus

Verfasst: Donnerstag 1. Februar 2018, 12:30
von noisefloor
Hallo,

"klappt nicht ganz richtig" heißt was genau? Absturtz des Programms? Die Projektion ist nicht wie erwartet? ...?

Gruß, noisefloor

Re: Projektion auf Globus

Verfasst: Donnerstag 1. Februar 2018, 13:32
von Samoth
Kann leider kein Bild hochladen...

Im Grunde passt die Projektion nicht. Auf dem Globus würde die Fläche wie eine Tonne aussehen.
(Wenn man den Code durchlaufen lässt sieht mans)

Theoretisch müssten allerdings die Kanten mit den Breiten und Längengradlinien verlaufen (d.h. eine Kurve beschreiben)
im Moment werden die Eckpunkte des Vierecks mit geraden Linien verbunden. Das ist natürlich falsch.

Re: Projektion auf Globus

Verfasst: Donnerstag 1. Februar 2018, 15:44
von Samoth
So ich habe das nun anderst gelöst.

Indem ich einfach einen Auschnitt aus einer globalen generiert habe.

Code: Alles auswählen

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import cartopy
import matplotlib.patches as mpatches

#Definition des Ausschnittes
llcrnrlon=-29.	#Lon. definition left border
llcrnrlat=1.	#Lat. bottom border
urcrnrlon=29.	#lon. right
urcrnrlat=39.	#Lat. top

box_size_lon=abs(llcrnrlon-urcrnrlon)
box_size_lat=abs(llcrnrlat-urcrnrlat)



#Plane Projektion der Erde
import shapely.geometry as sgeom

box = sgeom.box(minx=llcrnrlon, maxx=urcrnrlon, miny=llcrnrlat, maxy=urcrnrlat)
x0, y0, x1, y1 = box.bounds

proj = ccrs.PlateCarree(central_longitude=0)
box_proj = ccrs.PlateCarree(central_longitude=0)
ax1 = plt.subplot(211, projection=proj)
ax1.stock_img()
ax1.add_geometries([box], box_proj, facecolor='coral', 
                   edgecolor='black', alpha=0.5)
ax1.coastlines(resolution='50m')
ax1.gridlines()
plt.title('Global')

ax2 = plt.subplot(212, projection=proj)
ax2.stock_img()
ax2.set_extent([x0, x1, y0, y1], box_proj)
ax2.add_feature(cartopy.feature.BORDERS, linestyle='-', alpha=.5)
ax2.coastlines(resolution='50m')
ax2.gridlines(ccrs.PlateCarree(), \
                  xlocs=[-30,-20,-10, 0, 10, 20, 30],  \
                  ylocs=[0 , 10 ,20 ,30, 40 , 50], \
                  linestyle='--', 
                  alpha=1, linewidth=0.5, draw_labels=True)
plt.title('Zoomed in area')
plt.show()
Nun habe ich eine andere Frage, durch die x-Achsenbeschriftung wird der Titel überdeckt. Wie kann ich den Titel verschieben, oder die Achsenbeschriftung auf einer Seite entfernen?