Indra and Startical Echoes project needed a Brazilian map to show their test software working in Brazilian coast area.
Looking the tutorials and chating with copilot I made this small project. Maybe it could be good for someone else.
Creating polyline GMS file for Brazilian borders
Download and Install
https://github.com/GenericMappingTools/gmt/releases/latest
Download packages
DCM - https://github.com/GenericMappingTools/dcw-gmt/releases/latest
GSHHG - https://github.com/GenericMappingTools/gshhg-gmt/releases/latest
Brazilian Coast
gmt pscoast -R-74/-28/-34/6 -Df -A1000 -W -M > costa_raw.txt
Brazilian Border
gmt pscoast -R-74/-28/-34/6 -Df -N1 -M > fronteira_raw.txt
- ´-R´: Defines Brazil(R)
- ´-74/-28/-34/6´: Defines geographic region boundries = West(-74)/East(-28)/South(-34)/North(6)
- ´-Df´: Full resolution
- ´-A1000´: Ignore islands smaller than 1000 km²
- ´-W´: Draw coast lines
- ´-M´: Exports as polylines
Join data
Just copy the values and paste in a unique file.
Exemple: brasil_complete.map
Check the data
Run a python script with matplotlib.
import matplotlib.pyplot as plt
def gms_to_decimal(gms):
direction = gms[-1]
gms = gms[:-1]
if len(gms) == 6: # Latitude
degrees = int(gms[:2])
minutes = int(gms[2:4])
seconds = int(gms[4:6])
else: # Longitude
degrees = int(gms[:3])
minutes = int(gms[3:5])
seconds = int(gms[5:7])
decimal = degrees + minutes / 60 + seconds / 3600
if direction in ['S', 'W']:
decimal *= -1
return decimal
def ler_polilinhas(arquivo):
polilinhas = []
cor = (0, 0, 0) # Cor padrão
with open(arquivo, 'r') as f:
linhas = f.readlines()
i = 0
while i < len(linhas):
linha = linhas[i].strip()
if linha.startswith("ColorLinea"):
partes = linha.split()
cor = tuple(int(p)/255 for p in partes[1:4])
elif linha.startswith("Polilinea"):
qtd = int(linha.split()[-1])
coords = []
for j in range(i+1, i+1+qtd):
lat_gms, lon_gms = linhas[j].strip().split()
lat = gms_to_decimal(lat_gms)
lon = gms_to_decimal(lon_gms)
coords.append((lon, lat))
polilinhas.append((coords, cor))
i += qtd # pula as coordenadas lidas
i += 1
return polilinhas
print('Iniciando')
polilinhas = ler_polilinhas('brasil_complete.map')
plt.figure(figsize=(8, 6))
for coords, cor in polilinhas:
x, y = zip(*coords)
plt.plot(x, y, color=cor, linewidth=2)
plt.title("Costas e Fronteiras do Brasil")
plt.xlabel("Longitude")
plt.ylabel("Latitude")
plt.grid(True)
plt.axis("equal")
plt.show()
