This script allows to filter prediction geometry based on the assumption that they can only be, or can only be outside, of specific areas.
In both cases, these areas needs to be provided to the script along with the predictions.
Based on the prediction geometries and the definition of the areas, the script is used in the following way :
$ python3 filter-prediction.py --prediction [Prediction geometries]
--filter [Filtering areas geometries]
--mode [Filtering mode]
--export [Exportation mode]
--output [Exportation file for filtered geometries]
The mode parameter can be either inside or outside. In the first case, only the geometries of the prediction that are within the area are kept. In the second case, only the prediction outside the area are kept.
The export parameter can be either polygon or point. In the first case, the kept prediction, after filtering, are exported as polygons.
In case point is provided, the filtered predictions are transformed into points using their geometry centroid. The filtered prediction are then exported as point only, corresponding to their respective centroid.
As an example, the following predictions, in red, are filtered according to the building footprints, in black. As prediction should correspond to thermal panel, one assumes that prediction make sense only inside the geometry of the city buildings.
Thermal panels prediction (red) and building footprints (black) - STDL/SITG
If the mode is set to inside, the following outcome are obtained when setting export parameter to _polygon and to point :
Inside filtering exported as polygons (left) and points (right)
The points are rendered with their corresponding geometry on the images, but the script only exports point when export is set to point.
When the mode is set to outside, the following outcomes are obtained :
Inside filtering exported as polygons (left) and points (right)
Again, the point are shown along with their corresponding geometries.