why is below code giving me very wierd results? I want to do SpatialJoin. Target polygon feature is "zapojporost" with target field "cislo". I want DRUH_POZEMKU and TEXT_KM from input feature to be merged to corresponding cells.
As a result I always get mixed up results. In some fields, there is no value. In field "cislo" I even get different number and I thought that when it was target feature, it could not be changed by SpatialJoin. Thank you for any tips.
KN_Feature = "PARCELY_KN_JOIN"
areaVysledek = "area_Vysledek"
zapojporostFeature = "zapojporost"
fms1 = arcpy.FieldMappings()
keepers = ["cislo","KATUZE_KOD","TEXT_KM","DRUH_POZEMKU"] # etc.
# Remove all output fields you don't want.
for field in fms1.fields:
if field.name not in keepers:
parcela_index = fms1.findFieldMapIndex("TEXT_KM")
fieldmap = fms1.getFieldMap(parcela_index)
field = fieldmap.outputField
field.name = "parcelaCislo"
field.aliasName = "parcela č."
fieldmap.outputField = field
fieldmap.mergeRule = "Join"
fieldmap.joinDelimiter = ", "
drupoz_index = fms1.findFieldMapIndex("DRUH_POZEMKU")
fieldmap1 = fms1.getFieldMap(drupoz_index)
field1 = fieldmap1.outputField
field1.name = "druhPozemku1"
field1.aliasName = "druh pozemku"
fieldmap1.outputField = field1
fieldmap1.mergeRule = "Join"
fieldmap1.joinDelimiter = ", "
# SpatailJoin pro plochy
arcpy.analysis.SpatialJoin(zapojporostFeature, "PARCELY_KN_JOIN", areaVysledek, 'JOIN_ONE_TO_ONE',"KEEP_ALL",fms1)
Hi, thank you very much for your answer. Yes, I believe INTERSECT is the best option for me. According to this site. There is an issue that can arise (options I and J when selecting polygon with polygon).
This is hardly a case since all target polygons are made by hand. It would be great to have some option INTERSECT WITHOUT TOUCHING 🙂
As with other options, WITHIN and CONTAINS are too strict. I need the join feature to be matched whenever both join and target inner parts overlap.
As a result, I would like to get target features with lists of values of desired attributes in corresponding cells delimited by comma.