I want to verify that a GeoDataFrame called mask2 COMPLETELY CONTAINS all the linestrings in another GeoDataFrame called transect_file2.

In the image is clearly visible that transect number 16 (TR_ID=16) is partially outside the mask2 polygon, while transect number 2 is within.

Mask2 polygon and transect_file2 transects file

Here is my code for reading the geopackages and changing the geometry name:

mask = gpd.read_file(r"C:\jupyter\masks\mask_apollo20180601.gpkg")
transect_file = gpd.read_file(r"C:\jupyter\transects_gpkg\apollo_transects_errortest.gpkg")

mask2 = mask.rename(columns={'geometry': 'geom'}).set_geometry('geom')
transect_file2 = transect_file.rename(columns={'geometry': 'geom'}).set_geometry('geom')

Then, I slice the transect GeoDataFrame into one line where tr_id = 16 and run the within method on the mask polygon to evaluate if the transect geometry is completly within the mask geometry, and it returns False, as expected.

a=transect_file2[transect_file2['TR_ID'] == 16]

output of tr_id 16 within mask

If I change the transect ID with 2, which I know is completely within the mask, I expect the method .within to return True instead of False. But this does not happen.

Any clue on what I am missing?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.