You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Figure.psconvert: Add support for GeoTIFF output #2658
In classic GMT, I have long used this command to generate a GeoTIFF file from an EPS file:
gmt psconvert -A -P -Tt -W+g $out
I see there is a pygmt.Figure.psconvert call that wraps the GMT psconvert but it does not seem to have the -W+g option to make a GeoTIFF.
The GeoTIFF output is extremely helpful for taking a GMT or PyGMT map and loading it into Google Earth or QGIS to view it with other geographic information. I attach an example of a map that I made in GMT that I converted to GeoTIFF and then opened as an image overlay in Google Earth.
Are you willing to help implement and maintain this feature?
I have only used the -W+g modifier for my purposes. The GeoTIFF is good for loading in QGIS, ArcGIS, and other GIS systems in addition to Google Earth or Google Maps. I have not used the KML file generation, but I imagine that others use that, so it would be good to support as well.
I've done a few tests to understand GMT's behavior about GeoTIFF support.
The test PS file is generated using the following command:
gmt coast -R0/10/0/10 -JM10c -Baf -W1p -ps map
I've tried the following commands:
gmt psconvert map.ps -Tt produces map.tif (a normal TIFF file)
gmt psconvert map.ps -W produces map.jpw (the plaintext world file) and map.jpg (default image format)
gmt psconvert map.ps -W+g produces map.pgw (the plaintext world file) and map.tiff (GeoTIFF)
gmt psconvert map.ps -W+g -Tt produces map.tfw (the plaintext world file) , map.tif (normal TIFF) and map.tiff (GeoTIFF).
Usually, both .tif and .tiff are valid extensions for a TIFF file. You can't tell if a TIFF file is GeoTIFF or not from the file extension. But for files produced by GMT, .tif is a normal TIFF file, and .tiff is a GeoTIFF file.
I'm wondering if we should follow the same convention as GMT? If yes, then we can provide a Pythonic user interface for PyGMT users:
Figure.savefig("map.tif") produces a normal TIFF file
Figure.savefig("map.tiff") produces a GeoTIFF file
As PyGMT maintainers, we just need to check the file extension. If it's tiff/TIFF, then we add the -W+g option automatically.
If we decide not to follow the GMT convention, then we may want to add a new parameter (e.g., geotiff or georeference) to Figure.savefig. If it's True, then we add the -W+g option, but users may be surprised that Figure.savefig("map.tif", georeference=True) produces two TIFF files (map.tif and map.tiff). To avoid producing two TIFF files, we need to modify the logic of the codes (i.e., don't add -Tt if georeference=True), but it still produces map.tiff, rather than map.tif provided by users. Then we may need to rename map.tiff to map.tif to make users happy.
What do you think? @EJFielding @GenericMappingTools/pygmt-maintainers
I'm wondering if we should follow the same convention as GMT? If yes, then we can provide a Pythonic user interface for PyGMT users:
* `Figure.savefig("map.tif")` produces a normal TIFF file
* `Figure.savefig("map.tiff")` produces a GeoTIFF file
As PyGMT maintainers, we just need to check the file extension. If it's tiff/TIFF, then we add the -W+g option automatically.
Should be easier to follow the GMT convention to avoid adding another parameter that can get confusing. Technically, a normal TIFF file would become a 'GeoTIFF' if there is a corresponding tfw file, whereas a GeoTIFF has the geo metadata baked into the TIFF file directly. As long as we properly document that of tif=TIFF and tiff=GeoTIFF, it should be fine, and users can always rename .tiff to .tif if needed. Personally, I don't expect many users saving their figures as GeoTIFF files (though it is a cool feature to have)!
Oh, and just to be clear, modifying savefig is more of an additional enhancement, we should make the change in psconvert first.
Hi, I have been traveling for the last week. I am not sure which implementation is best. I think the details are not so important and you can choose what you think works best with the rest of PyGMT.
If I understand this feature request, it sounds like we just need to alias -W to altmode (or some other name) here?
-W is a very complicated option. Its +g and +c modifiers are used to generate GeoTIFF file, while all other modifiers are related to KML format. So, aliasing -W to any names likely makes little sense. We probably need two parameters, one controls geotiff and another one controls KML. So it needs more discussions.
modifying savefig is more of an additional enhancement, we should make the change in psconvert first.
See PR #2698. We don't need to modify psconvert to support GeoTIFF.
@EJFielding I've implemented the GeoTIFF support in PR #2698. It would be great if you can give it a try. It's not finished yet. I still need to add some tests to check if the generated file is georeferenced or not.
@EJFielding I've implemented the GeoTIFF support in PR #2698. It would be great if you can give it a try. It's not finished yet. I still need to add some tests to check if the generated file is georeferenced or not.
Sorry, PR #2698 doesn't work yet. Need more time to find out why.
changed the title [-]Add support for GeoTIFF output to Figure.psconvert[/-][+]Figure.psconvert: Add support for GeoTIFF output to Figure.psconvert[/+]on Oct 9, 2023
changed the title [-]Figure.psconvert: Add support for GeoTIFF output to Figure.psconvert[/-][+]Figure.psconvert: Add support for GeoTIFF output[/+]on Oct 9, 2023
Activity
seisman commentedon Sep 7, 2023
@EJFielding
This feature seems easy to implement in PyGMT.
After reading the documentation, my impressions are:
Do I understand it correctly?
EJFielding commentedon Sep 8, 2023
I have only used the
-W+gmodifier for my purposes. The GeoTIFF is good for loading in QGIS, ArcGIS, and other GIS systems in addition to Google Earth or Google Maps. I have not used the KML file generation, but I imagine that others use that, so it would be good to support as well.seisman commentedon Sep 9, 2023
I've done a few tests to understand GMT's behavior about GeoTIFF support.
The test PS file is generated using the following command:
I've tried the following commands:
gmt psconvert map.ps -Ttproducesmap.tif(a normal TIFF file)gmt psconvert map.ps -Wproducesmap.jpw(the plaintext world file) andmap.jpg(default image format)gmt psconvert map.ps -W+gproducesmap.pgw(the plaintext world file) andmap.tiff(GeoTIFF)gmt psconvert map.ps -W+g -Ttproducesmap.tfw(the plaintext world file) ,map.tif(normal TIFF) andmap.tiff(GeoTIFF).Usually, both
.tifand.tiffare valid extensions for a TIFF file. You can't tell if a TIFF file is GeoTIFF or not from the file extension. But for files produced by GMT,.tifis a normal TIFF file, and.tiffis a GeoTIFF file.I'm wondering if we should follow the same convention as GMT? If yes, then we can provide a Pythonic user interface for PyGMT users:
Figure.savefig("map.tif")produces a normal TIFF fileFigure.savefig("map.tiff")produces a GeoTIFF fileAs PyGMT maintainers, we just need to check the file extension. If it's
tiff/TIFF, then we add the-W+goption automatically.If we decide not to follow the GMT convention, then we may want to add a new parameter (e.g.,
geotifforgeoreference) toFigure.savefig. If it's True, then we add the-W+goption, but users may be surprised thatFigure.savefig("map.tif", georeference=True)produces two TIFF files (map.tifandmap.tiff). To avoid producing two TIFF files, we need to modify the logic of the codes (i.e., don't add-Ttifgeoreference=True), but it still producesmap.tiff, rather thanmap.tifprovided by users. Then we may need to renamemap.tifftomap.tifto make users happy.What do you think? @EJFielding @GenericMappingTools/pygmt-maintainers
weiji14 commentedon Sep 14, 2023
If I understand this feature request, it sounds like we just need to alias
-Wtoaltmode(or some other name) here?pygmt/pygmt/figure.py
Lines 129 to 143 in e4bd4fb
Should be easier to follow the GMT convention to avoid adding another parameter that can get confusing. Technically, a normal TIFF file would become a 'GeoTIFF' if there is a corresponding tfw file, whereas a GeoTIFF has the geo metadata baked into the TIFF file directly. As long as we properly document that of tif=TIFF and tiff=GeoTIFF, it should be fine, and users can always rename
.tiffto.tifif needed. Personally, I don't expect many users saving their figures as GeoTIFF files (though it is a cool feature to have)!Oh, and just to be clear, modifying
savefigis more of an additional enhancement, we should make the change inpsconvertfirst.EJFielding commentedon Sep 17, 2023
Hi, I have been traveling for the last week. I am not sure which implementation is best. I think the details are not so important and you can choose what you think works best with the rest of PyGMT.
I am happy to test a developer version.
seisman commentedon Sep 22, 2023
-Wis a very complicated option. Its +g and +c modifiers are used to generate GeoTIFF file, while all other modifiers are related to KML format. So, aliasing-Wto any names likely makes little sense. We probably need two parameters, one controls geotiff and another one controls KML. So it needs more discussions.See PR #2698. We don't need to modify
psconvertto support GeoTIFF.@EJFielding I've implemented the GeoTIFF support in PR #2698. It would be great if you can give it a try. It's not finished yet. I still need to add some tests to check if the generated file is georeferenced or not.
seisman commentedon Sep 22, 2023
Sorry, PR #2698 doesn't work yet. Need more time to find out why.Edit: Now PR #2698 should work.
[-]Add support for GeoTIFF output to Figure.psconvert[/-][+]Figure.psconvert: Add support for GeoTIFF output to Figure.psconvert[/+][-]Figure.psconvert: Add support for GeoTIFF output to Figure.psconvert[/-][+]Figure.psconvert: Add support for GeoTIFF output[/+]