TransWikia.com

Error using GDAL to clip raster to KML (CRS is same for both): Cutline not of polygon type

Geographic Information Systems Asked on March 6, 2021

I have a high-resolution, 4-band (RGBA) geo-tiff (22.26 Gb) with an image of an airport. I have a KML file that has a polygon for a runway. I used Google Earth to construct the KML. Both files use the same CRS and align properly in QGIS (i.e. the polygon perfectly outlines the runway when displayed together). I want to use GDAL (version 3.2.0) to clip the geo-tiff with the KML file, and I want the output to have a transparent background. But when I try I get an error:

ERROR 1: Cutline not of polygon type.

This post shows that errors can arise when the polygon and raster don’t have the same CRS, but my KML and raster use the same CRS.

From the output of ogrinfo for the KML, I noticed the line Geometry: Unknown (any), but I don’t know if that’s related to the error.

I tried converting the KML to an ESRI shapefile using ogr2ogr, but I get the same error.

GDAL command:

gdalwarp -of GTiff -cutline "RW1634.kml" -cl "RW1634.kml" -crop_to_cutline -dstalpha -dstnodata -999.0 rw1634.tif rw1634_clipped.tif

What could be causing this error and how do I fix it?

Below are the outputs of gdalinfo for the raster and ogrinfo for the KML:

RASTER (gdalinfo)

Driver: GTiff/GeoTIFF
Files: rw1634.tif
Size is 51083, 108944
Coordinate System is:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    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]],
    ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
Origin = (-90.475312585529650,31.184756697157653)
Pixel Size = (0.000000134865000,-0.000000115954000)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  ( -90.4753126,  31.1847567) ( 90d28'31.13"W, 31d11' 5.12"N)
Lower Left  ( -90.4753126,  31.1721242) ( 90d28'31.13"W, 31d10'19.65"N)
Upper Right ( -90.4684233,  31.1847567) ( 90d28' 6.32"W, 31d11' 5.12"N)
Lower Right ( -90.4684233,  31.1721242) ( 90d28' 6.32"W, 31d10'19.65"N)
Center      ( -90.4718679,  31.1784405) ( 90d28'18.72"W, 31d10'42.39"N)
Band 1 Block=51083x1 Type=Byte, ColorInterp=Red
  Mask Flags: PER_DATASET ALPHA 
Band 2 Block=51083x1 Type=Byte, ColorInterp=Green
  Mask Flags: PER_DATASET ALPHA 
Band 3 Block=51083x1 Type=Byte, ColorInterp=Blue
  Mask Flags: PER_DATASET ALPHA 
Band 4 Block=51083x1 Type=Byte, ColorInterp=Alpha

KML (ogrinfo -al)

INFO: Open of `RW1634.kml'
      using driver `LIBKML' successful.

Layer name: RW1634.kml
Geometry: Unknown (any)
Feature Count: 1
Extent: (-90.475312, 31.172124) - (-90.468423, 31.184757)
Layer SRS WKT:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    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]],
    ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
Name: String (0.0)
description: String (0.0)
timestamp: DateTime (0.0)
begin: DateTime (0.0)
end: DateTime (0.0)
altitudeMode: String (0.0)
tessellate: Integer (0.0)
extrude: Integer (0.0)
visibility: Integer (0.0)
drawOrder: Integer (0.0)
icon: String (0.0)
OGRFeature(RW1634.kml):1
  Name (String) = RW1634
  tessellate (Integer) = 1
  extrude (Integer) = 0
  visibility (Integer) = -1
  Style = @m_ylw-pushpin
  LINESTRING Z (-90.4753124912034 31.1846445852666 0,-90.4750229284792 31.1847566316438 0,-90.4749292579975 31.1845910350613 0,-90.4748288161075 31.1844036280404 0,-90.4747220906378 31.1842017736694 0,-90.474377266881 31.1835458629179 0,-90.4741249354232 31.1830610804011 0,-90.4734341410196 31.1817503059949 0,-90.4723932839778 31.1797706863484 0,-90.4716687193589 31.1783953646793 0,-90.4710184083647 31.177165151549 0,-90.4702268574338 31.1756583941818 0,-90.4698778621991 31.1749931231149 0,-90.4691750565429 31.1736696922447 0,-90.4687854807428 31.1729183421635 0,-90.4684231552055 31.1722403307614 0,-90.4687178791877 31.1721241739937 0,-90.4687308782668 31.1721487678317 0,-90.46895975626 31.1725817940356 0,-90.4691436041896 31.1729296206193 0,-90.4693965560035 31.1734138351111 0,-90.469811353387 31.1741933559874 0,-90.4702333646854 31.1750010829828 0,-90.4706513271147 31.1757963406044 0,-90.471554546709 31.1775061738734 0,-90.4720755486982 31.1784917566076 0,-90.4727430768749 31.1797585268031 0,-90.4733099660671 31.1808335216472 0,-90.4742753224242 31.1826732284418 0,-90.4746786439144 31.1834472945963 0,-90.4749918591061 31.184039731776 0,-90.4751268131754 31.184297946721 0,-90.4752248920029 31.1844834554095 0,-90.4752849205458 31.1845940361614 0,-90.4752864671578 31.1846010879602 0,-90.4752962104744 31.1846180162179 0,-90.4753007412126 31.1846250853319 0,-90.4753060875201 31.1846284456701 0,-90.4753124912034 31.1846445852666 0)

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP