stcorp / harp

Data harmonization toolset for scientific earth observation data
http://stcorp.github.io/harp/doc/html/index.html
BSD 3-Clause "New" or "Revised" License
55 stars 19 forks source link

Invalid polygon with area_intersects_area #232

Closed bilelomrani1 closed 4 years ago

bilelomrani1 commented 4 years ago

I want to exclude measurements using a mask file and the area_intersects_area command. I use the following command with Python:

output_product = harp.import_product(my_nc_file, operations="area_intersects_area(\"mask_file.csv\")")

Here is the first polygon in mask_file.csv:

``` 49.5519866943363,5.380458831787102,49.55342102050818,5.390920639038078,49.555179595947635,5.39573669433593,49.55555343627967,5.398660659790032,49.55463027954138,5.397914409637444,49.55381011962928,5.398349285125724,49.55346298217811,5.3979129791259695,49.55266952514686,5.398970603942863,49.551361083984744,5.398810386657707,49.55059051513708,5.399109363555901,49.550106048584354,5.3969388008117605,49.54840087890664,5.396836757659904,49.54530334472695,5.401679039001457,49.543865203857806,5.401594161987296,49.539875030517955,5.402735233306878,49.53750991821328,5.405549049377433,49.53541946411172,5.404733657836907,49.53404998779336,5.4002861976623455,49.532802581787514,5.399728775024406,49.532524108887124,5.4001264572143475,49.53107070922891,5.398934841155998,49.52823638916055,5.404012680053703,49.52617263793985,5.4052557945251385,49.52273559570354,5.400893688201896,49.52172851562541,5.398071289062492,49.52243041992227,5.395559310913078,49.520729064941825,5.395306110382072,49.51978683471721,5.393384933471672,49.520793914795334,5.389164447784416,49.52036285400432,5.3883795738220135 ```

I get the following exception:

CLibraryError: invalid polygon (line segments overlap) (line 2) (while reading area mask file 'mask_file.csv')

This surprises me because the list of coordinates was obtained using the .exterior method of shapely so it shouldn't overlap. Here is a visualisation of the geometry in a Jupyter notebook.

Capture d’écran 2020-08-27 à 21 14 51

The .is_valid method returns True and according to the shapely documentation:

A valid Polygon may not possess any overlapping exterior or interior rings.

Am I missing something?

svniemeijer commented 4 years ago

I think this issue is also resolved by the fix for #233 (also mind the comment on needing a header line in your file).

However, be aware that your mask may be way too detailed. Especially if you want to match it against satellite pixels, I would recommend to use a much lower resolution bounding polygon of the area that you want to match against; the more points you have in your area, the slower the area filter in HARP is going to be.

bilelomrani1 commented 4 years ago

You're right, I realized that this detailed mask is not interacting very well with harp so I ended up using the simplify method of geopandas. Thank you for your help