I have two shapefiles. The first contains a lot of squares. For each square I have the type of forest cover (Coniferous, leafy or mixed).

The second shapefile contains different polygons with different size and shape. In the second shapefile I have the type or forest cover also and I have the main forest species. I want to found a way to join the information of the polygon of the second shapefile to the first shapefile. I want to have the information of the closest polygon of each square in the square but the type of forest cover need to be the same.

I’m able to join the closest polygon but I am not able to join with the closest polygon with the same type of forest cover I have try with python but I have never used this tool and it doesn’t work

I try:

arcpy.Near_analysis('chantier1', 'chantier2') 

WHERE (((chantier1.TYPE_COUV)=(chantier2.type_couv2))

Chantier1 is my first shapefile and chantier2 my second. TYPE_COUV and type_couv2 are the column with the type of forest cover respectively in my shapefile

In summary, for each polygon of chantier1, how do I join the information of the closest polygon of chantier2 with the same type of forest cover?


1 Answer 1


I would recommend using Spatial Join tool instead of Near tool. You'll have more spatial match options (like CLOSEST, INTERSECT, WITHIN_A_DISTANCE) and also able to pull in all joined fields/attributes (whereas in the Near tool only pulls back the objectid). If your not to familiar with python I would recommend:

  1. Create a model (using Model Builder) with the workflow/processes
  2. After step one is working, if you are still interested in having the python script do the following in Model Builder right click the Model menu>Export>To Python Script option

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.