I have a geo-referenced tiff file and a point shapefile. I want to ignore all the points in the shapefile which are outside raster's boundary.
Based in your more recent commentary, I think that is preferable to produce a new point vector layer, with points overlay raster, for preserving original point layer. Next PyQGIS code produces it as memory layer in QGIS. You only have to change my name layers for yours.
registry = QgsMapLayerRegistry.instance() raster = registry.mapLayersByName('noise_linear_raster') vector = registry.mapLayersByName('random_points3') extent_polygon = raster.extent().asWktPolygon() geom_extent = QgsGeometry.fromWkt(extent_polygon) feat_vector = [ feat for feat in vector.getFeatures() ] new_feat_vector = [ feat for feat in feat_vector if feat.geometry().within(geom_extent) ] epsg = vector.crs().postgisSrid() uri = "Point?crs=epsg:" + str(epsg) + "&field=id:integer""&index=yes" mem_layer = QgsVectorLayer(uri, 'no_ignored_points', 'memory') prov = mem_layer.dataProvider() for i, feat in enumerate(new_feat_vector): feat.setAttributes([i]) prov.addFeatures(new_feat_vector) QgsMapLayerRegistry.instance().addMapLayer(mem_layer)
I tried out above code in Python Console of QGIS and I got:
Red points are corresponding to memory layer and all of them are within raster layer.