0

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:

  1. 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 }

  1. 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"

  2. 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

5
  • 1
    I suggest reading gdal.org/en/latest/programs/gdal_translate.html and gdal.org/en/latest/programs/gdalwarp.html first. Consider if projwin is good to your, or perhaps cutline. Practise with gdal_translate and/or gdalwarp. When you know what you want all the same is possible to do also with programming with Python or some other language.
    – user30184
    Commented Sep 3 at 13:17
  • Hi, thanks for the reply. i updated the question with the progres i have made
    – pcace
    Commented Sep 3 at 15:19
  • A few comments: 1) You have downloaded image from WMS with parameters &crs=EPSG:25833 and bbox=.... It would make much more sense to use those for georeferencing the image than EPSG:4326 bounding box. 2) As documented, srcwin is based on pixel/line location. You do not want to use that. You need to use -projwin and tell with -projwin_srs in which coordinate system the -projwin is. But with the values that you use you seem to select the whole image because they are the same than those that you used in &bbox= for fetching the image from WMS.
    – user30184
    Commented Sep 3 at 15:50
  • I know this is just an example, but in this case why not just request the image as a tiff in epsg:4326 using the BBOX you need. GetCapabilities response shows epsg:4326 and tiff are supported gdi.berlin.de/services/wms/…
    – nmtoken
    Commented Sep 5 at 9:04
  • 1
    Hi @nmtoken i know this explicit wms supports more, but i need a solution for not only this berlin wms.
    – pcace
    Commented Sep 5 at 9:05

0

Your Answer

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

Browse other questions tagged or ask your own question.