Rob174 / detection_nappe_hydrocarbures_IMT_cefrem

0 stars 0 forks source link

Get the annotations from the polygons #5

Closed Rob174 closed 3 years ago

Rob174 commented 3 years ago

In order to extract the polygons from the shapefiles .shp, we will use the package pyshp denoted as shapefile in python imports. The QGIS python package does not work (on my computer) on Windows.

The Readerobject allows to open the shapefile and returns an object. Then we can access to its metadata thanks to the property record of this object.

We can extract the points of each polygon shape by looping over the values of the object and getting the shape.pointattribute. It allows us to get the list of the points of the polygon. The points seems to be using the geographical coordinates rather than pixel coordinates.

Example of coordinate : (25.078123755232415, 38.92436547557481)

Rob174 commented 3 years ago

Thanks to the rasterio module and the data stored in the .img file, we can use the index function of the object image to get the corresponding location of some coordinates on the raster as shown here

Rob174 commented 3 years ago

I have tested the following code

raster_object # object img opened with rasterio
raster_object.index(raster_object.bounds.right,raster_object.bounds.bottom) # returns the same value as img_array.shape
raster_object.index(raster_object.bounds.left,raster_object.bounds.top) # returns (0,0)

So the index method does output the pixel coordinates in the original system of coordinates provided with first the horizontal coordinate and then the vertical coordinate.

The problem comes from the value read from the shp file

Rob174 commented 3 years ago

Problem with the coordinates given by the shapefile library : on geogebra we can use put the limits of the window and then the points given by shapefile. We observe that the points are far out of the window:

Capture d’écran (193) Capture d’écran (196)

--> maybe the reference image with the superposition of the polygons can give hints of the global location of the polygons...

Rob174 commented 3 years ago

Maybe it is a package issue. Same problem with fiona.

Rob174 commented 3 years ago

It must be a package issue : we have the following figure for the S1A_IW_GRDH_1SDV_20190601T042305_20190601T042330_027481_0319CB_0EB7 image on QGIS :

Asset 1@2x
Rob174 commented 3 years ago

Ok solved in 241cb41704efd3f20ac97e9f68c5680b3789f08a with debugging searches allowed to find the correct property to get and manage side cases

Rob174 commented 3 years ago

For the moment Pillow is used to draw the shape. It will maybe a better idea to use an other package that can work directly on numpy arrays

Rob174 commented 3 years ago

Result

20190601_S1A_annotated 20190601_S1B_annotated 20190618_annotated