2

I have some ship trajectories and I want to know which point of the trajectory is inside the port(=buffer) and which points are outside. The following picture shows my Geopandas Dataframe with the geometry.

The problem is that some points that are inside, are shown as outside. The problem can be easily seen if I use a huge buffer.

enter image description here

After that I am loading the port's point and buffing it, like below.

enter image description here

And then I am finding which points are inside and which outside, with the code below.

enter image description here

Now if I use a huge buffer, the are still rows in the points_outside_geometry dataframe. These rows shouldn't be tracked as outside points and this can be verified by the following plot.

enter image description here

enter image description here

How is that possible?

Code:

polys = gpd.GeoDataFrame.from_file('final_port.shp').buffer(100000)
sindex = gdf.sindex
points_within_geometry = pd.DataFrame()


for poly in port_poly:

    possible_matches_index = list(sindex.intersection(poly.bounds))
    possible_matches = gdf.iloc[possible_matches_index]
    precise_matches = possible_matches[possible_matches.intersects(poly)]
    points_within_geometry = points_within_geometry.append(precise_matches)

points_within_geometry = points_within_geometry.drop_duplicates(subset=['MMSI', 'TIMESTAMP'])
points_outside_geometry = gdf[~gdf.isin(points_within_geometry)].dropna(how='all')
3
  • @user2856 I updated the code. One question, the problem as stated in the referred question is on the alignment but in my question the intersection() parameter is a buffed point. Any ideas?
    – gete
    Commented Feb 19, 2020 at 3:54
  • Where do you define gdf? There is one buffer in the image. Does port_poly contain one port (one record)? Commented Feb 19, 2020 at 8:33
  • If points_within_geometry has duplicate records, and If you try to get points outside after dropping duplicates, that means points_outside_geometry includes duplicate ones already dropped . Commented Feb 19, 2020 at 9:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.