I wanted to clip an OSM vector layer with the boundaries of a raster image--a GeoTIFF file. I was able to polygonize the raster and obtain its boundary in a vector format. But I am getting a error about the vector layer having invalid geometry when I try to clip the OSM layer with the polygonize vector layer. So let me walk you through what I did.
I took a GeoTIFF image and polygonized it using this code from a previous post.
gdal_translate -b mask -of vrt -a_nodata 0 test.tif test.vrt # Note the -a_nodata 0 doesn't seem to work when the mask is input, so do another pass gdal_translate -b 1 -of vrt -a_nodata 0 test.vrt test2.vrt gdal_polygonize.py -q -8 test2.vrt -b 1 -f "ESRI Shapefile" testdata.shp
I get the corresponding image when I import the data to QGIS
However, when I go to clip the OSM layer with the new boundary layer, I get this error about an invalid geometry.
I tried to fix this inside of QGIS, but not sure how to proceed. I tried to use the "Validate Geometry" tool, but that did not fix the invalid geometry issue. Any suggestions about how to either correct the original GDAL code to make valid geometries, or how to fix the subsequently generated polygons?