Match by location


Well, I’m trying to organize some geometry by location ( in ArcGIS, this would be a Spatial Join ).

I made this definition, that works with some polygons: by the center point, I can find wich building is inside the plot (both closed polylines) and organize them by tree/branches: One branch for each plot and same branch path for various buildings. Example:

Tree Plots (red): Branch {233} with one single polyline in plot geometry
Tree Buildings (green): Branch {233} with two buildings - two polylines - that has its center inside the plot 233.

If you need to do the same with few polygons, my definition works:

spatial join (few polygons).gh (106.5 KB)

But the main component that does it, the Point In Curve, it is not efficient if you have thousands plots and hundred of thousands buildings, because it compares every point to every plot. I wish to have a component that tests only the points that are close to the polyline, so the processing time is optmized.

Is there any efficient way to do that?

Thank you in advance,


This should work faster. Plots with a high area value are kind of a problem since the closest points to the center are most likely not inside the curve, so I filtered by area and divided the plot curves that have a larger area than 3000. You have to play with the slider values if you use it for a different scenario.
Hope it helps.

spatial join (few polygons) (211.3 KB)

Maybe this can make it faster. I have grouped all plots in groups of 3 by proximity.
Then PointInCurves only searches through these 3 curves…

spatial join (few polygons) (211.0 KB)

Thank you, guys, for the quick response! If you want to see the full city file, here it is:
(be prepared for a 10 mb grasshopper file)

whole (10.6 MB)

Jakinta, your definition don’t give to us the plots and buildings in the same branch. As you can see in the image below, the path 64, for example, gives us buildings that are not inside the weird plot form. But the search distance is a good idea, i’ll try to work on that.

Daniel, I’m trying to work with your definition for the whole city. If it does works, I’ll post the result here.

Thanks again,


Uhm, that’s such a large data set every try takes minutes to calculate :frowning: and I think it doesn’t matter if it takes 10 or 20 minutes, since it’s a script you run only once and internalize the result after.

But what I noticed is that there are a lot of invalid curves in both data sets and the branching of the plots doesn’t make any sense atleast for branch {0}, didn’t really check the others, {1} on the other hand made sense.

I see, Daniel. The curves come from a shapefile (.shp), using the ghshp component. But it does not cause problems, the invalid curves still forms surfaces, probably Rhino corrects it.

And about the branches: the branch 0 is for plots that has no block for it. Then, the branch 1 and so on are correct.

But Daniel, running your definition, I couldn’t get it right. Probably because the number sliders. I’m not sure what configuration it should have. My definition is running for hours and no results until now :pensive: (running in an intel i5 2º gen). Can you try and see if your definition works for the whole city?

Ah okay, thanks for the clarification :slight_smile:

I don’t think my script will work well on that file, I didn’t even try and went another way:

  1. made surfaces out of every plot curve thats longer than ~220m, since area calculates too long
  2. populated the surfaces (made more sense to me than than dividing the curve)
  3. merged populated points and center points again
  4. used closest point like in my previuos definition

But I killed it after ~10 minutes since I don’t have a free pc to let it run god knows how long atm, maybe I have time tomorrow.

Thanks, Daniel! I’ll try it soon.

CORRECTION: My definition did not work. Just some buildings came up in the result. Still trying to figure out the best solution.

Hey @kevin.carvalho, said to here that! I can’t contribute a file yet, sorry.

To solve this kind of problem you have to use some sort of spatial search algorithm.
In attached C# component RTree is used with its capability of spatial searching. Execution time is around 1 sec for given set of curves, few more seconds is for manipulating data - “moving” it from one component to another.

whole (10.5 MB)


Radovan, it works perfectly, and it’s faster than softwares made for this, as ArcMap.

I wish I could code like this… In your code, I just understand that there is some for loops. The rest is incredible. rs

Thank you a lot!