Don't enumerate units in a rect, enumerate player units or units of type.

JASS:
native GroupEnumUnitsOfType takes group whichGroup, string unitname, boolexpr filter returns nothing
native GroupEnumUnitsOfPlayer takes group whichGroup, player whichPlayer, boolexpr filter returns nothing
To detect whether the enum unit is in a transport or not use the following natives:

JASS:
constant native IsUnitInTransport takes unit whichUnit, unit whichTransport returns boolean
constant native IsUnitLoaded takes unit whichUnit returns boolean