I am trying to use gdalwarp to project a polar stereographic image to a mercator projection epsg 28992 (for use in leaflet)
gdalinfo "HDF5:\"RAD_NL25_PCP_NA_202010271205.h5\"://image1/image_data"
Driver: HDF5Image/HDF5 Dataset
Files: RAD_NL25_PCP_NA_202010271205.h5
Size is 700, 765
Metadata:
geographic_geo_column_offset=0
geographic_geo_dim_pixel=KM,KM
geographic_geo_number_columns=700
geographic_geo_number_rows=765
geographic_geo_par_pixel=X,Y
geographic_geo_pixel_def=LU
geographic_geo_pixel_size_x=1.0000035
geographic_geo_pixel_size_y=-1.0000048
geographic_geo_product_corners=0 49.362064 0 55.973602 10.856453 55.388973 9.0093002 48.895302
geographic_geo_row_offset=3649.9819
geographic_map_projection_projection_indication=Y
geographic_map_projection_projection_name=STEREOGRAPHIC
geographic_map_projection_projection_proj4_params=+proj=stere +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378.14 +b=6356.75 +x_0=0 y_0=0
image1_calibration_calibration_flag=Y
image1_calibration_calibration_formulas=GEO = 0.500000 * PV + -32.000000
image1_calibration_calibration_missing_data=0
image1_calibration_calibration_out_of_image=255
image1_image_bytes_per_pixel=1
image1_image_geo_parameter=REFLECTIVITY_[DBZ]
image1_image_product_name=RAD_NL25_PCP_H1.5_NA
image1_image_size=535500
image1_statistics_stat_max_value=44.5
image1_statistics_stat_min_value=-31.5
overview_hdftag_version_number=3.6
overview_number_image_groups=1
overview_number_radar_groups=3
overview_number_satellite_groups=0
overview_number_station_groups=0
overview_products_missing=NA
overview_product_datetime_end=27-OCT-2020;12:05:00.000
overview_product_datetime_start=27-OCT-2020;12:05:00.000
overview_product_group_name=RAD_NL25_PCP_NA
radar1_radar_location=5.17834 52.101681
radar1_radar_name=DeBilt
radar1_radar_operational=0
radar2_radar_location=4.7999701 52.953339
radar2_radar_name=DenHelder
radar2_radar_operational=1
radar3_radar_location=5.1381001 51.836899
radar3_radar_name=Herwijnen
radar3_radar_operational=1
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 765.0)
Upper Right ( 700.0, 0.0)
Lower Right ( 700.0, 765.0)
Center ( 350.0, 382.5)
Band 1 Block=700x765 Type=Byte, ColorInterp=Undefined
Metadata:
image1_image_data_CLASS=IMAGE
image1_image_data_PALETTE=
image1_image_data_VERSION=1.2
gdalwarp -s_srs "+proj=stere +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378.14 +b=6356.75 +x_0=0 y_0=0" -t_srs "epsg:28992" "HDF5:\"RAD_NL25_PCP_NA_202010271205.h5\"://image1/image_data" output.tif
which results in this error message:
Processing HDF5:"RAD_NL25_PCP_NA_202010271205.h5"://image1/image_data [1/1] : 0ERROR 1: The transformation is already "north up" or a transformation between pixel/line and georeferenced coordinates cannot be computed for HDF5:"RAD_NL25_PCP_NA_202010271205.h5"://image1/image_data. There is no affine transformation and no GCPs. Specify transformation option SRC_METHOD=NO_GEOTRANSFORM to bypass this check.
What am i missing? If i set the flag SRC_METHOD=NO_GEOTRANSFORM i dont get the expected result
Georeference support for HDF5 data in GDAL is very limited (https://gdal.org/drivers/raster/hdf5.html). Therefore, your HDF5 file is not recognized by GDAL as georeferenced data.
My solution is to divide your command into two steps:
Georeferencing to stereographic projection using gdal_translate
Transformation to epsg:28992 using gdalwarp
First, the definition of SRS, the size of the Earth should be expressed in m as follows.
+proj=stere +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378140 +b=6356750 +x_0=0 +y_0=0
Next, assuming that the metadata geographic_geo_product_corners represents the latitude and longitude of the four corners of the image, we find the projected coordinates of the corners of the image.
LL (0, -4415002.84084825)
UL (0, -3649999.11191775)
UR (700002.437056242, -3649999.05174429)
LR (700002.440031711, -4415003.15918867)
I used gdaltransform to find this.
gdaltransform -s_srs "+proj=latlong" -t_srs "+proj=stere +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378140 +b=6356750 +x_0=0 y_0=0"
So, the conversion in your question can be done with the following command
gdal_translate -of VRT -a_srs "+proj=stere +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378140 +b=6356750 +x_0=0 +y_0=0" -a_ullr 0 -3649999.05174429 700002.440031711 -4415003.15918867 "HDF5:\"RAD_NL25_PCP_NA_202010271205.h5\"://image1/image_data" /vsistdout/ | gdalwarp -of GTiff -t_srs epsg:28992 /vsistdin/ output.tif
For information on how to combine two gdal command with a pipe, see the answer in How to convert projection of png tile from epsg:4326 to epsg:3857 by one command using gdal.
I use gdalwarp to get a planisphere with the EPSG 4326 projection (equidistant cylindrical projection). Before with GDAL 2 I had no problem to use gdalwarp with this command :
gdalwarp -te lonMin latMin lonMax latMax -t_srs EPSG:4326 sphere.tiff planisphere.tiff
Example
gdalwarp -te -100 -10 -60 10 -t_srs EPSG:4326 sphere.tiff planisphere.tiff
But now with GDAL 3.0.4 it returns an error like if I made a mistake in coordinates.
Creating output file that is 0P x 0L. ERROR 1: Attempt to create 0x0 dataset is illegal,sizes must be larger than zero.
Do we need to install something else now? (maybe because now GDAL seems to use PROJ6).
If someone have the solution or an idea, I will be glad to hear it. Thanks !
Alright gdalwarp works well, this problem is due to gdal_translate.
Since GDAL 3, if you extract an image from netCDF file, it doesn't georeference automatically your tiff image. This is why gdalwarp wouldn't work because it was impossible to crop my image.
So if you have a non-georeferenced image, you have to georeference your image with gdal_translate.
i've been trying to convert a geotiff image to .rst and again back to geotiff (i need both ways and figured i could check wether the Output is equal to the original).
Problem is: the output Image is shifted and i really have no clue what im doing wrong.
here is what i do:
gdal_translate -of rst -a_srs EPSG:32632 Input.tif Output.rst
gdal_translate -of gtiff -a_srs EPSG:32632 Output.rst Output.tif
now the Output.tif is shifted upward by the size of the Image. My assumption is that somehow coordinates are being mixed up and the top left corner of the Input Image is used as the bottom left corner for the Output.
Does somebody have a clue how to fix this?
Thank you in advance.
Try being explicit about what the output corner coordinates should be. To assign/override the georeferenced bounds of the output file add the -a_ullr option and provide corner coordinates in the form of ulx uly lrx lry. GDAL usually will generate these implicitly from the metadata of the input file, but I've noticed that prescribing them myself sometimes eliminates these issues.
For example:
gdal_translate -of gtiff -a_srs EPSG:32632 -a_ullr ulx uly lrx lry Output.rst Output.tif
i am using gdal 1.10 and 2.1.1.
i have a VRT datasource in WGS84 where i forced the corner coordinates to the min/max values of EPSG:3857 (-180,85.5,180,-85.5).
gdalinfo output for this VRT looks like this:
Size is 1296001, 601200
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (-180.000000000000000,85.500000000000000)
Pixel Size = (0.000277777563443,-0.000284431137725)
Corner Coordinates:
Upper Left (-180.0000000, 85.5000000) (180d 0' 0.00"W, 85d30' 0.00"N)
Lower Left (-180.0000000, -85.5000000) (180d 0' 0.00"W, 85d30' 0.00"S)
Upper Right ( 180.0000000, 85.5000000) (180d 0' 0.00"E, 85d30' 0.00"N)
Lower Right ( 180.0000000, -85.5000000) (180d 0' 0.00"E, 85d30' 0.00"S)
Center ( 0.0000000, -0.0000000) ( 0d 0' 0.01"E, 0d 0' 0.00"S)
Band 1 Block=128x128 Type=Int16, ColorInterp=Gray
Basically, i have the world minus the poles.
Now i want to convert this to EPSG:3857.
I use gdalwarp for this, using bilinear interpolation:
./gdalwarp -of VRT -co TILED=YES -srcnodata 9999 -t_srs 'EPSG:3785' -multi wgs84.vrt wmerc.vrt -overwrite -r bilinear
running gdalinfo on wmerc then gives this:
Size is 995026, 1025175
Coordinate System is:
PROJCS["Popular Visualisation CRS / Mercator (deprecated)",
GEOGCS["Popular Visualisation CRS",
DATUM["Popular_Visualisation_Datum",
SPHEROID["Popular Visualisation Sphere",6378137,0,
AUTHORITY["EPSG","7059"]],
TOWGS84[0,0,0,0,0,0,0],
AUTHORITY["EPSG","6055"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4055"]],
PROJECTION["Mercator_1SP"],
PARAMETER["central_meridian",0],
PARAMETER["scale_factor",1],
PARAMETER["false_easting",0],
PARAMETER["false_northing",0],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AXIS["X",EAST],
AXIS["Y",NORTH],
EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=#null +wktext +no_defs"],
AUTHORITY["EPSG","3785"]]
Origin = (-20037508.342789247632027,20644642.363762538880110)
Pixel Size = (40.275313937642778,-40.275354414328227)
Corner Coordinates:
Upper Left (-20037508.343,20644642.364) (180d 0' 0.00"E, 85d28'11.27"N)
Lower Left (-20037508.343,-20644644.098) (180d 0' 0.00"E, 85d28'11.28"S)
Upper Right (20037476.183,20644642.364) (179d59'58.96"E, 85d28'11.27"N)
Lower Right (20037476.183,-20644644.098) (179d59'58.96"E, 85d28'11.28"S)
Center ( -16.0797308, -0.8670919) ( 0d 0' 0.52"W, 0d 0' 0.03"S)
Band 1 Block=512x128 Type=Int16, ColorInterp=Gray
NoData Value=9999
Note that the corner coordinates for upper/lower left look correct, but the corner coordinates for upper/lower right (the longitude) is missing is missing 32 units.
Broadly put, i am missing a sliver on the right side, but only in regards to the coordinates. The data is there, but the coordinates to the right seem wrong.
Why is that?
i could just modify the coordinates to match the world (longitudinal) using gdal_translate but i fear i am overlooking something else here which might just come back to bite me.
EPSG 3857 bounds latitudes to be between -85 and 80 degrees. It does this for two reasons:
It allows the entire earth to be square and be indexed by a quadtree where every node is a square.
The Mercator projection blows up at the poles; considering that most people who use maps aren't interested in them anyways, the projection kills two birds with one stone and discards them.
I'm using gdal to create different kinds of layers, such as color reliefs and hillshades, and Mapnik to combine them into a single image to use as texture for the 3D dem model obtained from a single .hgt file.
Premising that I'm new to gdal, I'm facing some problem with the hillshade layer.By using the gdal command:gdal_translate N44E007.hgt N44E007.tif
I get the N44E007.tif file, which in IrfanView looks like this
With the following gdal command:gdaldem hillshade -of PNG .\tif\N44E007.tif .\hillshade_png\N44E007_hillshade.png
The N44E007_hillshade.png file I get is the following
How can I prevent gdal from creating these artifacts in the hillshade .png?
I'm using Windows 7 and cmd.
Update 1
This is the image I get by replacing gdal_translate N44E007.hgt N44E007.tif with gdalwarp -t_srs EPSG:32632 -r bilinear N44E006.hgt N44E006.tif
The problem is that the reprojected image is slightly rotated and stretched. How can I get a squared and straight image to use as texture for a 3d plane?
The reason for the artefacts in the first attempt is because the raster horizontal distance units are in degrees, and the vertical are in meters. You can use a scale option to normalise horizontal and vertical distance units, e.g. try:
gdaldem hillshade -s 111120 -compute_edges -of PNG N44E007.hgt N44E007_hs.png
The second attempt (Update 1) reprojects to WGS84 UTM zone 32, which is a transverse Mercator projection centred on a meridian at 9°E, which is close to the SRTM raster, which is centred on 7.5°E. Since the two meridians are not the same, it is expected the raster to be rotated. And it is stretched since the true distance of degrees are not equal in N-S and E-W directions, except at the equator.