2

I have a plot that displays a raster file and shapefiles with the axes shown in lat/lon. Is there an option to change the axis to DMS instead?

coastline = gpd.read_file('.shp')
coords = gpd.read_file('.shp')
raster = rasterio.open('.tif')

fig, ax = plt.subplots(figsize=(15, 15))
rasterio.plot.show(raster, ax=ax)
coastline.plot(ax=ax, facecolor='none', edgecolor='black',legend=True)
coords.plot(ax=ax, facecolor='none',edgecolor='red',linewidth=1.3)
ax.set_ylim([lat1, lat2])
ax.set_xlim([lon1, lon2])

image_hidden = ax.imshow(raster.read()[0])
cbar=fig.colorbar(image_hidden, ax=ax)
2
  • Is your problem that lat/lon are in decimal degrees vs. DMS?
    – Llaves
    Nov 16, 2021 at 0:22
  • Yes, exactly. Apologies for the confusion. Nov 16, 2021 at 0:58

1 Answer 1

2

All you have to do is divide de decimal part of min part of the coord by 60 and the second by 3600. eg: 10°15'45.2"

d, m, s = coord_text.replace("°","'").replace("\"", "'").split("'")
d = float(d)
m = float(m)/60
s = float(s)/3600
coord = d + m + s

Do this for each axis and after that you have decimal values.

2
  • This plots on a decimal degrees axis. The OP asked how to plot in DMS.
    – Llaves
    Nov 26, 2021 at 4:04
  • to plot DMS they need to transform to decimal degree
    – marcosgeo
    Nov 27, 2021 at 2:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.