I have an png image where I know the bounds and its CRS. I have a bbox in a different CRS which I want to use to cut a part from the original image.
How can I do that?
Ultimately I need to do that in a node environment. For that I think I am going to use gdal-async - or is there a better way?
I got a tiny bit further trying it manually:
- I download this image: https://gdi.berlin.de/services/wms/truedop_2023?SERVICE=WMS&request=GetMap&version=1.3.0&layers=truedop_2023&styles=truedop_2023&crs=EPSG%3A25833&width=512&height=512&format=image%2Fpng&bbox=392680.95083132095%2C5816991.938620153%2C393134.43388141005%2C5817424.944091731&transparent=TRUE it has these outlines:
{ "type": "Feature", "properties": {}, "geometry": { "type": "Polygon", "coordinates": [ [ [ 13.425815172448008, 52.49249712044625 ], [ 13.42581523957934, 52.49647748166542 ], [ 13.419277533858136, 52.49647748166542 ], [ 13.419277600989467, 52.49249712044625 ], [ 13.425815172448008, 52.49249712044625 ] ] ] }, "id": 0 }
as far as I understand I have to add the georeference to the image like this:
gdal_translate -of GTiff -a_ullr 13.419277600989467 52.49249712044625 13.42581523957934 52.49647748166542 -a_srs EPSG:4326 "truedop_2023-truedop_2023.png" "georef_truedop_2023.tiff"
now I would like to cut a piece out of this image like so:
gdal_translate -srcwin 392680.95083132095 5816991.938620153 393134.43388141005 5817424.944091731 -projwin_srs EPSG:25833 georef_truedop_2023.tiff georef_truedop_2023_split.tiff
but I get this error:
Warning 1: -srcwin 392717 5.81703e+06 393098 5.81739e+06 falls completely outside raster extent. Going on however.
ERROR 3: georef_truedop_2023_split.tiff: Free disk space available is 234466742272 bytes, whereas 9147242338836 are at least necessary. You can disable this check by defining the CHECK_DISK_FREE_SPACE configuration option to FALSE.
which is weird, because when I translate the outlines to 4326, they are well within the outer outline of the first image. what is wrong here?
Gdalinfo shows the correct bounds for the tiff:
gdalinfo georef_truedop_2023.tiff
Driver: GTiff/GeoTIFF
Files: georef_truedop_2023.tiff
Size is 512, 512
Coordinate System is:
GEOGCRS["WGS 84",
ENSEMBLE["World Geodetic System 1984 ensemble",
MEMBER["World Geodetic System 1984 (Transit)"],
MEMBER["World Geodetic System 1984 (G730)"],
MEMBER["World Geodetic System 1984 (G873)"],
MEMBER["World Geodetic System 1984 (G1150)"],
MEMBER["World Geodetic System 1984 (G1674)"],
MEMBER["World Geodetic System 1984 (G1762)"],
MEMBER["World Geodetic System 1984 (G2139)"],
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]],
ENSEMBLEACCURACY[2.0]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["geodetic latitude (Lat)",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["geodetic longitude (Lon)",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
USAGE[
SCOPE["Horizontal component of 3D system."],
AREA["World."],
BBOX[-90,-180,90,180]],
ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
Origin = (13.419277533858136,52.496477481665423)
Pixel Size = (0.000012768825371,-0.000007774143006)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 13.4192775, 52.4964775) ( 13d25' 9.40"E, 52d29'47.32"N)
Lower Left ( 13.4192775, 52.4924971) ( 13d25' 9.40"E, 52d29'32.99"N)
Upper Right ( 13.4258152, 52.4964775) ( 13d25'32.93"E, 52d29'47.32"N)
Lower Right ( 13.4258152, 52.4924971) ( 13d25'32.93"E, 52d29'32.99"N)
Center ( 13.4225464, 52.4944873) ( 13d25'21.17"E, 52d29'40.15"N)
Band 1 Block=512x4 Type=Byte, ColorInterp=Red
Mask Flags: PER_DATASET ALPHA
Band 2 Block=512x4 Type=Byte, ColorInterp=Green
Mask Flags: PER_DATASET ALPHA
Band 3 Block=512x4 Type=Byte, ColorInterp=Blue
Mask Flags: PER_DATASET ALPHA
Band 4 Block=512x4 Type=Byte, ColorInterp=Alpha