Last active
February 12, 2023 09:09
-
-
Save mikkohei13/41d65583bd68027ce3b27003200b16b0 to your computer and use it in GitHub Desktop.
Generates small PNG maps of Finland with a dot at given coordinates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generates small maps of Finland with a dot at given coordinates. | |
import geopandas as gpd | |
import matplotlib.pyplot as plt | |
from pyproj import Proj, transform | |
# Load a GeoJSON file with outline of Finland into a GeoDataFrame | |
geojson = gpd.read_file('fin.geojson') | |
def make_map(gdf, lat, lon): | |
filename = f"./images/{ lat }_{ lon }.png" | |
print(filename) | |
# Convert the WGS84 coordinates to the CRS used by the GeoDataFrame | |
in_crs = Proj(init='epsg:4326') # WGS84 | |
out_crs = Proj(gdf.crs) | |
x, y = transform(in_crs, out_crs, lon, lat) | |
# Plot the GeoDataFrame using matplotlib | |
fig, ax = plt.subplots() | |
gdf.plot(ax=ax, edgecolor='black', linewidth=0.5, facecolor='none') | |
#ax.scatter(x, y, color='#006E8D', s=50) # Petrol blue | |
ax.scatter(x, y, color='#dd0000', s=30) # Red | |
ax.axis('off') | |
# Save the plot as a PNG image with a height of 200 pixels | |
fig.set_size_inches(fig.get_size_inches()[0], 200/fig.dpi) | |
fig.savefig(filename, dpi=fig.dpi, bbox_inches='tight', pad_inches=0, transparent=True) | |
# Interval of 0.1 | |
#latitude_values = [x/10 for x in range(600, 611)] | |
#longitude_values = [x/10 for x in range(240, 251)] | |
#interval of 1 | |
latitude_values = range(59, 71) | |
longitude_values = range(19, 33) | |
for latitude in latitude_values: | |
for longitude in longitude_values: | |
make_map(geojson, latitude, longitude) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use GeoJSON from https://gist.github.com/mikkohei13/6c5f5d1c356745f96177b0cdc73f3d4d