Find which polygon in a geospatial shapefile contains a spatial geopoint.

Hi,

I have a shapefile that contains a number of polygons, and I have a CSV file with a list of point coordinates. There are nodes that can read the shapefile and points, but how do I find the matching polygon and then add the columns to the point row.

Sample Data

Using the KNIME Spatial Processing “Read from Shapefile” the output table looks like this…

and the points file after the coordinates were converted to 2D Points.

I need to find which polygon contains each point and then add the polygon properties to the point coordinate row.

This should have a really simple solution.

If anyone has solved something like this or has some ideas, I would really appreciate your comments.

Thanks.

tC/.

Hi @TigerCole

It depends on the shape of your polygons. If they are convex, the solution is simpler, otherwise it is not. Are your polygons by any chance convex ?

Best

Ael

Hi @aworker,

I wish they were, but unfortunately, they are exactly the opposite. They are regional boundaries so there is nothing neat about them.

tC/.

Hi @TigerCole

Did you find a solution for your polygon problem ?

  • If yes, which one ?
  • If not, just a further question to think about a plausible solution: Are the shape of your polygons exactly delineating the perimeter of well defined areas (closed, no edge crossing, etc.) or can they be more complex polygons such coming for instance from the walking of a person (with crossing edges, etc.) ?

Thanks & regards,

Ael

Hi @aworker,

I have used QGIS to get the output I need but it is not the solution I want. Using a GIS tool adds another step to an already very inefficient process, so yes I have solved the problem for this week, but no I don’t have a long term solution. I want to do this in KNIME.

The polygons are very neat. They were created by generating Uber H3 Hexagons and then dissolving them to create polygons that represent management areas. All the polygons are closed, there are no overlaps or crossings.

I am working on a long-winded and messy flow to load each polygon from the shapefile and then check for a relationship with each row of the points table, filter out the “false” returns and then process further. It is not very elegant, a big hammer hitting a tiny nail but it will probably work. And, it will be very slow, The points table has nearly a million rows and is growing weekly, which will need to be tested against 130 polygons from an initial shapefile and 22560 in another so it is a lot of looping.

I have found some java and python libraries that might do the work, I just need to get some time from one of my developers to help.

tC/.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.